excel_to_code 0.2.1 → 0.2.3
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/bin/excel_to_c +0 -4
- data/bin/excel_to_ruby +0 -4
- data/src/commands/excel_to_c.rb +7 -27
- data/src/commands/excel_to_ruby.rb +2 -2
- data/src/commands/excel_to_x.rb +215 -175
- data/src/compile/c/a.out +0 -0
- data/src/compile/c/excel_to_c_runtime.c +39 -806
- data/src/compile/c/excel_to_c_runtime_test.c +759 -0
- data/src/compile/ruby/map_formulae_to_ruby.rb +1 -0
- data/src/excel/excel_functions.rb +2 -0
- data/src/excel/excel_functions/lower.rb +21 -0
- data/src/extract.rb +1 -10
- data/src/extract/{extract_everything.rb → extract_data_from_worksheet.rb} +1 -1
- metadata +30 -39
- data/src/extract/check_for_unknown_functions.rb +0 -20
- data/src/extract/extract_array_formulae.rb +0 -23
- data/src/extract/extract_formulae.rb +0 -46
- data/src/extract/extract_shared_formulae.rb +0 -24
- data/src/extract/extract_shared_formulae_targets.rb +0 -15
- data/src/extract/extract_simple_formulae.rb +0 -23
- data/src/extract/extract_values.rb +0 -53
- data/src/extract/extract_worksheet_dimensions.rb +0 -21
- data/src/extract/extract_worksheet_table_relationships.rb +0 -22
- data/src/extract/simple_extract_from_xml.rb +0 -17
@@ -0,0 +1,21 @@
|
|
1
|
+
module ExcelFunctions
|
2
|
+
|
3
|
+
def lower(string)
|
4
|
+
return string if string.is_a?(Symbol)
|
5
|
+
case string
|
6
|
+
when nil; ""
|
7
|
+
when String; string.downcase
|
8
|
+
when Numeric
|
9
|
+
if string.round == string
|
10
|
+
string.to_i.to_s
|
11
|
+
else
|
12
|
+
string.to_s
|
13
|
+
end
|
14
|
+
when true; "true"
|
15
|
+
when false; "false"
|
16
|
+
else
|
17
|
+
string.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
data/src/extract.rb
CHANGED
@@ -1,15 +1,6 @@
|
|
1
|
-
require_relative 'extract/check_for_unknown_functions'
|
2
|
-
require_relative "extract/extract_array_formulae"
|
3
|
-
require_relative "extract/extract_formulae"
|
4
1
|
require_relative "extract/extract_relationships"
|
5
|
-
require_relative "extract/extract_shared_formulae"
|
6
|
-
require_relative "extract/extract_shared_formulae_targets"
|
7
2
|
require_relative "extract/extract_shared_strings"
|
8
|
-
require_relative "extract/extract_simple_formulae"
|
9
|
-
require_relative "extract/extract_values"
|
10
|
-
require_relative "extract/extract_worksheet_dimensions"
|
11
3
|
require_relative "extract/extract_worksheet_names"
|
12
4
|
require_relative "extract/extract_named_references"
|
13
|
-
require_relative "extract/extract_worksheet_table_relationships"
|
14
5
|
require_relative "extract/extract_table"
|
15
|
-
require_relative "extract/
|
6
|
+
require_relative "extract/extract_data_from_worksheet"
|
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
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.3
|
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:
|
11
|
+
date: 2014-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubypeg
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: nokogiri
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 1.5.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 1.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: 2.7.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 2.7.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: ffi
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 1.0.11
|
62
62
|
type: :runtime
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: 1.0.11
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: ox
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: 2.0.12
|
76
76
|
type: :runtime
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: 2.0.12
|
83
83
|
description: "# excel_to_code\n\nConverts some excel spreadsheets (.xlsx, not .xls)
|
@@ -108,30 +108,35 @@ extra_rdoc_files: []
|
|
108
108
|
files:
|
109
109
|
- README.md
|
110
110
|
- TODO
|
111
|
+
- bin/excel_to_c
|
112
|
+
- bin/excel_to_ruby
|
113
|
+
- src/commands.rb
|
111
114
|
- src/commands/excel_to_c.rb
|
112
115
|
- src/commands/excel_to_ruby.rb
|
113
116
|
- src/commands/excel_to_x.rb
|
114
|
-
- src/
|
117
|
+
- src/compile.rb
|
118
|
+
- src/compile/c.rb
|
115
119
|
- src/compile/c/a.out
|
116
120
|
- src/compile/c/compile_named_reference_setters.rb
|
117
121
|
- src/compile/c/compile_to_c.rb
|
118
122
|
- src/compile/c/compile_to_c_header.rb
|
119
123
|
- src/compile/c/compile_to_c_unit_test.rb
|
120
124
|
- src/compile/c/excel_to_c_runtime.c
|
125
|
+
- src/compile/c/excel_to_c_runtime_test.c
|
121
126
|
- src/compile/c/map_formulae_to_c.rb
|
122
127
|
- src/compile/c/map_sheet_names_to_c_names.rb
|
123
128
|
- src/compile/c/map_values_to_c.rb
|
124
129
|
- src/compile/c/map_values_to_c_structs.rb
|
125
|
-
- src/compile/
|
130
|
+
- src/compile/ruby.rb
|
126
131
|
- src/compile/ruby/compile_to_ruby.rb
|
127
132
|
- src/compile/ruby/compile_to_ruby_unit_test.rb
|
128
133
|
- src/compile/ruby/excel_to_ruby_runtime.rb
|
129
134
|
- src/compile/ruby/map_formulae_to_ruby.rb
|
130
135
|
- src/compile/ruby/map_sheet_names_to_ruby_names.rb
|
131
136
|
- src/compile/ruby/map_values_to_ruby.rb
|
132
|
-
- src/
|
133
|
-
- src/compile.rb
|
137
|
+
- src/excel.rb
|
134
138
|
- src/excel/area.rb
|
139
|
+
- src/excel/excel_functions.rb
|
135
140
|
- src/excel/excel_functions/abs.rb
|
136
141
|
- src/excel/excel_functions/add.rb
|
137
142
|
- src/excel/excel_functions/and.rb
|
@@ -158,6 +163,7 @@ files:
|
|
158
163
|
- src/excel/excel_functions/less_than.rb
|
159
164
|
- src/excel/excel_functions/less_than_or_equal.rb
|
160
165
|
- src/excel/excel_functions/log.rb
|
166
|
+
- src/excel/excel_functions/lower.rb
|
161
167
|
- src/excel/excel_functions/max.rb
|
162
168
|
- src/excel/excel_functions/mid.rb
|
163
169
|
- src/excel/excel_functions/min.rb
|
@@ -189,30 +195,19 @@ files:
|
|
189
195
|
- src/excel/excel_functions/text.rb
|
190
196
|
- src/excel/excel_functions/trim.rb
|
191
197
|
- src/excel/excel_functions/vlookup.rb
|
192
|
-
- src/excel/excel_functions.rb
|
193
198
|
- src/excel/formula_peg.rb
|
194
199
|
- src/excel/formula_peg.txt
|
195
200
|
- src/excel/reference.rb
|
196
201
|
- src/excel/table.rb
|
197
|
-
- src/excel.rb
|
198
202
|
- src/excel_to_code.rb
|
199
|
-
- src/extract
|
200
|
-
- src/extract/
|
201
|
-
- src/extract/extract_everything.rb
|
202
|
-
- src/extract/extract_formulae.rb
|
203
|
+
- src/extract.rb
|
204
|
+
- src/extract/extract_data_from_worksheet.rb
|
203
205
|
- src/extract/extract_named_references.rb
|
204
206
|
- src/extract/extract_relationships.rb
|
205
|
-
- src/extract/extract_shared_formulae.rb
|
206
|
-
- src/extract/extract_shared_formulae_targets.rb
|
207
207
|
- src/extract/extract_shared_strings.rb
|
208
|
-
- src/extract/extract_simple_formulae.rb
|
209
208
|
- src/extract/extract_table.rb
|
210
|
-
- src/extract/extract_values.rb
|
211
|
-
- src/extract/extract_worksheet_dimensions.rb
|
212
209
|
- src/extract/extract_worksheet_names.rb
|
213
|
-
- src/
|
214
|
-
- src/extract/simple_extract_from_xml.rb
|
215
|
-
- src/extract.rb
|
210
|
+
- src/rewrite.rb
|
216
211
|
- src/rewrite/ast_copy_formula.rb
|
217
212
|
- src/rewrite/ast_expand_array_formulae.rb
|
218
213
|
- src/rewrite/caching_formula_parser.rb
|
@@ -227,7 +222,7 @@ files:
|
|
227
222
|
- src/rewrite/rewrite_values_to_ast.rb
|
228
223
|
- src/rewrite/rewrite_whole_row_column_references_to_areas.rb
|
229
224
|
- src/rewrite/rewrite_worksheet_names.rb
|
230
|
-
- src/
|
225
|
+
- src/simplify.rb
|
231
226
|
- src/simplify/count_formula_references.rb
|
232
227
|
- src/simplify/emergency_array_formula_replace_indirect_bodge.rb
|
233
228
|
- src/simplify/identify_dependencies.rb
|
@@ -251,12 +246,9 @@ files:
|
|
251
246
|
- src/simplify/simplify_arithmetic.rb
|
252
247
|
- src/simplify/sort_into_calculation_order.rb
|
253
248
|
- src/simplify/wrap_formulae_that_return_arrays_and_are_not_in_arrays.rb
|
254
|
-
- src/
|
249
|
+
- src/util.rb
|
255
250
|
- src/util/not_supported_exception.rb
|
256
251
|
- src/util/try.rb
|
257
|
-
- src/util.rb
|
258
|
-
- bin/excel_to_c
|
259
|
-
- bin/excel_to_ruby
|
260
252
|
homepage: http://github.com/tamc/excel_to_code
|
261
253
|
licenses:
|
262
254
|
- MIT
|
@@ -267,20 +259,19 @@ require_paths:
|
|
267
259
|
- src
|
268
260
|
required_ruby_version: !ruby/object:Gem::Requirement
|
269
261
|
requirements:
|
270
|
-
- -
|
262
|
+
- - ">="
|
271
263
|
- !ruby/object:Gem::Version
|
272
264
|
version: 1.9.1
|
273
265
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
274
266
|
requirements:
|
275
|
-
- -
|
267
|
+
- - ">="
|
276
268
|
- !ruby/object:Gem::Version
|
277
269
|
version: '0'
|
278
270
|
requirements: []
|
279
271
|
rubyforge_project:
|
280
|
-
rubygems_version: 2.0
|
272
|
+
rubygems_version: 2.2.0
|
281
273
|
signing_key:
|
282
274
|
specification_version: 4
|
283
275
|
summary: Converts .xlxs files into pure ruby 1.9 code or pure C code so that they
|
284
276
|
can be executed without excel
|
285
277
|
test_files: []
|
286
|
-
has_rdoc: false
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require_relative '../compile/ruby/map_formulae_to_ruby'
|
2
|
-
|
3
|
-
class CheckForUnknownFunctions
|
4
|
-
|
5
|
-
attr_accessor :settable
|
6
|
-
|
7
|
-
def self.rewrite(*args)
|
8
|
-
self.new.rewrite(*args)
|
9
|
-
end
|
10
|
-
|
11
|
-
def check(input,output)
|
12
|
-
self.settable ||= lambda { |ref| false }
|
13
|
-
input.each_line do |line|
|
14
|
-
line.scan(/\[:function, :["']?([A-Z ]+)['"]?/).each do |match|
|
15
|
-
output.puts $1 unless MapFormulaeToRuby::FUNCTIONS.has_key?($1.to_sym)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative 'extract_formulae'
|
2
|
-
|
3
|
-
class ExtractArrayFormulae < ExtractFormulae
|
4
|
-
|
5
|
-
def start_formula(type,attributes)
|
6
|
-
return unless type == 'array' && attributes.assoc('ref')
|
7
|
-
@array_range = attributes.assoc('ref').last
|
8
|
-
@parsing = true
|
9
|
-
end
|
10
|
-
|
11
|
-
def write_formula
|
12
|
-
return if @formula.empty?
|
13
|
-
formula_text = @formula.join.gsub(/[\r\n]+/,'')
|
14
|
-
ast = CachingFormulaParser.parse(formula_text)
|
15
|
-
unless ast
|
16
|
-
$stderr.puts "Could not parse #{@sheet_name} #{@ref} #{formula_text}"
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
# FIXME: Should leave in original form rather than converting to ast?
|
20
|
-
@output[[@sheet_name, @ref]] = [@array_range, ast]
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|
@@ -1,46 +0,0 @@
|
|
1
|
-
require 'nokogiri'
|
2
|
-
|
3
|
-
class ExtractFormulae < Nokogiri::XML::SAX::Document
|
4
|
-
|
5
|
-
def self.extract(*args)
|
6
|
-
self.new.extract(*args)
|
7
|
-
end
|
8
|
-
|
9
|
-
def extract(sheet_name, input)
|
10
|
-
@sheet_name = sheet_name.to_sym
|
11
|
-
@output = {}
|
12
|
-
@parsing = false
|
13
|
-
Nokogiri::XML::SAX::Parser.new(self).parse(input)
|
14
|
-
@output
|
15
|
-
end
|
16
|
-
|
17
|
-
def start_element(name,attributes)
|
18
|
-
if name == 'c'
|
19
|
-
@ref = attributes.assoc('r').last.to_sym
|
20
|
-
elsif name == "f"
|
21
|
-
type = attributes.assoc('t')
|
22
|
-
@formula = []
|
23
|
-
start_formula( type && type.last, attributes)
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def end_element(name)
|
28
|
-
return unless @parsing && name == "f"
|
29
|
-
@parsing = false
|
30
|
-
write_formula
|
31
|
-
end
|
32
|
-
|
33
|
-
def characters(string)
|
34
|
-
return unless @parsing
|
35
|
-
@formula.push(string)
|
36
|
-
end
|
37
|
-
|
38
|
-
def start_formula(type,attributes)
|
39
|
-
# Override
|
40
|
-
end
|
41
|
-
|
42
|
-
def write_formula
|
43
|
-
# Override
|
44
|
-
end
|
45
|
-
|
46
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require_relative 'extract_formulae'
|
2
|
-
|
3
|
-
class ExtractSharedFormulae < ExtractFormulae
|
4
|
-
|
5
|
-
def start_formula(type,attributes)
|
6
|
-
return unless type == 'shared' && attributes.assoc('ref')
|
7
|
-
@shared_range = attributes.assoc('ref').last
|
8
|
-
@shared_formula_identifier = attributes.assoc('si').last
|
9
|
-
@parsing = true
|
10
|
-
end
|
11
|
-
|
12
|
-
def write_formula
|
13
|
-
return if @formula.empty?
|
14
|
-
formula_text = @formula.join.gsub(/[\r\n]+/,'')
|
15
|
-
ast = CachingFormulaParser.parse(formula_text)
|
16
|
-
unless ast
|
17
|
-
$stderr.puts "Could not parse #{@sheet_name} #{@ref} #{formula_text}"
|
18
|
-
exit
|
19
|
-
end
|
20
|
-
# FIXME: Should leave in original form rather than converting to ast?
|
21
|
-
@output[[@sheet_name, @ref]] = [@shared_range, @shared_formula_identifier, ast]
|
22
|
-
end
|
23
|
-
|
24
|
-
end
|
@@ -1,15 +0,0 @@
|
|
1
|
-
require_relative 'extract_formulae'
|
2
|
-
|
3
|
-
class ExtractSharedFormulaeTargets < ExtractFormulae
|
4
|
-
|
5
|
-
def start_formula(type,attributes)
|
6
|
-
return unless type == 'shared'
|
7
|
-
@shared_formula_identifier = attributes.assoc('si').last
|
8
|
-
@parsing = true
|
9
|
-
end
|
10
|
-
|
11
|
-
def write_formula
|
12
|
-
@output[[@sheet_name, @ref]] = @shared_formula_identifier
|
13
|
-
end
|
14
|
-
|
15
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
require_relative 'extract_formulae'
|
2
|
-
|
3
|
-
class ExtractSimpleFormulae < ExtractFormulae
|
4
|
-
|
5
|
-
def start_formula(type,attributes)
|
6
|
-
# Simple formulas don't have a type
|
7
|
-
return if type
|
8
|
-
@parsing = true
|
9
|
-
end
|
10
|
-
|
11
|
-
def write_formula
|
12
|
-
return if @formula.empty?
|
13
|
-
formula_text = @formula.join.gsub(/[\r\n]+/,'')
|
14
|
-
ast = CachingFormulaParser.parse(formula_text)
|
15
|
-
unless ast
|
16
|
-
$stderr.puts "Could not parse #{@sheet_name} #{@ref} #{formula_text}"
|
17
|
-
exit
|
18
|
-
end
|
19
|
-
# FIXME: Should leave in original form rather than converting to ast?
|
20
|
-
@output[[@sheet_name, @ref]] = ast
|
21
|
-
end
|
22
|
-
|
23
|
-
end
|