excel_to_code 0.3.13 → 0.3.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8913cb43d387cfb52e6a6ad5ef5a8554758164ef
4
- data.tar.gz: c305a04d9de3fd7b1f6c3608787820db3ec47601
3
+ metadata.gz: 4708f58031f15c26a9b1f63bafefb4f1188044a6
4
+ data.tar.gz: 384d5599d104b8591a1dd38344da83e1d118efab
5
5
  SHA512:
6
- metadata.gz: 76e98bfafc8a0ee0832b4e735c8b9eb49658e36dcc7f2d4063bc1e945ed55e45e6e8422ee20659b513ce59c881ff60c3d11159dabb38c052162a48774187fb4a
7
- data.tar.gz: a43591e548cd6ee59e1ef907a109fa77151bbd017f8027f1cd2351882e641f8fca05461b5070a7a6e7534ce30c031b380f8fc8f25e2a460f837b341b114b1826
6
+ metadata.gz: 5a6c02501134cc3e84a4814e403add71e6bed25d8252f16ea93c8e4e964a21f3a192b644759fcc0409c91f2bb72de87a3b77292e10c542bd8ff546b636869e57
7
+ data.tar.gz: 0f37ecbf4955e480e421f24eedb74b2f88b641ac82202a817e6052ba021493d1a15ec41bd37e347bea6c2652ca5887040843285f7aa1b80909fd70d21e24bcd8
data/README.md CHANGED
@@ -45,7 +45,6 @@ There are some how to guides in the doc folder.
45
45
  4. Doesn't implement references that involve range unions and lists (but does implement standard ranges)
46
46
  5. Sometimes gives cells as being empty, when excel would give the cell as having a numeric value of zero
47
47
  6. The generated C version does not multithread and will give bad results if you try
48
- 7. Newlines are removed from strings
49
- 8. The generated code uses floating point, rather than fully precise arithmetic, so results can differ slightly
50
- 9. The generated code uses the sprintf approach to rounding (even-odd) rather than excel's 0.5 rounds away from zero.
51
- 10. Ranges like this: Sheet1!A10:Sheet1!B20 and 3D ranges don't work
48
+ 7. The generated code uses floating point, rather than fully precise arithmetic, so results can differ slightly
49
+ 8. The generated code uses the sprintf approach to rounding (even-odd) rather than excel's 0.5 rounds away from zero.
50
+ 90. Ranges like this: Sheet1!A10:Sheet1!B20 and 3D ranges don't work
@@ -239,7 +239,7 @@ class #{ruby_module_name}
239
239
  end
240
240
  end
241
241
  return a
242
- when :ExcelError; [:value,:name,:div0,:ref,:na][excel_value[:number]]
242
+ when :ExcelError; [:value,:name,:div0,:ref,:na,:num][excel_value[:number]]
243
243
  else
244
244
  raise Exception.new("ExcelValue type \u0023{excel_value[:type].inspect} not recognised")
245
245
  end
@@ -8,6 +8,7 @@ module ExcelFunctions
8
8
  return rate if rate.is_a?(Symbol)
9
9
  return number_of_periods if number_of_periods.is_a?(Symbol)
10
10
  return present_value if present_value.is_a?(Symbol)
11
+ return :num if number_of_periods == 0
11
12
 
12
13
  return -(present_value / number_of_periods) if rate == 0
13
14
  -present_value*(rate*((1+rate)**number_of_periods))/(((1+rate)**number_of_periods)-1)
@@ -11,7 +11,7 @@ module ExcelFunctions
11
11
  return b if b.is_a?(Symbol)
12
12
 
13
13
  return 1 if b ==0 # Special case so can do the following negative number check
14
- return :num if a < 1 && b < 1
14
+ return :num if a < 0 && b < 1
15
15
 
16
16
  a**b
17
17
  end
data/src/excel_to_code.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  class ExcelToCode
2
- def self.version() "0.3.13" end
2
+ def self.version() "0.3.14" end
3
3
  end
4
4
 
5
5
  require_relative 'commands'
@@ -69,7 +69,7 @@ class ExtractDataFromWorksheet < ::Ox::Sax
69
69
  when 's'; [:shared_string, value.to_i]
70
70
  when 'n'; [:number, value.to_f]
71
71
  when 'e'; [:error, value.to_sym]
72
- when 'str'; [:string, value.gsub(/_x[0-9A-F]{4}_/,'').freeze]
72
+ when 'str'; [:string, convert_excels_unicode_escaping(value).freeze]
73
73
  else
74
74
  $stderr.puts "Value of type #{@value_type} not known #{@sheet_name} #{@ref}"
75
75
  exit
@@ -146,4 +146,13 @@ class ExtractDataFromWorksheet < ::Ox::Sax
146
146
  end
147
147
  end
148
148
 
149
+ # Excel encodes unicode as _x000D_ where the 000D
150
+ # is the unicode codepoint
151
+ def convert_excels_unicode_escaping(excel_string)
152
+ excel_string.gsub(/_x([0-9A-F]{4})_/) do
153
+ unicode_codepoint = $1
154
+ [unicode_codepoint.hex].pack("U")
155
+ end
156
+ end
157
+
149
158
  end
@@ -94,6 +94,11 @@ class CachingFormulaParser
94
94
  end
95
95
 
96
96
  def sheet_reference(ast)
97
+ # Sheet names shouldn't start with [1], because those are
98
+ # external references
99
+ if ast[1] =~ /^\[\d+\]/
100
+ raise ExternalReferenceException.new(ast, @full_ast, @text)
101
+ end
97
102
  ast[1] = ast[1].to_sym
98
103
  ast[2] = map(ast[2])
99
104
  # We do this to deal with Control!#REF! style rerferences
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.3.13
4
+ version: 0.3.14
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: 2015-03-02 00:00:00.000000000 Z
11
+ date: 2015-03-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rubypeg
@@ -102,11 +102,11 @@ description: "# excel_to_code\n\nConverts some excel spreadsheets (.xlsx, not .x
102
102
  Doesn't implement references that involve range unions and lists (but does implement
103
103
  standard ranges)\n5. Sometimes gives cells as being empty, when excel would give
104
104
  the cell as having a numeric value of zero\n6. The generated C version does not
105
- multithread and will give bad results if you try\n7. Newlines are removed from strings\n8.
106
- The generated code uses floating point, rather than fully precise arithmetic, so
107
- results can differ slightly\n9. The generated code uses the sprintf approach to
108
- rounding (even-odd) rather than excel's 0.5 rounds away from zero.\n10. Ranges like
109
- this: Sheet1!A10:Sheet1!B20 and 3D ranges don't work\n"
105
+ multithread and will give bad results if you try\n7. The generated code uses floating
106
+ point, rather than fully precise arithmetic, so results can differ slightly\n8.
107
+ The generated code uses the sprintf approach to rounding (even-odd) rather than
108
+ excel's 0.5 rounds away from zero.\n90. Ranges like this: Sheet1!A10:Sheet1!B20
109
+ and 3D ranges don't work\n"
110
110
  email: tamc@greenonblack.com
111
111
  executables:
112
112
  - excel_to_c