excel_to_code 0.2.21 → 0.2.22
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/excel_to_c +5 -0
- data/bin/excel_to_ruby +5 -0
- data/src/commands/excel_to_ruby.rb +28 -0
- data/src/commands/excel_to_x.rb +13 -6
- data/src/compile/c/compile_named_reference_setters.rb +31 -4
- data/src/excel/excel_functions.rb +1 -0
- data/src/excel/excel_functions/reset.rb +14 -0
- data/src/excel_to_code.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3ccdb199882da15b8172e1714f446a6bf0327d9e
|
4
|
+
data.tar.gz: 1a6a3be2a554c829a9654a0d567f385f8f8fca92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2653de86cca389d7865e7fe853fa1253255b3399953764c3746ed968432ab0c6f6a3fc4cb10bd10de4b7beeefa06d563f85463b697e385b783f19c07b5cc7a3
|
7
|
+
data.tar.gz: 7040c57720a1bfb389106405ac2c6d17e8f2f0602d944456b8cffd3b5ad2033f5104850af57cb2d7a022e06697af9fe1a03689f53fc8c05d25390612c89e7259
|
data/bin/excel_to_c
CHANGED
@@ -52,6 +52,11 @@ END
|
|
52
52
|
opts.on('--isolate WORKSHEET', "Only performs translation and optimiation of that one worksheet. Useful for debugging an incorrect translation of a large worksheet") do |sheet|
|
53
53
|
command.isolate = sheet
|
54
54
|
end
|
55
|
+
|
56
|
+
opts.on('-d','--debug', "Does not perform final optimisations of spreadsheet, leaving the resulting code more similar to the original worksheet, but potentially slower") do |sheet|
|
57
|
+
command.should_inline_formulae_that_are_only_used_once = false
|
58
|
+
command.extract_repeated_parts_of_formulae = false
|
59
|
+
end
|
55
60
|
|
56
61
|
opts.on("-h", "--help", "Show this message") do
|
57
62
|
puts opts
|
data/bin/excel_to_ruby
CHANGED
@@ -52,6 +52,11 @@ END
|
|
52
52
|
opts.on('--isolate WORKSHEET', "Only performs translation and optimiation of that one worksheet. Useful for debugging an incorrect translation of a large worksheet") do |sheet|
|
53
53
|
command.isolate = sheet
|
54
54
|
end
|
55
|
+
|
56
|
+
opts.on('-d','--debug', "Does not perform final optimisations of spreadsheet, leaving the resulting code more similar to the original worksheet, but potentially slower") do |sheet|
|
57
|
+
command.should_inline_formulae_that_are_only_used_once = false
|
58
|
+
command.extract_repeated_parts_of_formulae = false
|
59
|
+
end
|
55
60
|
|
56
61
|
opts.on("-h", "--help", "Show this message") do
|
57
62
|
puts opts
|
@@ -38,6 +38,33 @@ class ExcelToRuby < ExcelToX
|
|
38
38
|
c.rewrite(@formulae, @worksheet_c_names, o)
|
39
39
|
o.puts
|
40
40
|
|
41
|
+
# Output the named references
|
42
|
+
|
43
|
+
# Getters
|
44
|
+
o.puts "# Start of named references"
|
45
|
+
c.settable = lambda { |ref| false }
|
46
|
+
named_references_ast = {}
|
47
|
+
@named_references_to_keep.each do |ref|
|
48
|
+
c_name = ref.is_a?(Array) ? c_name_for(ref) : ["", c_name_for(ref)]
|
49
|
+
named_references_ast[c_name] = @named_references[ref]
|
50
|
+
end
|
51
|
+
|
52
|
+
c.rewrite(named_references_ast, @worksheet_c_names, o)
|
53
|
+
|
54
|
+
# Setters
|
55
|
+
m = MapNamedReferenceToRubySetter.new
|
56
|
+
m.cells_that_can_be_set_at_runtime = cells_that_can_be_set_at_runtime
|
57
|
+
m.sheet_names = @worksheet_c_names
|
58
|
+
@named_references_that_can_be_set_at_runtime.each do |ref|
|
59
|
+
c_name = c_name_for(ref)
|
60
|
+
ast = @named_references[ref]
|
61
|
+
o.puts " def #{c_name}=(newValue)"
|
62
|
+
o.puts " @#{c_name} = newValue"
|
63
|
+
o.puts m.map(ast)
|
64
|
+
o.puts " end"
|
65
|
+
end
|
66
|
+
o.puts "# End of named references"
|
67
|
+
|
41
68
|
log.info "Starting to write initializer"
|
42
69
|
o.puts
|
43
70
|
o.puts " # starting initializer"
|
@@ -50,6 +77,7 @@ class ExcelToRuby < ExcelToX
|
|
50
77
|
o.puts ""
|
51
78
|
log.info "Finished writing initializer"
|
52
79
|
|
80
|
+
|
53
81
|
o.puts "end"
|
54
82
|
close(o)
|
55
83
|
log.info "Finished writing code"
|
data/src/commands/excel_to_x.rb
CHANGED
@@ -87,22 +87,28 @@ class ExcelToX
|
|
87
87
|
|
88
88
|
# Optional attribute. Boolean.
|
89
89
|
# * true - the generated tests are run
|
90
|
-
# * false - the generated tests are not run
|
90
|
+
# * false (default) - the generated tests are not run
|
91
91
|
attr_accessor :actually_run_tests
|
92
92
|
|
93
93
|
# This is the log file, if set it needs to respond to the same methods as the standard logger library
|
94
94
|
attr_accessor :log
|
95
95
|
|
96
|
-
# Optional attribute. Boolean.
|
97
|
-
# * true - empty cells and zeros are treated as being equivalent in tests. Numbers greater then 1 are only expected to match with assert_in_epsilon, numbers less than 1 are only expected to match with assert_in_delta
|
96
|
+
# Optional attribute. Boolean.
|
97
|
+
# * true (default) - empty cells and zeros are treated as being equivalent in tests. Numbers greater then 1 are only expected to match with assert_in_epsilon, numbers less than 1 are only expected to match with assert_in_delta
|
98
98
|
# * false - empty cells and zeros are treated as being different in tests. Numbers must match to full accuracy.
|
99
99
|
attr_accessor :sloppy_tests
|
100
100
|
|
101
|
-
# Optional attribute, Boolean.
|
102
|
-
# * true - the compiler attempts to
|
101
|
+
# Optional attribute, Boolean.
|
102
|
+
# * true (default) - the compiler attempts to inline any calculation that is done in another cell, but only referred to by this cell. This should increase performance
|
103
|
+
# * false - the compiler leaves calculations in their original cells expanded. This may make debugging easier
|
104
|
+
attr_accessor :should_inline_formulae_that_are_only_used_once
|
105
|
+
|
106
|
+
# Optional attribute, Boolean.
|
107
|
+
# * true (default) - the compiler attempts to extract bits of calculation that appear in more than one formula into separate methods. This should increase performance
|
103
108
|
# * false - the compiler leaves calculations fully expanded. This may make debugging easier
|
104
109
|
attr_accessor :extract_repeated_parts_of_formulae
|
105
110
|
|
111
|
+
|
106
112
|
# Optional attribute, Array. Default nil
|
107
113
|
# This is used to help debug large spreadsheets that aren't working correctly.
|
108
114
|
# If set to the name of a worksheet then ONLY that worksheet will be run through the
|
@@ -189,7 +195,7 @@ class ExcelToX
|
|
189
195
|
filter_named_references
|
190
196
|
|
191
197
|
replace_formulae_with_their_results
|
192
|
-
inline_formulae_that_are_only_used_once
|
198
|
+
inline_formulae_that_are_only_used_once if should_inline_formulae_that_are_only_used_once
|
193
199
|
remove_any_cells_not_needed_for_outputs
|
194
200
|
separate_formulae_elements if extract_repeated_parts_of_formulae
|
195
201
|
replace_values_with_constants
|
@@ -228,6 +234,7 @@ class ExcelToX
|
|
228
234
|
|
229
235
|
# Setting this to false may make it easier to figure out errors
|
230
236
|
self.extract_repeated_parts_of_formulae = true if @extract_repeated_parts_of_formulae == nil
|
237
|
+
self.should_inline_formulae_that_are_only_used_once = true if @should_inline_formulae_that_are_only_used_once == nil
|
231
238
|
|
232
239
|
# This setting is used for debugging, and makes the system only do the conversion on a subset of the the
|
233
240
|
if self.isolate
|
@@ -31,8 +31,8 @@ class MapNamedReferenceToCSetter
|
|
31
31
|
def sheet_reference(sheet,reference)
|
32
32
|
s = sheet_names[sheet]
|
33
33
|
c = map(reference)
|
34
|
-
return
|
35
|
-
|
34
|
+
return not_settable_code(s,c) unless settable(sheet, c)
|
35
|
+
settable_code(s,c)
|
36
36
|
end
|
37
37
|
|
38
38
|
def array(*rows)
|
@@ -48,8 +48,7 @@ class MapNamedReferenceToCSetter
|
|
48
48
|
end.flatten.join("\n")
|
49
49
|
|
50
50
|
@new_value_name = "newValue"
|
51
|
-
|
52
|
-
" ExcelValue *array = newValue.array;\n#{result}"
|
51
|
+
array_code(result)
|
53
52
|
end
|
54
53
|
|
55
54
|
def settable(sheet, reference)
|
@@ -59,8 +58,36 @@ class MapNamedReferenceToCSetter
|
|
59
58
|
settable_refs.include?(reference.upcase.to_sym)
|
60
59
|
end
|
61
60
|
|
61
|
+
def not_settable_code(s,c)
|
62
|
+
" // #{s}_#{c} not settable"
|
63
|
+
end
|
64
|
+
|
65
|
+
def settable_code(s,c)
|
66
|
+
" set_#{s}_#{c}(#{@new_value_name});"
|
67
|
+
end
|
68
|
+
|
69
|
+
def array_code(result)
|
70
|
+
" ExcelValue *array = newValue.array;\n#{result}"
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
class MapNamedReferenceToRubySetter < MapNamedReferenceToCSetter
|
76
|
+
def not_settable_code(s,c)
|
77
|
+
" # @#{s}_#{c} not settable"
|
78
|
+
end
|
79
|
+
|
80
|
+
def settable_code(s,c)
|
81
|
+
" @#{s}_#{c} = #{@new_value_name}"
|
82
|
+
end
|
83
|
+
|
84
|
+
def array_code(result)
|
85
|
+
" array = newValue\n#{result}"
|
86
|
+
end
|
62
87
|
end
|
63
88
|
|
89
|
+
|
90
|
+
|
64
91
|
class CompileNamedReferenceSetters
|
65
92
|
|
66
93
|
attr_accessor :cells_that_can_be_set_at_runtime
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
# This is a support function for reseting a spreadsheet's instance
|
4
|
+
# variables back to nil, allowing the results to be recalculated
|
5
|
+
def reset()
|
6
|
+
# Set all the instance variables to nil
|
7
|
+
instance_variables.each do |iv|
|
8
|
+
instance_variable_set(iv,nil)
|
9
|
+
end
|
10
|
+
# Reset the settable variables to their defaults
|
11
|
+
initialize
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
data/src/excel_to_code.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: excel_to_code
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Counsell, Green on Black Ltd
|
@@ -186,6 +186,7 @@ files:
|
|
186
186
|
- src/excel/excel_functions/power.rb
|
187
187
|
- src/excel/excel_functions/pv.rb
|
188
188
|
- src/excel/excel_functions/rank.rb
|
189
|
+
- src/excel/excel_functions/reset.rb
|
189
190
|
- src/excel/excel_functions/right.rb
|
190
191
|
- src/excel/excel_functions/round.rb
|
191
192
|
- src/excel/excel_functions/rounddown.rb
|