excel_to_code 0.3.8 → 0.3.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/src/commands/excel_to_x.rb +10 -3
- data/src/excel_to_code.rb +1 -1
- data/src/simplify.rb +1 -0
- data/src/simplify/fix_subtotal_of_subtotals.rb +76 -0
- 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: 8f304a10a7977c70c147712719e56badfba0a619
|
|
4
|
+
data.tar.gz: 182ecde186d561e58a3cf15c8b8765fca8f996c0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7c36dcaca5afc7cb6210fc906f33a8e5fe42dcacaa7dbe45275bca689ea67aa5d060b5a1e457a463689573736cccc4507addac4edb78db4288e10dfdd9aebd27
|
|
7
|
+
data.tar.gz: ff50f71cfd95e7023862ed9b5a2344273c44273103e54eaba17b0c80cce798147a0e1be0eb7546f92c614355dffedcf25ecce537c485c1ea93f90f66fc561bdc
|
data/src/commands/excel_to_x.rb
CHANGED
|
@@ -228,7 +228,12 @@ class ExcelToX
|
|
|
228
228
|
self.output_directory = File.expand_path(output_directory)
|
|
229
229
|
|
|
230
230
|
# Set up our log file
|
|
231
|
-
self.log
|
|
231
|
+
unless self.log
|
|
232
|
+
self.log = Logger.new(STDOUT)
|
|
233
|
+
log.formatter = proc do |severity, datetime, progname, msg|
|
|
234
|
+
"#{datetime.strftime("%H:%M")}\t#{msg}\n"
|
|
235
|
+
end
|
|
236
|
+
end
|
|
232
237
|
|
|
233
238
|
# By default, tests allow empty cells and zeros to be treated as equivalent, and numbers only have to match to a 0.001 epsilon (if expected>1) or 0.001 delta (if expected<1)
|
|
234
239
|
self.sloppy_tests ||= true
|
|
@@ -257,8 +262,8 @@ class ExcelToX
|
|
|
257
262
|
|
|
258
263
|
# FIXME: Replace these with pure ruby versions?
|
|
259
264
|
def unzip_excel
|
|
260
|
-
log.info `rm -fr '#{xml_directory}'` # Force delete
|
|
261
|
-
log.info `unzip '#{excel_file}' -d '#{xml_directory}'` # If don't force delete, make sure that force the zip to overwrite old files
|
|
265
|
+
log.info "Removing any old xml #{`rm -fr '#{xml_directory}'`}" # Force delete
|
|
266
|
+
log.info "Unziping excel into xml #{`unzip -q '#{excel_file}' -d '#{xml_directory}'`}" # If don't force delete, make sure that force the zip to overwrite old files
|
|
262
267
|
end
|
|
263
268
|
|
|
264
269
|
# The excel workbook.xml and allied relationship files knows about
|
|
@@ -905,6 +910,7 @@ class ExcelToX
|
|
|
905
910
|
@replace_string_joins_on_ranges_replacer ||= ReplaceStringJoinOnRangesAST.new
|
|
906
911
|
@sheetless_cell_reference_replacer ||= RewriteCellReferencesToIncludeSheetAst.new
|
|
907
912
|
@replace_references_to_blanks_with_zeros ||= ReplaceReferencesToBlanksWithZeros.new(@formulae, nil, inline_ast_decision)
|
|
913
|
+
@fix_subtotal_of_subtotals ||= FixSubtotalOfSubtotals.new(@formulae)
|
|
908
914
|
|
|
909
915
|
#require 'pry'; binding.pry
|
|
910
916
|
|
|
@@ -929,6 +935,7 @@ class ExcelToX
|
|
|
929
935
|
@wrap_formulae_that_return_arrays_replacer.map(ast)
|
|
930
936
|
@replace_references_to_blanks_with_zeros.current_sheet_name = ref.first
|
|
931
937
|
@replace_references_to_blanks_with_zeros.map(ast)
|
|
938
|
+
@fix_subtotal_of_subtotals.map(ast)
|
|
932
939
|
rescue Exception => e
|
|
933
940
|
log.fatal "Exception when simplifying #{ref}: #{ast}"
|
|
934
941
|
raise
|
data/src/excel_to_code.rb
CHANGED
data/src/simplify.rb
CHANGED
|
@@ -22,3 +22,4 @@ require_relative "simplify/replace_string_join_on_ranges"
|
|
|
22
22
|
require_relative "simplify/emergency_array_formula_replace_indirect_bodge.rb"
|
|
23
23
|
require_relative "simplify/replace_transpose_function"
|
|
24
24
|
require_relative "simplify/replace_references_to_blanks_with_zeros"
|
|
25
|
+
require_relative "simplify/fix_subtotal_of_subtotals"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
class FixSubtotalOfSubtotals
|
|
2
|
+
|
|
3
|
+
attr_accessor :references
|
|
4
|
+
attr_accessor :count_replaced
|
|
5
|
+
|
|
6
|
+
def initialize(references = nil)
|
|
7
|
+
@references = references
|
|
8
|
+
@count_replaced = 0
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def map(ast)
|
|
12
|
+
return ast unless ast.is_a?(Array)
|
|
13
|
+
if ast[0] == :function && ast[1] == :SUBTOTAL
|
|
14
|
+
count_before = @count_replaced
|
|
15
|
+
new_arguments = ast[2..-1].map do |a|
|
|
16
|
+
remove_subtotals_from(a)
|
|
17
|
+
end
|
|
18
|
+
new_arguments.compact!
|
|
19
|
+
if @count_replaced > count_before
|
|
20
|
+
ast.replace([:function, :SUBTOTAL].concat(new_arguments))
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
ast.each do |a|
|
|
24
|
+
map(a) if a.is_a?(Array)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def is_subtotal?(ast)
|
|
29
|
+
return false unless ast.is_a?(Array)
|
|
30
|
+
return true if ast[0] == :function && ast[1] == :SUBTOTAL
|
|
31
|
+
ast.each do |e|
|
|
32
|
+
r = is_subtotal?(e) if e.is_a?(Array) # To limit the stack depth
|
|
33
|
+
return true if r
|
|
34
|
+
end
|
|
35
|
+
return false
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def is_or_refers_to_subtotal?(ast)
|
|
39
|
+
return false unless ast.is_a?(Array)
|
|
40
|
+
return is_subtotal?(ast) unless ast[0] == :sheet_reference
|
|
41
|
+
|
|
42
|
+
raise ExcelToCodeException.new("Expecting cell") unless ast[2][0] == :cell
|
|
43
|
+
reference_ast = references[[ast[1], ast[2][1]]]
|
|
44
|
+
return false unless reference_ast
|
|
45
|
+
|
|
46
|
+
is_subtotal?(reference_ast)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def remove_subtotals_from(ast)
|
|
50
|
+
return ast unless ast.is_a?(Array)
|
|
51
|
+
if ast.first == :array
|
|
52
|
+
new_ast = ast.dup
|
|
53
|
+
new_ast.delete_if do |element|
|
|
54
|
+
if element == :array
|
|
55
|
+
false
|
|
56
|
+
else
|
|
57
|
+
raise ExcelToCodeException("Expecting row") unless element.is_a?(Array) && element[0] == :row
|
|
58
|
+
element[1..-1].any? { |cell| is_or_refers_to_subtotal?(cell) }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
return ast if new_ast.length == ast.length
|
|
62
|
+
@count_replaced += 1
|
|
63
|
+
return new_ast
|
|
64
|
+
else
|
|
65
|
+
if is_or_refers_to_subtotal?(ast)
|
|
66
|
+
@count_replaced += 1
|
|
67
|
+
return nil
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
ast
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
end
|
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.3.
|
|
4
|
+
version: 0.3.9
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Thomas Counsell, Green on Black Ltd
|
|
@@ -247,6 +247,7 @@ files:
|
|
|
247
247
|
- src/simplify.rb
|
|
248
248
|
- src/simplify/count_formula_references.rb
|
|
249
249
|
- src/simplify/emergency_array_formula_replace_indirect_bodge.rb
|
|
250
|
+
- src/simplify/fix_subtotal_of_subtotals.rb
|
|
250
251
|
- src/simplify/identify_dependencies.rb
|
|
251
252
|
- src/simplify/identify_repeated_formula_elements.rb
|
|
252
253
|
- src/simplify/inline_formulae.rb
|