excel_to_code 0.2.26 → 0.2.27
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/src/commands/excel_to_c.rb +2 -2
- data/src/commands/excel_to_ruby.rb +2 -2
- data/src/commands/excel_to_x.rb +39 -20
- data/src/excel/table.rb +4 -0
- data/src/excel_to_code.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 86c6743f72819d7a8b5372c8f252c3b109c71921
|
4
|
+
data.tar.gz: 9a5a252b856bf6e58266f32fb742c94ba9511d0c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0c1356a0c2cbdd5bb6214c1465ea8b1f5a9991fd15f08d54f5525fd8596bd5881e00f6337d6e57289b062b42b0256f3c169dd5bcc612bc6f5ee7dc41c2435687
|
7
|
+
data.tar.gz: baaa79346e1fae183328ad246781bfa459c6dac83c06299448445b05421b692ddc3027b84b0897e263ad76f6c4017a35b7adf8aa60ec8c4195c6cf3154ac1504
|
data/src/commands/excel_to_c.rb
CHANGED
@@ -76,7 +76,7 @@ class ExcelToC < ExcelToX
|
|
76
76
|
named_references_ast = {}
|
77
77
|
@named_references_to_keep.each do |ref|
|
78
78
|
c_name = ref.is_a?(Array) ? c_name_for(ref) : ["", c_name_for(ref)]
|
79
|
-
named_references_ast[c_name] = @named_references[ref]
|
79
|
+
named_references_ast[c_name] = @named_references[ref] || @table_areas[ref]
|
80
80
|
end
|
81
81
|
|
82
82
|
c.rewrite(named_references_ast, @worksheet_c_names, o)
|
@@ -86,7 +86,7 @@ class ExcelToC < ExcelToX
|
|
86
86
|
c.cells_that_can_be_set_at_runtime = cells_that_can_be_set_at_runtime
|
87
87
|
named_references_ast = {}
|
88
88
|
@named_references_that_can_be_set_at_runtime.each do |ref|
|
89
|
-
named_references_ast[c_name_for(ref)] = @named_references[ref]
|
89
|
+
named_references_ast[c_name_for(ref)] = @named_references[ref] || @table_areas[ref]
|
90
90
|
end
|
91
91
|
c.rewrite(named_references_ast, @worksheet_c_names, o)
|
92
92
|
o.puts "// End of named references"
|
@@ -46,7 +46,7 @@ class ExcelToRuby < ExcelToX
|
|
46
46
|
named_references_ast = {}
|
47
47
|
@named_references_to_keep.each do |ref|
|
48
48
|
c_name = ref.is_a?(Array) ? c_name_for(ref) : ["", c_name_for(ref)]
|
49
|
-
named_references_ast[c_name] = @named_references[ref]
|
49
|
+
named_references_ast[c_name] = @named_references[ref] || @table_areas[ref]
|
50
50
|
end
|
51
51
|
|
52
52
|
c.rewrite(named_references_ast, @worksheet_c_names, o)
|
@@ -57,7 +57,7 @@ class ExcelToRuby < ExcelToX
|
|
57
57
|
m.sheet_names = @worksheet_c_names
|
58
58
|
@named_references_that_can_be_set_at_runtime.each do |ref|
|
59
59
|
c_name = c_name_for(ref)
|
60
|
-
ast = @named_references[ref]
|
60
|
+
ast = @named_references[ref] || @table_areas[ref]
|
61
61
|
o.puts " def #{c_name}=(newValue)"
|
62
62
|
o.puts " @#{c_name} = newValue"
|
63
63
|
o.puts m.map(ast)
|
data/src/commands/excel_to_x.rb
CHANGED
@@ -32,7 +32,9 @@ class ExcelToX
|
|
32
32
|
# should be setable, or an array of cell names on that sheet that should be settable (e.g., A1)
|
33
33
|
attr_accessor :cells_that_can_be_set_at_runtime
|
34
34
|
|
35
|
-
# Optional attribute. Specifies which named references to be turned into setters
|
35
|
+
# Optional attribute. Specifies which named references to be turned into setters.
|
36
|
+
#
|
37
|
+
# NB: Named references are assumed to include table names.
|
36
38
|
#
|
37
39
|
# Should be an array of strings. Each string is a named reference. Case sensitive.
|
38
40
|
# To specify a named reference scoped to a worksheet, use ['worksheet', 'named reference'] instead
|
@@ -64,6 +66,8 @@ class ExcelToX
|
|
64
66
|
|
65
67
|
# Optional attribute. Specifies which named references should be included in the output
|
66
68
|
#
|
69
|
+
# NB: Named references are assumed to include table names.
|
70
|
+
#
|
67
71
|
# Should be an array of strings. Each string is a named reference. Case sensitive.
|
68
72
|
#
|
69
73
|
# To specify a named reference scoped to a worksheet, use ['worksheet', 'named reference'] instead
|
@@ -140,6 +144,9 @@ class ExcelToX
|
|
140
144
|
# These gets the named references, worksheet names and shared strings out of the excel
|
141
145
|
extract_data_from_workbook
|
142
146
|
|
147
|
+
# This gets all the formulae, values and tables out of the worksheets
|
148
|
+
extract_data_from_worksheets
|
149
|
+
|
143
150
|
# This checks that the user inputs of which cells to keep are in the right
|
144
151
|
# format and refer to sheets and references that actually exist
|
145
152
|
clean_cells_that_can_be_set_at_runtime
|
@@ -147,9 +154,6 @@ class ExcelToX
|
|
147
154
|
clean_named_references_to_keep
|
148
155
|
clean_named_references_that_can_be_set_at_runtime
|
149
156
|
|
150
|
-
# This gets all the formulae, values and tables out of the worksheets
|
151
|
-
extract_data_from_worksheets
|
152
|
-
|
153
157
|
# This is an early check that the functions in the extracted data have
|
154
158
|
# all got an implementation in, at least, the ruby code
|
155
159
|
check_all_functions_implemented
|
@@ -423,7 +427,11 @@ class ExcelToX
|
|
423
427
|
new_named_references_to_keep = @named_references.keys.select do |named_reference|
|
424
428
|
named_references_to_keep.call(named_reference)
|
425
429
|
end
|
426
|
-
|
430
|
+
table_references_to_keep = @table_areas.keys.select do |table_name|
|
431
|
+
named_references_to_keep.call(table_name)
|
432
|
+
end
|
433
|
+
|
434
|
+
@named_references_to_keep = new_named_references_to_keep.concat(table_references_to_keep)
|
427
435
|
end
|
428
436
|
|
429
437
|
return unless named_references_to_keep.is_a?(Array)
|
@@ -431,8 +439,8 @@ class ExcelToX
|
|
431
439
|
|
432
440
|
# Now we need to check the user specified named references actually exist
|
433
441
|
named_references_to_keep.each.with_index do |named_reference, i|
|
434
|
-
next if @named_references.has_key?(named_reference)
|
435
|
-
|
442
|
+
next if @named_references.has_key?(named_reference) || @table_areas.has_key?(named_reference)
|
443
|
+
$stderr.puts "Named reference #{named_reference.inspect} in named_references_to_keep has not been found in the spreadsheet: #{@named_references.keys.inspect}"
|
436
444
|
exit
|
437
445
|
end
|
438
446
|
end
|
@@ -446,7 +454,10 @@ class ExcelToX
|
|
446
454
|
new_named_references_that_can_be_set_at_runtime = @named_references.keys.select do |named_reference|
|
447
455
|
named_references_that_can_be_set_at_runtime.call(named_reference)
|
448
456
|
end
|
449
|
-
|
457
|
+
table_references_that_can_be_set_at_runtime = @table_areas.keys.select do |table_name|
|
458
|
+
named_references_that_can_be_set_at_runtime.call(table_name)
|
459
|
+
end
|
460
|
+
@named_references_that_can_be_set_at_runtime = new_named_references_that_can_be_set_at_runtime.concat(table_references_that_can_be_set_at_runtime)
|
450
461
|
end
|
451
462
|
|
452
463
|
return unless named_references_that_can_be_set_at_runtime.is_a?(Array)
|
@@ -454,8 +465,8 @@ class ExcelToX
|
|
454
465
|
|
455
466
|
# Now we need to check the user specified named references actually exist
|
456
467
|
named_references_that_can_be_set_at_runtime.each.with_index do |named_reference, i|
|
457
|
-
next if @named_references.has_key?(named_reference)
|
458
|
-
|
468
|
+
next if @named_references.has_key?(named_reference) || @table_areas.has_key?(named_reference)
|
469
|
+
$stderr.puts "Named reference #{named_reference.inspect} in named_references_that_can_be_set_at_runtime has not been found in the spreadsheet: #{@named_references.keys.inspect}"
|
459
470
|
exit
|
460
471
|
end
|
461
472
|
end
|
@@ -491,6 +502,7 @@ class ExcelToX
|
|
491
502
|
@worksheets_dimensions = extractor.worksheets_dimensions
|
492
503
|
@table_rids = extractor.table_rids
|
493
504
|
@tables = {}
|
505
|
+
@table_areas = {}
|
494
506
|
extract_tables
|
495
507
|
end
|
496
508
|
|
@@ -499,6 +511,7 @@ class ExcelToX
|
|
499
511
|
# reference and contains the table data. Then we consolidate all the data
|
500
512
|
# from individual table files into a single table file for the worksheet.
|
501
513
|
def extract_tables
|
514
|
+
log.info "Extracting Tables"
|
502
515
|
@table_rids.each do |worksheet_name, array_of_table_rids|
|
503
516
|
xml_filename = @worksheet_xmls[worksheet_name]
|
504
517
|
xml_for_rids = {}
|
@@ -512,11 +525,22 @@ class ExcelToX
|
|
512
525
|
array_of_table_rids.each do |rid|
|
513
526
|
xml(File.join('worksheets', xml_for_rids[rid])) do |i|
|
514
527
|
ExtractTable.extract(worksheet_name, i).each do |table_name, details|
|
515
|
-
|
528
|
+
name = table_name.downcase
|
529
|
+
table = Table.new(table_name, *details)
|
530
|
+
@tables[name] = table
|
531
|
+
@table_areas[name.to_sym] = table.all
|
516
532
|
end
|
517
533
|
end
|
518
534
|
end
|
519
535
|
end
|
536
|
+
|
537
|
+
# Replace A$1:B2 with [A1, A2, B1, B2]
|
538
|
+
@replace_ranges_with_array_literals_replacer ||= ReplaceRangesWithArrayLiteralsAst.new
|
539
|
+
|
540
|
+
@table_areas.each do |name, reference|
|
541
|
+
@table_areas[name] = @replace_ranges_with_array_literals_replacer.map(reference)
|
542
|
+
end
|
543
|
+
|
520
544
|
end
|
521
545
|
|
522
546
|
def check_all_functions_implemented
|
@@ -548,7 +572,7 @@ class ExcelToX
|
|
548
572
|
log.info "Transfering named references to keep into cells to keep"
|
549
573
|
return unless @named_references_to_keep
|
550
574
|
if @named_references_to_keep == :all
|
551
|
-
@named_references_to_keep = @named_references.keys
|
575
|
+
@named_references_to_keep = @named_references.keys + @table_areas.keys
|
552
576
|
# If the user has specified named_references_to_keep == :all, but there are none, fall back
|
553
577
|
if @named_references_to_keep.empty?
|
554
578
|
log.warn "named_references_to_keep == :all, but no named references found"
|
@@ -557,7 +581,7 @@ class ExcelToX
|
|
557
581
|
end
|
558
582
|
@cells_to_keep ||= {}
|
559
583
|
@named_references_to_keep.each do |name|
|
560
|
-
ref = @named_references[name]
|
584
|
+
ref = @named_references[name] || @table_areas[name]
|
561
585
|
if ref
|
562
586
|
add_ref_to_hash(ref, @cells_to_keep)
|
563
587
|
else
|
@@ -573,7 +597,7 @@ class ExcelToX
|
|
573
597
|
return if @named_references_that_can_be_set_at_runtime == :where_possible # in this case will be done in #work_out_which_named_references_can_be_set_at_runtime
|
574
598
|
@cells_that_can_be_set_at_runtime ||= {}
|
575
599
|
@named_references_that_can_be_set_at_runtime.each do |name|
|
576
|
-
ref = @named_references[name]
|
600
|
+
ref = @named_references[name] || @table_areas[name]
|
577
601
|
if ref
|
578
602
|
add_ref_to_hash(ref, @cells_that_can_be_set_at_runtime)
|
579
603
|
else
|
@@ -761,7 +785,7 @@ class ExcelToX
|
|
761
785
|
# In some situations also need to add the named references
|
762
786
|
if @named_references_to_keep
|
763
787
|
@named_references_to_keep.each do |name|
|
764
|
-
ref = @named_references[name]
|
788
|
+
ref = @named_references[name] || @table_areas[name]
|
765
789
|
if ref.first == :sheet_reference
|
766
790
|
s = ref[1]
|
767
791
|
c = Reference.for(ref[2][1]).unfix.to_sym
|
@@ -853,11 +877,6 @@ class ExcelToX
|
|
853
877
|
end
|
854
878
|
end
|
855
879
|
|
856
|
-
@named_references.each do |name, ref|
|
857
|
-
if named_references_that_can_be_set_at_runtime.include?(name)
|
858
|
-
@named_references_that_can_be_set_at_runtime << name
|
859
|
-
end
|
860
|
-
end
|
861
880
|
end
|
862
881
|
|
863
882
|
def simplify(cells = @formulae)
|
data/src/excel/table.rb
CHANGED
data/src/excel_to_code.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Counsell, Green on Black Ltd
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-06-
|
11
|
+
date: 2014-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypeg
|