excel_to_code 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/src/commands/excel_to_c.rb +2 -5
- data/src/commands/excel_to_ruby.rb +1 -1
- data/src/commands/excel_to_x.rb +14 -17
- data/src/simplify.rb +0 -1
- metadata +9 -10
- data/src/simplify/replace_blanks.rb +0 -58
data/src/commands/excel_to_c.rb
CHANGED
@@ -20,10 +20,7 @@ class ExcelToC < ExcelToX
|
|
20
20
|
all_refs = all_formulae("formulae_inlined_pruned_replaced.ast")
|
21
21
|
|
22
22
|
number_of_refs = 0
|
23
|
-
|
24
|
-
# Probably a better way of getting the runtime file to be compiled with the created file
|
25
|
-
puts `cp #} #{File.join(output_directory,'excel_to_c_runtime.c')}`
|
26
|
-
|
23
|
+
|
27
24
|
# Output the workbook preamble
|
28
25
|
w = input("worksheet_c_names")
|
29
26
|
o = output("#{output_name.downcase}.c")
|
@@ -219,7 +216,7 @@ END
|
|
219
216
|
o.puts "require 'test/unit'"
|
220
217
|
o.puts "require_relative '#{output_name.downcase}'"
|
221
218
|
o.puts
|
222
|
-
o.puts "class Test#{
|
219
|
+
o.puts "class Test#{ruby_module_name} < Test::Unit::TestCase"
|
223
220
|
o.puts " def spreadsheet; @spreadsheet ||= init_spreadsheet; end"
|
224
221
|
o.puts " def init_spreadsheet; #{ruby_module_name} end"
|
225
222
|
|
@@ -95,7 +95,7 @@ class ExcelToRuby < ExcelToX
|
|
95
95
|
o.puts "require 'test/unit'"
|
96
96
|
o.puts "require_relative '#{output_name.downcase}'"
|
97
97
|
o.puts
|
98
|
-
o.puts "class Test#{
|
98
|
+
o.puts "class Test#{ruby_module_name} < Test::Unit::TestCase"
|
99
99
|
o.puts " def worksheet; @worksheet ||= #{ruby_module_name}.new; end"
|
100
100
|
|
101
101
|
c = CompileToRubyUnitTest.new
|
data/src/commands/excel_to_x.rb
CHANGED
@@ -109,7 +109,6 @@ class ExcelToX
|
|
109
109
|
# that are in the excel
|
110
110
|
simplify_worksheets
|
111
111
|
optimise_and_replace_indirect_loop
|
112
|
-
replace_blanks
|
113
112
|
remove_any_cells_not_needed_for_outputs
|
114
113
|
inline_formulae_that_are_only_used_once
|
115
114
|
separate_formulae_elements
|
@@ -148,7 +147,8 @@ class ExcelToX
|
|
148
147
|
if File.exists?(File.join(xml_directory,'xl','sharedStrings.xml'))
|
149
148
|
extract ExtractSharedStrings, 'sharedStrings.xml', 'shared_strings'
|
150
149
|
else
|
151
|
-
|
150
|
+
i = intermediate('shared_strings')
|
151
|
+
close(i)
|
152
152
|
end
|
153
153
|
end
|
154
154
|
|
@@ -326,17 +326,7 @@ class ExcelToX
|
|
326
326
|
replace ReplaceRangesWithArrayLiterals, File.join(name,"formulae_no_table_references.ast"), File.join(name,"formulae_no_ranges.ast")
|
327
327
|
end
|
328
328
|
end
|
329
|
-
|
330
|
-
def replace_blanks
|
331
|
-
references = all_formulae("formulae_no_indirects_optimised.ast")
|
332
|
-
r = ReplaceBlanks.new
|
333
|
-
r.references = references
|
334
|
-
worksheets("Replacing blanks") do |name,xml_filename|
|
335
|
-
r.default_sheet_name = name
|
336
|
-
replace r, File.join(name,"formulae_no_indirects_optimised.ast"),File.join(name,"formulae_no_blanks.ast")
|
337
|
-
end
|
338
|
-
end
|
339
|
-
|
329
|
+
|
340
330
|
def optimise_and_replace_indirect_loop
|
341
331
|
number_of_loops = 4
|
342
332
|
1.upto(number_of_loops) do |pass|
|
@@ -441,7 +431,7 @@ class ExcelToX
|
|
441
431
|
end
|
442
432
|
end
|
443
433
|
|
444
|
-
def remove_any_cells_not_needed_for_outputs(formula_in = "
|
434
|
+
def remove_any_cells_not_needed_for_outputs(formula_in = "formulae_no_indirects_optimised.ast", formula_out = "formulae_pruned.ast", values_in = "values_no_shared_strings.ast", values_out = "values_pruned.ast")
|
445
435
|
if cells_to_keep && !cells_to_keep.empty?
|
446
436
|
identifier = IdentifyDependencies.new
|
447
437
|
identifier.references = all_formulae(formula_in)
|
@@ -456,9 +446,16 @@ class ExcelToX
|
|
456
446
|
end
|
457
447
|
r = RemoveCells.new
|
458
448
|
worksheets("Removing cells") do |name,xml_filename|
|
459
|
-
|
460
|
-
|
461
|
-
|
449
|
+
next if @cells_that_can_be_set_at_runtime[name] == :all
|
450
|
+
cells_to_keep = identifier.dependencies[name]
|
451
|
+
if @cells_that_can_be_set_at_runtime[name]
|
452
|
+
@cells_that_can_be_set_at_runtime[name].each do |ref|
|
453
|
+
cells_to_keep[ref] = true
|
454
|
+
end
|
455
|
+
end
|
456
|
+
r.cells_to_keep = cells_to_keep
|
457
|
+
rewrite r, File.join(name, formula_in), File.join(name, formula_out)
|
458
|
+
rewrite r, File.join(name, values_in), File.join(name, values_out)
|
462
459
|
end
|
463
460
|
else
|
464
461
|
worksheets do |name,xml_filename|
|
data/src/simplify.rb
CHANGED
@@ -2,7 +2,6 @@ require_relative "simplify/replace_shared_strings"
|
|
2
2
|
require_relative "simplify/replace_named_references"
|
3
3
|
require_relative "simplify/replace_table_references"
|
4
4
|
require_relative "simplify/replace_ranges_with_array_literals"
|
5
|
-
require_relative "simplify/replace_blanks"
|
6
5
|
require_relative "simplify/inline_formulae"
|
7
6
|
require_relative "simplify/replace_formulae_with_calculated_values"
|
8
7
|
require_relative "simplify/replace_indirects_with_references"
|
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.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-26 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rubypeg
|
16
|
-
requirement: &
|
16
|
+
requirement: &70309715642480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70309715642480
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &70309715641980 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 1.5.0
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70309715641980
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &70309715641480 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.7.0
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70309715641480
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: ffi
|
49
|
-
requirement: &
|
49
|
+
requirement: &70309715641020 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,7 +54,7 @@ dependencies:
|
|
54
54
|
version: 1.0.11
|
55
55
|
type: :runtime
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *70309715641020
|
58
58
|
description: ! "# excel_to_code\n\nConverts some excel spreadsheets (.xlsx, not .xls)
|
59
59
|
into some other programming languages (currently ruby or c).\nThis allows the excel
|
60
60
|
spreadsheets to be run programatically, without excel.\n\nIts cannonical source
|
@@ -187,7 +187,6 @@ files:
|
|
187
187
|
- src/simplify/map_formulae_to_values.rb
|
188
188
|
- src/simplify/remove_cells.rb
|
189
189
|
- src/simplify/replace_arrays_with_single_cells.rb
|
190
|
-
- src/simplify/replace_blanks.rb
|
191
190
|
- src/simplify/replace_common_elements_in_formulae.rb
|
192
191
|
- src/simplify/replace_formulae_with_calculated_values.rb
|
193
192
|
- src/simplify/replace_indirects_with_references.rb
|
@@ -1,58 +0,0 @@
|
|
1
|
-
class ReplaceBlanksAst
|
2
|
-
|
3
|
-
attr_accessor :references, :default_sheet_name
|
4
|
-
|
5
|
-
def initialize(references, default_sheet_name)
|
6
|
-
@references, @default_sheet_name = references, default_sheet_name
|
7
|
-
end
|
8
|
-
|
9
|
-
def map(ast)
|
10
|
-
return ast unless ast.is_a?(Array)
|
11
|
-
operator = ast[0]
|
12
|
-
if respond_to?(operator)
|
13
|
-
send(operator,*ast[1..-1])
|
14
|
-
else
|
15
|
-
[operator,*ast[1..-1].map {|a| map(a) }]
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
def sheet_reference(sheet,reference)
|
20
|
-
if references[sheet].has_key?(reference.last.gsub('$',''))
|
21
|
-
[:sheet_reference,sheet,reference]
|
22
|
-
else
|
23
|
-
[:blank]
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def cell(reference)
|
28
|
-
if references[default_sheet_name].has_key?(reference.gsub('$',''))
|
29
|
-
[:cell,reference]
|
30
|
-
else
|
31
|
-
[:blank]
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
|
38
|
-
class ReplaceBlanks
|
39
|
-
|
40
|
-
attr_accessor :references, :default_sheet_name
|
41
|
-
|
42
|
-
def self.replace(*args)
|
43
|
-
self.new.replace(*args)
|
44
|
-
end
|
45
|
-
|
46
|
-
def replace(input,output)
|
47
|
-
rewriter = ReplaceBlanksAst.new(references,default_sheet_name)
|
48
|
-
input.lines do |line|
|
49
|
-
# Looks to match lines with references
|
50
|
-
if line =~ /\[:cell/
|
51
|
-
ref, ast = line.split("\t")
|
52
|
-
output.puts "#{ref}\t#{rewriter.map(eval(ast)).inspect}"
|
53
|
-
else
|
54
|
-
output.puts line
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|