rubyfromexcel 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (188) hide show
  1. data/README +22 -0
  2. data/bin/rubyfromexcel +20 -0
  3. data/examples/create_and_test_examples.rb +37 -0
  4. data/examples/ruby-versions/array-formulas-ruby/sheets/sheet1.rb +59 -0
  5. data/examples/ruby-versions/array-formulas-ruby/sheets/sheet2.rb +9 -0
  6. data/examples/ruby-versions/array-formulas-ruby/specs/sheet1_rspec.rb +156 -0
  7. data/examples/ruby-versions/array-formulas-ruby/specs/sheet2_rspec.rb +8 -0
  8. data/examples/ruby-versions/array-formulas-ruby/spreadsheet.rb +9 -0
  9. data/examples/ruby-versions/complex-test-ruby/sheets/sheet1.rb +305 -0
  10. data/examples/ruby-versions/complex-test-ruby/sheets/sheet2.rb +147 -0
  11. data/examples/ruby-versions/complex-test-ruby/specs/sheet1_rspec.rb +876 -0
  12. data/examples/ruby-versions/complex-test-ruby/specs/sheet2_rspec.rb +412 -0
  13. data/examples/ruby-versions/complex-test-ruby/spreadsheet.rb +9 -0
  14. data/examples/ruby-versions/namedReferenceTest-ruby/sheets/sheet1.rb +9 -0
  15. data/examples/ruby-versions/namedReferenceTest-ruby/sheets/sheet2.rb +8 -0
  16. data/examples/ruby-versions/namedReferenceTest-ruby/specs/sheet1_rspec.rb +16 -0
  17. data/examples/ruby-versions/namedReferenceTest-ruby/specs/sheet2_rspec.rb +16 -0
  18. data/examples/ruby-versions/namedReferenceTest-ruby/spreadsheet.rb +9 -0
  19. data/examples/ruby-versions/pruning-ruby/sheets/sheet1.rb +11 -0
  20. data/examples/ruby-versions/pruning-ruby/sheets/sheet2.rb +14 -0
  21. data/examples/ruby-versions/pruning-ruby/sheets/sheet3.rb +7 -0
  22. data/examples/ruby-versions/pruning-ruby/specs/sheet1_rspec.rb +20 -0
  23. data/examples/ruby-versions/pruning-ruby/specs/sheet2_rspec.rb +20 -0
  24. data/examples/ruby-versions/pruning-ruby/specs/sheet3_rspec.rb +8 -0
  25. data/examples/ruby-versions/pruning-ruby/spreadsheet.rb +9 -0
  26. data/examples/ruby-versions/sharedFormulaTest-ruby/sheets/sheet1.rb +15 -0
  27. data/examples/ruby-versions/sharedFormulaTest-ruby/specs/sheet1_rspec.rb +44 -0
  28. data/examples/ruby-versions/sharedFormulaTest-ruby/spreadsheet.rb +9 -0
  29. data/examples/ruby-versions/table-test-ruby/sheets/sheet1.rb +17 -0
  30. data/examples/ruby-versions/table-test-ruby/sheets/sheet2.rb +5 -0
  31. data/examples/ruby-versions/table-test-ruby/sheets/sheet3.rb +5 -0
  32. data/examples/ruby-versions/table-test-ruby/specs/sheet1_rspec.rb +20 -0
  33. data/examples/ruby-versions/table-test-ruby/specs/sheet2_rspec.rb +8 -0
  34. data/examples/ruby-versions/table-test-ruby/specs/sheet3_rspec.rb +8 -0
  35. data/examples/ruby-versions/table-test-ruby/spreadsheet.rb +9 -0
  36. data/examples/sheets/array-formulas.xlsx +0 -0
  37. data/examples/sheets/complex-test.xlsx +0 -0
  38. data/examples/sheets/namedReferenceTest.xlsx +0 -0
  39. data/examples/sheets/pruning.xlsx +0 -0
  40. data/examples/sheets/sharedFormulaTest.xlsx +0 -0
  41. data/examples/sheets/table-test.xlsx +0 -0
  42. data/examples/sheets/~$array-formulas.xlsx +0 -0
  43. data/examples/unzipped-sheets/array-formulas/[Content_Types].xml +2 -0
  44. data/examples/unzipped-sheets/array-formulas/docProps/app.xml +2 -0
  45. data/examples/unzipped-sheets/array-formulas/docProps/core.xml +2 -0
  46. data/examples/unzipped-sheets/array-formulas/docProps/thumbnail.jpeg +0 -0
  47. data/examples/unzipped-sheets/array-formulas/xl/_rels/workbook.xml.rels +2 -0
  48. data/examples/unzipped-sheets/array-formulas/xl/calcChain.xml +2 -0
  49. data/examples/unzipped-sheets/array-formulas/xl/sharedStrings.xml +2 -0
  50. data/examples/unzipped-sheets/array-formulas/xl/styles.xml +2 -0
  51. data/examples/unzipped-sheets/array-formulas/xl/theme/theme1.xml +2 -0
  52. data/examples/unzipped-sheets/array-formulas/xl/workbook.xml +2 -0
  53. data/examples/unzipped-sheets/array-formulas/xl/worksheets/sheet1.xml +2 -0
  54. data/examples/unzipped-sheets/array-formulas/xl/worksheets/sheet2.xml +2 -0
  55. data/examples/unzipped-sheets/complex-test/[Content_Types].xml +2 -0
  56. data/examples/unzipped-sheets/complex-test/docProps/app.xml +2 -0
  57. data/examples/unzipped-sheets/complex-test/docProps/core.xml +2 -0
  58. data/examples/unzipped-sheets/complex-test/xl/_rels/workbook.xml.rels +2 -0
  59. data/examples/unzipped-sheets/complex-test/xl/calcChain.xml +2 -0
  60. data/examples/unzipped-sheets/complex-test/xl/charts/chart1.xml +2 -0
  61. data/examples/unzipped-sheets/complex-test/xl/charts/chart2.xml +2 -0
  62. data/examples/unzipped-sheets/complex-test/xl/comments1.xml +5 -0
  63. data/examples/unzipped-sheets/complex-test/xl/comments2.xml +5 -0
  64. data/examples/unzipped-sheets/complex-test/xl/drawings/_rels/drawing1.xml.rels +2 -0
  65. data/examples/unzipped-sheets/complex-test/xl/drawings/_rels/drawing2.xml.rels +2 -0
  66. data/examples/unzipped-sheets/complex-test/xl/drawings/drawing1.xml +2 -0
  67. data/examples/unzipped-sheets/complex-test/xl/drawings/drawing2.xml +2 -0
  68. data/examples/unzipped-sheets/complex-test/xl/drawings/vmlDrawing1.vml +46 -0
  69. data/examples/unzipped-sheets/complex-test/xl/drawings/vmlDrawing2.vml +46 -0
  70. data/examples/unzipped-sheets/complex-test/xl/sharedStrings.xml +2 -0
  71. data/examples/unzipped-sheets/complex-test/xl/styles.xml +2 -0
  72. data/examples/unzipped-sheets/complex-test/xl/theme/theme1.xml +2 -0
  73. data/examples/unzipped-sheets/complex-test/xl/workbook.xml +2 -0
  74. data/examples/unzipped-sheets/complex-test/xl/worksheets/_rels/sheet1.xml.rels +2 -0
  75. data/examples/unzipped-sheets/complex-test/xl/worksheets/_rels/sheet2.xml.rels +2 -0
  76. data/examples/unzipped-sheets/complex-test/xl/worksheets/sheet1.xml +2 -0
  77. data/examples/unzipped-sheets/complex-test/xl/worksheets/sheet2.xml +2 -0
  78. data/examples/unzipped-sheets/namedReferenceTest/[Content_Types].xml +2 -0
  79. data/examples/unzipped-sheets/namedReferenceTest/docProps/app.xml +2 -0
  80. data/examples/unzipped-sheets/namedReferenceTest/docProps/core.xml +2 -0
  81. data/examples/unzipped-sheets/namedReferenceTest/docProps/thumbnail.jpeg +0 -0
  82. data/examples/unzipped-sheets/namedReferenceTest/xl/_rels/workbook.xml.rels +2 -0
  83. data/examples/unzipped-sheets/namedReferenceTest/xl/calcChain.xml +2 -0
  84. data/examples/unzipped-sheets/namedReferenceTest/xl/styles.xml +2 -0
  85. data/examples/unzipped-sheets/namedReferenceTest/xl/theme/theme1.xml +2 -0
  86. data/examples/unzipped-sheets/namedReferenceTest/xl/workbook.xml +2 -0
  87. data/examples/unzipped-sheets/namedReferenceTest/xl/worksheets/sheet1.xml +2 -0
  88. data/examples/unzipped-sheets/namedReferenceTest/xl/worksheets/sheet2.xml +2 -0
  89. data/examples/unzipped-sheets/pruning/[Content_Types].xml +2 -0
  90. data/examples/unzipped-sheets/pruning/docProps/app.xml +2 -0
  91. data/examples/unzipped-sheets/pruning/docProps/core.xml +2 -0
  92. data/examples/unzipped-sheets/pruning/docProps/thumbnail.jpeg +0 -0
  93. data/examples/unzipped-sheets/pruning/xl/_rels/workbook.xml.rels +2 -0
  94. data/examples/unzipped-sheets/pruning/xl/calcChain.xml +2 -0
  95. data/examples/unzipped-sheets/pruning/xl/sharedStrings.xml +2 -0
  96. data/examples/unzipped-sheets/pruning/xl/styles.xml +2 -0
  97. data/examples/unzipped-sheets/pruning/xl/theme/theme1.xml +2 -0
  98. data/examples/unzipped-sheets/pruning/xl/workbook.xml +2 -0
  99. data/examples/unzipped-sheets/pruning/xl/worksheets/sheet1.xml +2 -0
  100. data/examples/unzipped-sheets/pruning/xl/worksheets/sheet2.xml +2 -0
  101. data/examples/unzipped-sheets/pruning/xl/worksheets/sheet3.xml +2 -0
  102. data/examples/unzipped-sheets/sharedFormulaTest/[Content_Types].xml +2 -0
  103. data/examples/unzipped-sheets/sharedFormulaTest/docProps/app.xml +2 -0
  104. data/examples/unzipped-sheets/sharedFormulaTest/docProps/core.xml +2 -0
  105. data/examples/unzipped-sheets/sharedFormulaTest/docProps/thumbnail.jpeg +0 -0
  106. data/examples/unzipped-sheets/sharedFormulaTest/xl/_rels/workbook.xml.rels +2 -0
  107. data/examples/unzipped-sheets/sharedFormulaTest/xl/calcChain.xml +2 -0
  108. data/examples/unzipped-sheets/sharedFormulaTest/xl/styles.xml +2 -0
  109. data/examples/unzipped-sheets/sharedFormulaTest/xl/theme/theme1.xml +2 -0
  110. data/examples/unzipped-sheets/sharedFormulaTest/xl/workbook.xml +2 -0
  111. data/examples/unzipped-sheets/sharedFormulaTest/xl/worksheets/sheet1.xml +2 -0
  112. data/examples/unzipped-sheets/table-test/[Content_Types].xml +2 -0
  113. data/examples/unzipped-sheets/table-test/docProps/app.xml +2 -0
  114. data/examples/unzipped-sheets/table-test/docProps/core.xml +2 -0
  115. data/examples/unzipped-sheets/table-test/xl/_rels/workbook.xml.rels +2 -0
  116. data/examples/unzipped-sheets/table-test/xl/calcChain.xml +2 -0
  117. data/examples/unzipped-sheets/table-test/xl/printerSettings/printerSettings1.bin +0 -0
  118. data/examples/unzipped-sheets/table-test/xl/sharedStrings.xml +2 -0
  119. data/examples/unzipped-sheets/table-test/xl/styles.xml +2 -0
  120. data/examples/unzipped-sheets/table-test/xl/tables/table1.xml +2 -0
  121. data/examples/unzipped-sheets/table-test/xl/theme/theme1.xml +2 -0
  122. data/examples/unzipped-sheets/table-test/xl/workbook.xml +2 -0
  123. data/examples/unzipped-sheets/table-test/xl/worksheets/_rels/sheet1.xml.rels +2 -0
  124. data/examples/unzipped-sheets/table-test/xl/worksheets/sheet1.xml +2 -0
  125. data/examples/unzipped-sheets/table-test/xl/worksheets/sheet2.xml +2 -0
  126. data/examples/unzipped-sheets/table-test/xl/worksheets/sheet3.xml +2 -0
  127. data/lib/cells/array/array_formula_builder.rb +58 -0
  128. data/lib/cells/array/array_formula_cell.rb +27 -0
  129. data/lib/cells/array/arraying_formula_cell.rb +67 -0
  130. data/lib/cells/array/single_cell_array_formula_builder.rb +9 -0
  131. data/lib/cells/array/single_cell_array_formula_cell.rb +11 -0
  132. data/lib/cells/cell.rb +98 -0
  133. data/lib/cells/cells.rb +9 -0
  134. data/lib/cells/formula/formula_cell.rb +18 -0
  135. data/lib/cells/formula/simple_formula_cell.rb +4 -0
  136. data/lib/cells/shared/shared_formula_builder.rb +15 -0
  137. data/lib/cells/shared/shared_formula_cell.rb +20 -0
  138. data/lib/cells/shared/sharing_formula_cell.rb +36 -0
  139. data/lib/cells/value/value_cell.rb +24 -0
  140. data/lib/excelfile/excelfile.rb +6 -0
  141. data/lib/excelfile/relationships.rb +24 -0
  142. data/lib/excelfile/shared_strings.rb +21 -0
  143. data/lib/excelfile/sheet_names.rb +6 -0
  144. data/lib/excelfile/table.rb +116 -0
  145. data/lib/excelfile/workbook.rb +108 -0
  146. data/lib/excelfile/worksheet.rb +122 -0
  147. data/lib/formulae/compile/formula_builder.rb +316 -0
  148. data/lib/formulae/formulae.rb +6 -0
  149. data/lib/formulae/parse/formula_peg.rb +213 -0
  150. data/lib/formulae/parse/formula_peg.txt +40 -0
  151. data/lib/formulae/run/excel_functions.rb +375 -0
  152. data/lib/formulae/run/excel_matrix.rb +114 -0
  153. data/lib/formulae/run/excel_range.rb +256 -0
  154. data/lib/formulae/run/reference.rb +79 -0
  155. data/lib/optimiser/dependency_builder.rb +86 -0
  156. data/lib/optimiser/optimiser.rb +3 -0
  157. data/lib/optimiser/shared_formula_dependency_builder.rb +43 -0
  158. data/lib/optimiser/workbook_pruner.rb +80 -0
  159. data/lib/rubyfromexcel.rb +105 -0
  160. data/lib/runtime/runtime_formula_builder.rb +32 -0
  161. data/spec/array_formula_builder_spec.rb +35 -0
  162. data/spec/array_formula_cell_spec.rb +17 -0
  163. data/spec/arraying_formula_cell_spec.rb +38 -0
  164. data/spec/dependency_builder_spec.rb +71 -0
  165. data/spec/excel_functions_spec.rb +381 -0
  166. data/spec/excel_matrix_spec.rb +92 -0
  167. data/spec/excel_range_spec.rb +161 -0
  168. data/spec/formula_builder_spec.rb +230 -0
  169. data/spec/formula_peg_spec.rb +165 -0
  170. data/spec/reference_spec.rb +72 -0
  171. data/spec/relationships_spec.rb +51 -0
  172. data/spec/runtime_formula_builder_spec.rb +55 -0
  173. data/spec/shared_formula_builder_spec.rb +29 -0
  174. data/spec/shared_formula_cell_spec.rb +23 -0
  175. data/spec/shared_formula_dependency_builder_spec.rb +48 -0
  176. data/spec/shared_strings_spec.rb +14 -0
  177. data/spec/sharing_formula_cell_spec.rb +79 -0
  178. data/spec/simple_formula_cell_spec.rb +78 -0
  179. data/spec/single_cell_array_formula_builder_spec.rb +19 -0
  180. data/spec/single_cell_array_formula_cell_spec.rb +25 -0
  181. data/spec/spec_helper.rb +2 -0
  182. data/spec/table_spec.rb +100 -0
  183. data/spec/value_cell_spec.rb +49 -0
  184. data/spec/workbook_pruner_spec.rb +27 -0
  185. data/spec/workbook_spec.rb +283 -0
  186. data/spec/worksheet_failiures_spec.rb +41 -0
  187. data/spec/worksheet_spec.rb +486 -0
  188. metadata +291 -0
data/README ADDED
@@ -0,0 +1,22 @@
1
+ = RubyFromExcel
2
+
3
+ RubyFromExcel converts .xlxs files into pure ruby 1.9 code so that they can be executed without excel. i.e., whereas there are many libraries that allow you to read excel files, this one allows you to alter a cell on the sheet and then recalculate the values of all the other cells.
4
+
5
+ We use it so that we can transform an excel spreadsheet into a ruby on rails application.
6
+
7
+ We've made this library public now, because another open source project depends on it. That project works, but in other respects this library should be considered, at best, beta.
8
+
9
+ In particular:
10
+ 1. It is intended for programmers rather than end users
11
+ 2. Only a few excel formulas have been implemented (just enough to convert the spreadsheets we have needed to convert).
12
+ 3. It is ruby 1.9+ only
13
+ 4. The resulting code is not optimised
14
+ 5. It has a few examples of bad coding practice: in particular, it uses some singleton classes as global variables – bad things may happen if you use it to transform more than one excel at a time.
15
+
16
+ Patches to fix these and other drawbacks gratefully received via http://github.com/tamc/rubyfromexcel
17
+
18
+ To see how it works, look in the examples dir.
19
+
20
+ This software is (c) 2010 Green on Black Ltd and distributed under the open source MIT [http://www.opensource.org/licenses/mit-license.php] licence. (See LICENCE for the wording).
21
+
22
+
data/bin/rubyfromexcel ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'tmpdir'
4
+ require 'fileutils'
5
+ require_relative '../lib/rubyfromexcel'
6
+
7
+ spreadsheet = File.absolute_path(ARGV[0])
8
+ ruby_version = File.absolute_path(ARGV[1] || "#{File.basename(ARGV[0],".*")}-ruby")
9
+
10
+ unzipped_spreadsheet = Dir.mktmpdir
11
+
12
+ # The spreadsheet needs to be unzipped before starting
13
+ puts `unzip -uo #{spreadsheet} -d #{unzipped_spreadsheet}`
14
+
15
+ RubyFromExcel::Process.new do
16
+ self.source_excel_directory = unzipped_spreadsheet
17
+ self.target_ruby_directory = ruby_version
18
+ end.start!
19
+
20
+ FileUtils.rm_rf(unzipped_spreadsheet)
@@ -0,0 +1,37 @@
1
+ require_relative '../lib/rubyfromexcel'
2
+
3
+ def convert(basename)
4
+ # Need the original spreadsheet
5
+ spreadsheet = File.join(File.dirname(__FILE__),'sheets',"#{basename}.xlsx")
6
+
7
+ # A place to put an unzipped version of the spreadsheet (could be a tmp dir, but helpful for debugging if local)
8
+ unzipped_spreadsheet = File.join(File.dirname(__FILE__),'unzipped-sheets',basename)
9
+
10
+ # A place to put the resulting ruby version
11
+ ruby_version = File.join(File.dirname(__FILE__),'ruby-versions',"#{basename}-ruby")
12
+
13
+ puts "Converting #{spreadsheet} into #{ruby_version}"
14
+
15
+ # The spreadsheet needs to be unzipped before starting
16
+ puts `unzip -uo #{spreadsheet} -d #{unzipped_spreadsheet}`
17
+
18
+ RubyFromExcel::Process.new do
19
+ self.source_excel_directory = unzipped_spreadsheet
20
+ self.target_ruby_directory = ruby_version
21
+ self.skip_tests = false
22
+ if basename == "pruning"
23
+ self.prune_except_output_sheets = ['Outputs']
24
+ self.convert_independent_of_input_sheets = ['Inputs']
25
+ end
26
+ end.start!
27
+
28
+ puts
29
+ end
30
+
31
+ if ARGV[0]
32
+ convert ARGV[0]
33
+ else
34
+ %w{array-formulas complex-test namedReferenceTest sharedFormulaTest table-test pruning}.each do |basename|
35
+ convert basename
36
+ end
37
+ end
@@ -0,0 +1,59 @@
1
+ # coding: utf-8
2
+ # Sheet1
3
+ class Sheet1 < Spreadsheet
4
+ def b2; 1.0; end
5
+ def c2; 2.0; end
6
+ def d2; 3.0; end
7
+ def e2; 4.0; end
8
+ def a3; 1.0; end
9
+ def b3_array; @b3_array ||= m(a('b2','e2'),a('a3','a6')) { |r1,r2| r1+r2 }; end
10
+ def b3; @b3 ||= b3_array.array_formula_offset(0,0); end
11
+ def c3; @c3 ||= b3_array.array_formula_offset(0,1); end
12
+ def d3; @d3 ||= b3_array.array_formula_offset(0,2); end
13
+ def e3; @e3 ||= b3_array.array_formula_offset(0,3); end
14
+ def a4; 2.0; end
15
+ def b4; @b4 ||= b3_array.array_formula_offset(1,0); end
16
+ def c4; @c4 ||= b3_array.array_formula_offset(1,1); end
17
+ def d4; @d4 ||= b3_array.array_formula_offset(1,2); end
18
+ def e4; @e4 ||= b3_array.array_formula_offset(1,3); end
19
+ def a5; 3.0; end
20
+ def b5; @b5 ||= b3_array.array_formula_offset(2,0); end
21
+ def c5; @c5 ||= b3_array.array_formula_offset(2,1); end
22
+ def d5; @d5 ||= b3_array.array_formula_offset(2,2); end
23
+ def e5; @e5 ||= b3_array.array_formula_offset(2,3); end
24
+ def a6; 4.0; end
25
+ def b6; @b6 ||= b3_array.array_formula_offset(3,0); end
26
+ def c6; @c6 ||= b3_array.array_formula_offset(3,1); end
27
+ def d6; @d6 ||= b3_array.array_formula_offset(3,2); end
28
+ def e6; @e6 ||= b3_array.array_formula_offset(3,3); end
29
+ def a11; 1.0; end
30
+ def b11_array; @b11_array ||= m(a('a11','a14'),b2) { |r1,r2| r1+r2 }; end
31
+ def b11; @b11 ||= b11_array.array_formula_offset(0,0); end
32
+ def c11; @c11 ||= b11_array.array_formula_offset(0,1); end
33
+ def d11; @d11 ||= b11_array.array_formula_offset(0,2); end
34
+ def e11; @e11 ||= b11_array.array_formula_offset(0,3); end
35
+ def a12; 2.0; end
36
+ def b12; @b12 ||= b11_array.array_formula_offset(1,0); end
37
+ def c12; @c12 ||= b11_array.array_formula_offset(1,1); end
38
+ def d12; @d12 ||= b11_array.array_formula_offset(1,2); end
39
+ def e12; @e12 ||= b11_array.array_formula_offset(1,3); end
40
+ def a13; 3.0; end
41
+ def b13; @b13 ||= b11_array.array_formula_offset(2,0); end
42
+ def c13; @c13 ||= b11_array.array_formula_offset(2,1); end
43
+ def d13; @d13 ||= b11_array.array_formula_offset(2,2); end
44
+ def e13; @e13 ||= b11_array.array_formula_offset(2,3); end
45
+ def a14; 4.0; end
46
+ def b14; @b14 ||= b11_array.array_formula_offset(3,0); end
47
+ def c14; @c14 ||= b11_array.array_formula_offset(3,1); end
48
+ def d14; @d14 ||= b11_array.array_formula_offset(3,2); end
49
+ def e14; @e14 ||= b11_array.array_formula_offset(3,3); end
50
+ def c21_array; @c21_array ||= m(2.0,sheet2.a('b15','e15')) { |r1,r2| r1*r2 }; end
51
+ def c21; @c21 ||= c21_array.array_formula_offset(0,0); end
52
+ def d21; @d21 ||= c21_array.array_formula_offset(0,1); end
53
+ def e21; @e21 ||= c21_array.array_formula_offset(0,2); end
54
+ def f21; @f21 ||= c21_array.array_formula_offset(0,3); end
55
+ def g21; @g21 ||= c21_array.array_formula_offset(0,4); end
56
+ def d24; "This is, hopefully, the first shared string"; end
57
+ def d25; "This a second shared string"; end
58
+ end
59
+
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ # Sheet2
3
+ class Sheet2 < Spreadsheet
4
+ def b15; 2.0; end
5
+ def c15; 4.0; end
6
+ def d15; 6.0; end
7
+ def e15; 8.0; end
8
+ end
9
+
@@ -0,0 +1,156 @@
1
+ # coding: utf-8
2
+ require_relative '../spreadsheet'
3
+ # Sheet1
4
+ describe 'Sheet1' do
5
+ def sheet1; $spreadsheet ||= Spreadsheet.new; $spreadsheet.sheet1; end
6
+
7
+ it 'cell b3 should equal 2.0' do
8
+ sheet1.b3.should be_close(2.0,0.2)
9
+ end
10
+
11
+ it 'cell c3 should equal 3.0' do
12
+ sheet1.c3.should be_close(3.0,0.3)
13
+ end
14
+
15
+ it 'cell d3 should equal 4.0' do
16
+ sheet1.d3.should be_close(4.0,0.4)
17
+ end
18
+
19
+ it 'cell e3 should equal 5.0' do
20
+ sheet1.e3.should be_close(5.0,0.5)
21
+ end
22
+
23
+ it 'cell b4 should equal 3.0' do
24
+ sheet1.b4.should be_close(3.0,0.3)
25
+ end
26
+
27
+ it 'cell c4 should equal 4.0' do
28
+ sheet1.c4.should be_close(4.0,0.4)
29
+ end
30
+
31
+ it 'cell d4 should equal 5.0' do
32
+ sheet1.d4.should be_close(5.0,0.5)
33
+ end
34
+
35
+ it 'cell e4 should equal 6.0' do
36
+ sheet1.e4.should be_close(6.0,0.6)
37
+ end
38
+
39
+ it 'cell b5 should equal 4.0' do
40
+ sheet1.b5.should be_close(4.0,0.4)
41
+ end
42
+
43
+ it 'cell c5 should equal 5.0' do
44
+ sheet1.c5.should be_close(5.0,0.5)
45
+ end
46
+
47
+ it 'cell d5 should equal 6.0' do
48
+ sheet1.d5.should be_close(6.0,0.6)
49
+ end
50
+
51
+ it 'cell e5 should equal 7.0' do
52
+ sheet1.e5.should be_close(7.0,0.7)
53
+ end
54
+
55
+ it 'cell b6 should equal 5.0' do
56
+ sheet1.b6.should be_close(5.0,0.5)
57
+ end
58
+
59
+ it 'cell c6 should equal 6.0' do
60
+ sheet1.c6.should be_close(6.0,0.6)
61
+ end
62
+
63
+ it 'cell d6 should equal 7.0' do
64
+ sheet1.d6.should be_close(7.0,0.7)
65
+ end
66
+
67
+ it 'cell e6 should equal 8.0' do
68
+ sheet1.e6.should be_close(8.0,0.8)
69
+ end
70
+
71
+ it 'cell b11 should equal 2.0' do
72
+ sheet1.b11.should be_close(2.0,0.2)
73
+ end
74
+
75
+ it 'cell c11 should equal 2.0' do
76
+ sheet1.c11.should be_close(2.0,0.2)
77
+ end
78
+
79
+ it 'cell d11 should equal 2.0' do
80
+ sheet1.d11.should be_close(2.0,0.2)
81
+ end
82
+
83
+ it 'cell e11 should equal 2.0' do
84
+ sheet1.e11.should be_close(2.0,0.2)
85
+ end
86
+
87
+ it 'cell b12 should equal 3.0' do
88
+ sheet1.b12.should be_close(3.0,0.3)
89
+ end
90
+
91
+ it 'cell c12 should equal 3.0' do
92
+ sheet1.c12.should be_close(3.0,0.3)
93
+ end
94
+
95
+ it 'cell d12 should equal 3.0' do
96
+ sheet1.d12.should be_close(3.0,0.3)
97
+ end
98
+
99
+ it 'cell e12 should equal 3.0' do
100
+ sheet1.e12.should be_close(3.0,0.3)
101
+ end
102
+
103
+ it 'cell b13 should equal 4.0' do
104
+ sheet1.b13.should be_close(4.0,0.4)
105
+ end
106
+
107
+ it 'cell c13 should equal 4.0' do
108
+ sheet1.c13.should be_close(4.0,0.4)
109
+ end
110
+
111
+ it 'cell d13 should equal 4.0' do
112
+ sheet1.d13.should be_close(4.0,0.4)
113
+ end
114
+
115
+ it 'cell e13 should equal 4.0' do
116
+ sheet1.e13.should be_close(4.0,0.4)
117
+ end
118
+
119
+ it 'cell b14 should equal 5.0' do
120
+ sheet1.b14.should be_close(5.0,0.5)
121
+ end
122
+
123
+ it 'cell c14 should equal 5.0' do
124
+ sheet1.c14.should be_close(5.0,0.5)
125
+ end
126
+
127
+ it 'cell d14 should equal 5.0' do
128
+ sheet1.d14.should be_close(5.0,0.5)
129
+ end
130
+
131
+ it 'cell e14 should equal 5.0' do
132
+ sheet1.e14.should be_close(5.0,0.5)
133
+ end
134
+
135
+ it 'cell c21 should equal 4.0' do
136
+ sheet1.c21.should be_close(4.0,0.4)
137
+ end
138
+
139
+ it 'cell d21 should equal 8.0' do
140
+ sheet1.d21.should be_close(8.0,0.8)
141
+ end
142
+
143
+ it 'cell e21 should equal 12.0' do
144
+ sheet1.e21.should be_close(12.0,1.2)
145
+ end
146
+
147
+ it 'cell f21 should equal 16.0' do
148
+ sheet1.f21.should be_close(16.0,1.6)
149
+ end
150
+
151
+ it 'cell g21 should equal :na' do
152
+ sheet1.g21.should == :na
153
+ end
154
+
155
+ end
156
+
@@ -0,0 +1,8 @@
1
+ # coding: utf-8
2
+ require_relative '../spreadsheet'
3
+ # Sheet2
4
+ describe 'Sheet2' do
5
+ def sheet2; $spreadsheet ||= Spreadsheet.new; $spreadsheet.sheet2; end
6
+
7
+ end
8
+
@@ -0,0 +1,9 @@
1
+ # coding: utf-8
2
+ require 'rubyfromexcel'
3
+
4
+ class Spreadsheet
5
+ include RubyFromExcel::ExcelFunctions
6
+
7
+ end
8
+
9
+ Dir[File.join(File.dirname(__FILE__),"sheets/","sheet*.rb")].each {|f| Spreadsheet.autoload(File.basename(f,".rb").capitalize,f)}
@@ -0,0 +1,305 @@
1
+ # coding: utf-8
2
+ # EU
3
+ class Sheet1 < Spreadsheet
4
+ def b1; "Note, numbers not checked. Worry about power sector figure. Worry about the UK share of auction revenues."; end
5
+ def d2; "Expansion"; end
6
+ def d3; "Additions"; end
7
+ def o3; "Annual"; end
8
+ def b4; "EU-27 Emissions"; end
9
+ def c4; "2005-6"; end
10
+ def d4; "Phase II"; end
11
+ def e4; "Phase III"; end
12
+ def f4; 2013.0; end
13
+ def g4; 2014.0; end
14
+ def h4; 2015.0; end
15
+ def i4; 2016.0; end
16
+ def j4; 2017.0; end
17
+ def k4; 2018.0; end
18
+ def l4; 2019.0; end
19
+ def m4; 2020.0; end
20
+ def o4; "Change"; end
21
+ def b5; "Power sector"; end
22
+ def c5; 1150.0; end
23
+ def d5; 50.0; end
24
+ def e5; 50.0; end
25
+ def f5; @f5 ||= +(c5+d5+e5)*0.9; end
26
+ def g5; @g5 ||= f5*(1.0-o5); end
27
+ def h5; @h5 ||= g5*(1.0-o5); end
28
+ def i5; @i5 ||= h5*(1.0-o5); end
29
+ def j5; @j5 ||= i5*(1.0-o5); end
30
+ def k5; @k5 ||= j5*(1.0-o5); end
31
+ def l5; @l5 ||= k5*(1.0-o5); end
32
+ def m5; @m5 ||= l5*(1.0-o5); end
33
+ def n5; "mtCO2"; end
34
+ def o5; 0.02; end
35
+ def b6; "Leakage sectors"; end
36
+ def c6; 350.0; end
37
+ def f6; @f6 ||= +(c6+d6+e6)*0.95; end
38
+ def g6; @g6 ||= f6*(1.0-o5); end
39
+ def h6; @h6 ||= g6*(1.0-o5); end
40
+ def i6; @i6 ||= h6*(1.0-o5); end
41
+ def j6; @j6 ||= i6*(1.0-o5); end
42
+ def k6; @k6 ||= j6*(1.0-o5); end
43
+ def l6; @l6 ||= k6*(1.0-o5); end
44
+ def m6; @m6 ||= l6*(1.0-o5); end
45
+ def n6; "mtCO2"; end
46
+ def o6; 0.01; end
47
+ def b7; "Other sectors"; end
48
+ def c7; 550.0; end
49
+ def d7; 100.0; end
50
+ def e7; 100.0; end
51
+ def f7; @f7 ||= +(c7+d7+e7)*0.95; end
52
+ def g7; @g7 ||= f7*(1.0-o5); end
53
+ def h7; @h7 ||= g7*(1.0-o5); end
54
+ def i7; @i7 ||= h7*(1.0-o5); end
55
+ def j7; @j7 ||= i7*(1.0-o5); end
56
+ def k7; @k7 ||= j7*(1.0-o5); end
57
+ def l7; @l7 ||= k7*(1.0-o5); end
58
+ def m7; @m7 ||= l7*(1.0-o5); end
59
+ def n7; "mtCO2"; end
60
+ def o7; 0.01; end
61
+ def b8; "Total"; end
62
+ def f8; @f8 ||= +sum(a('f5','f7')); end
63
+ def g8; @g8 ||= +sum(a('g5','g7')); end
64
+ def h8; @h8 ||= +sum(a('h5','h7')); end
65
+ def i8; @i8 ||= +sum(a('i5','i7')); end
66
+ def j8; @j8 ||= +sum(a('j5','j7')); end
67
+ def k8; @k8 ||= +sum(a('k5','k7')); end
68
+ def l8; @l8 ||= +sum(a('l5','l7')); end
69
+ def m8; @m8 ||= +sum(a('m5','m7')); end
70
+ def n8; "mtCO2"; end
71
+ def b10; "Proportion allocated for free"; end
72
+ def f10; @f10 ||= f4; end
73
+ def g10; @g10 ||= g4; end
74
+ def h10; @h10 ||= h4; end
75
+ def i10; @i10 ||= i4; end
76
+ def j10; @j10 ||= j4; end
77
+ def k10; @k10 ||= k4; end
78
+ def l10; @l10 ||= l4; end
79
+ def m10; @m10 ||= m4; end
80
+ def b11; "Power sector"; end
81
+ def f11; 0.0; end
82
+ def g11; @g11 ||= f11; end
83
+ def h11; @h11 ||= g11; end
84
+ def i11; @i11 ||= h11; end
85
+ def j11; @j11 ||= i11; end
86
+ def k11; @k11 ||= j11; end
87
+ def l11; @l11 ||= k11; end
88
+ def m11; @m11 ||= l11; end
89
+ def n11; "%"; end
90
+ def b12; @b12 ||= +b6; end
91
+ def f12; 0.9; end
92
+ def g12; @g12 ||= +f12+o12; end
93
+ def h12; @h12 ||= +g12+o12; end
94
+ def i12; @i12 ||= +h12+o12; end
95
+ def j12; @j12 ||= +i12+o12; end
96
+ def k12; @k12 ||= +j12+o12; end
97
+ def l12; @l12 ||= +k12+o12; end
98
+ def m12; @m12 ||= +l12+o12; end
99
+ def o12; -0.025; end
100
+ def b13; "Other"; end
101
+ def f13; 0.8; end
102
+ def g13; @g13 ||= f13+o13; end
103
+ def h13; @h13 ||= g13+o13; end
104
+ def i13; @i13 ||= h13+o13; end
105
+ def j13; @j13 ||= i13+o13; end
106
+ def k13; @k13 ||= j13+o13; end
107
+ def l13; @l13 ||= k13+o13; end
108
+ def m13; 0.0; end
109
+ def n13; "%"; end
110
+ def o13; @o13 ||= (m13-f13)/(m10-f10); end
111
+ def b14; "Average non-power sectors"; end
112
+ def f14; @f14 ||= +(f6*f12+f7*f13)/(f6+f7); end
113
+ def g14; @g14 ||= +(g6*g12+g7*g13)/(g6+g7); end
114
+ def h14; @h14 ||= +(h6*h12+h7*h13)/(h6+h7); end
115
+ def i14; @i14 ||= +(i6*i12+i7*i13)/(i6+i7); end
116
+ def j14; @j14 ||= +(j6*j12+j7*j13)/(j6+j7); end
117
+ def k14; @k14 ||= +(k6*k12+k7*k13)/(k6+k7); end
118
+ def l14; @l14 ||= +(l6*l12+l7*l13)/(l6+l7); end
119
+ def m14; @m14 ||= +(m6*m12+m7*m13)/(m6+m7); end
120
+ def b15; "Total free allocation, % emissions"; end
121
+ def f15; @f15 ||= ((f11*f5)+(f12*f6)+(f13*f7))/f8; end
122
+ def g15; @g15 ||= ((g11*g5)+(g12*g6)+(g13*g7))/g8; end
123
+ def h15; @h15 ||= ((h11*h5)+(h12*h6)+(h13*h7))/h8; end
124
+ def i15; @i15 ||= ((i11*i5)+(i12*i6)+(i13*i7))/i8; end
125
+ def j15; @j15 ||= ((j11*j5)+(j12*j6)+(j13*j7))/j8; end
126
+ def k15; @k15 ||= ((k11*k5)+(k12*k6)+(k13*k7))/k8; end
127
+ def l15; @l15 ||= ((l11*l5)+(l12*l6)+(l13*l7))/l8; end
128
+ def m15; @m15 ||= ((m11*m5)+(m12*m6)+(m13*m7))/m8; end
129
+ def n15; "%"; end
130
+ def b17; "Proportion auctioned, other sectors"; end
131
+ def f17; @f17 ||= 1.0-f14; end
132
+ def g17; @g17 ||= 1.0-g14; end
133
+ def h17; @h17 ||= 1.0-h14; end
134
+ def i17; @i17 ||= 1.0-i14; end
135
+ def j17; @j17 ||= 1.0-j14; end
136
+ def k17; @k17 ||= 1.0-k14; end
137
+ def l17; @l17 ||= 1.0-l14; end
138
+ def m17; @m17 ||= 1.0-m14; end
139
+ def b18; "Total allowances"; end
140
+ def d18; 2010.0; end
141
+ def f18; @f18 ||= f10; end
142
+ def g18; @g18 ||= g10; end
143
+ def h18; @h18 ||= h10; end
144
+ def i18; @i18 ||= i10; end
145
+ def j18; @j18 ||= j10; end
146
+ def k18; @k18 ||= k10; end
147
+ def l18; @l18 ||= l10; end
148
+ def m18; @m18 ||= m10; end
149
+ def b19; "Total allowances"; end
150
+ def d19; @d19 ||= +(2100.0+100.0)*0.935+150.0; end
151
+ def f19; @f19 ||= +d19*(1.0-3.0*o19); end
152
+ def g19; @g19 ||= +f19*(1.0-o19); end
153
+ def h19; @h19 ||= +g19*(1.0-o19); end
154
+ def i19; @i19 ||= +h19*(1.0-o19); end
155
+ def j19; @j19 ||= +i19*(1.0-o19); end
156
+ def k19; @k19 ||= +j19*(1.0-o19); end
157
+ def l19; @l19 ||= +k19*(1.0-o19); end
158
+ def m19; @m19 ||= +l19*(1.0-o19); end
159
+ def o19; 0.0174; end
160
+ def p19; "Note: 1720 \"based on current scope\""; end
161
+ def b20; "Total free allocation, MtCO2"; end
162
+ def f20; @f20 ||= +f6*f12+f7*f13*f19/f8; end
163
+ def g20; @g20 ||= +f6*g12+f7*g13*g19/g8; end
164
+ def h20; @h20 ||= +f6*h12+f7*h13*h19/h8; end
165
+ def i20; @i20 ||= +f6*i12+f7*i13*i19/i8; end
166
+ def j20; @j20 ||= +f6*j12+f7*j13*j19/j8; end
167
+ def k20; @k20 ||= +f6*k12+f7*k13*k19/k8; end
168
+ def l20; @l20 ||= +f6*l12+f7*l13*l19/l8; end
169
+ def m20; @m20 ||= +f6*m12+f7*m13*m19/m8; end
170
+ def b21; "Volume available for auctioning"; end
171
+ def f21; @f21 ||= +f19-f20; end
172
+ def g21; @g21 ||= +g19-g20; end
173
+ def h21; @h21 ||= +h19-h20; end
174
+ def i21; @i21 ||= +i19-i20; end
175
+ def j21; @j21 ||= +j19-j20; end
176
+ def k21; @k21 ||= +k19-k20; end
177
+ def l21; @l21 ||= +l19-l20; end
178
+ def m21; @m21 ||= +m19-m20; end
179
+ def b23; "Carbon Price"; end
180
+ def f23; @f23 ||= f10; end
181
+ def g23; @g23 ||= g10; end
182
+ def h23; @h23 ||= h10; end
183
+ def i23; @i23 ||= i10; end
184
+ def j23; @j23 ||= j10; end
185
+ def k23; @k23 ||= k10; end
186
+ def l23; @l23 ||= l10; end
187
+ def m23; @m23 ||= m10; end
188
+ def b24; "Price per allowance"; end
189
+ def f24; 25.0; end
190
+ def g24; @g24 ||= +f24*(1.0+o24); end
191
+ def h24; @h24 ||= +g24*(1.0+o24); end
192
+ def i24; @i24 ||= +h24*(1.0+o24); end
193
+ def j24; @j24 ||= +i24*(1.0+o24); end
194
+ def k24; @k24 ||= +j24*(1.0+o24); end
195
+ def l24; @l24 ||= +k24*(1.0+o24); end
196
+ def m24; @m24 ||= +l24*(1.0+o24); end
197
+ def n24; "€/tCO2"; end
198
+ def o24; 0.05; end
199
+ def b25; "Total revenue from auctions"; end
200
+ def f25; @f25 ||= +f24*f21; end
201
+ def g25; @g25 ||= +g24*g21; end
202
+ def h25; @h25 ||= +h24*h21; end
203
+ def i25; @i25 ||= +i24*i21; end
204
+ def j25; @j25 ||= +j24*j21; end
205
+ def k25; @k25 ||= +k24*k21; end
206
+ def l25; @l25 ||= +l24*l21; end
207
+ def m25; @m25 ||= +m24*m21; end
208
+ def b27; "EU-27 Auction volumes- bought into proportion to net shortfall"; end
209
+ def f27; @f27 ||= f10; end
210
+ def g27; @g27 ||= g10; end
211
+ def h27; @h27 ||= h10; end
212
+ def i27; @i27 ||= i10; end
213
+ def j27; @j27 ||= j10; end
214
+ def k27; @k27 ||= k10; end
215
+ def l27; @l27 ||= l10; end
216
+ def m27; @m27 ||= m10; end
217
+ def b28; "Power sector"; end
218
+ def f28; @f28 ||= +f5*(1.0-f11)*(f19/f8); end
219
+ def g28; @g28 ||= +g5*(1.0-g11)*(g19/g8); end
220
+ def h28; @h28 ||= +h5*(1.0-h11)*(h19/h8); end
221
+ def i28; @i28 ||= +i5*(1.0-i11)*(i19/i8); end
222
+ def j28; @j28 ||= +j5*(1.0-j11)*(j19/j8); end
223
+ def k28; @k28 ||= +k5*(1.0-k11)*(k19/k8); end
224
+ def l28; @l28 ||= +l5*(1.0-l11)*(l19/l8); end
225
+ def m28; @m28 ||= +m5*(1.0-m11)*(m19/m8); end
226
+ def b29; @b29 ||= +b6; end
227
+ def f29; @f29 ||= +f6*(1.0-f12)*(f19/f8); end
228
+ def g29; @g29 ||= +g6*(1.0-g12)*(g19/g8); end
229
+ def h29; @h29 ||= +h6*(1.0-h12)*(h19/h8); end
230
+ def i29; @i29 ||= +i6*(1.0-i12)*(i19/i8); end
231
+ def j29; @j29 ||= +j6*(1.0-j12)*(j19/j8); end
232
+ def k29; @k29 ||= +k6*(1.0-k12)*(k19/k8); end
233
+ def l29; @l29 ||= +l6*(1.0-l12)*(l19/l8); end
234
+ def m29; @m29 ||= +m6*(1.0-m12)*(m19/m8); end
235
+ def b30; "Other"; end
236
+ def f30; @f30 ||= +f7*(1.0-f13)*(f19/f8); end
237
+ def g30; @g30 ||= +g7*(1.0-g13)*(g19/g8); end
238
+ def h30; @h30 ||= +h7*(1.0-h13)*(h19/h8); end
239
+ def i30; @i30 ||= +i7*(1.0-i13)*(i19/i8); end
240
+ def j30; @j30 ||= +j7*(1.0-j13)*(j19/j8); end
241
+ def k30; @k30 ||= +k7*(1.0-k13)*(k19/k8); end
242
+ def l30; @l30 ||= +l7*(1.0-l13)*(l19/l8); end
243
+ def m30; @m30 ||= +m7*(1.0-m13)*(m19/m8); end
244
+ def b31; "Total"; end
245
+ def f31; @f31 ||= +sum(a('f28','f30')); end
246
+ def g31; @g31 ||= +sum(a('g28','g30')); end
247
+ def h31; @h31 ||= +sum(a('h28','h30')); end
248
+ def i31; @i31 ||= +sum(a('i28','i30')); end
249
+ def j31; @j31 ||= +sum(a('j28','j30')); end
250
+ def k31; @k31 ||= +sum(a('k28','k30')); end
251
+ def l31; @l31 ||= +sum(a('l28','l30')); end
252
+ def m31; @m31 ||= +sum(a('m28','m30')); end
253
+ def b33; "Revenues"; end
254
+ def b34; "Power sector"; end
255
+ def f34; @f34 ||= +f28*f24; end
256
+ def g34; @g34 ||= +g28*g24; end
257
+ def h34; @h34 ||= +h28*h24; end
258
+ def i34; @i34 ||= +i28*i24; end
259
+ def j34; @j34 ||= +j28*j24; end
260
+ def k34; @k34 ||= +k28*k24; end
261
+ def l34; @l34 ||= +l28*l24; end
262
+ def m34; @m34 ||= +m28*m24; end
263
+ def b35; "Other sectors"; end
264
+ def f35; @f35 ||= +(f29+f30)*f24; end
265
+ def g35; @g35 ||= +(g29+g30)*g24; end
266
+ def h35; @h35 ||= +(h29+h30)*h24; end
267
+ def i35; @i35 ||= +(i29+i30)*i24; end
268
+ def j35; @j35 ||= +(j29+j30)*j24; end
269
+ def k35; @k35 ||= +(k29+k30)*k24; end
270
+ def l35; @l35 ||= +(l29+l30)*l24; end
271
+ def m35; @m35 ||= +(m29+m30)*m24; end
272
+ def b39; "2005 UK ETS Emissions"; end
273
+ def f39; 242.0; end
274
+ def g39; "mtCO2"; end
275
+ def n39; " "; end
276
+ def b40; "2005 EU ETS Emissions"; end
277
+ def f40; 1785.0; end
278
+ def g40; "mtCO2"; end
279
+ def b41; "Basic UK share of auction revenues"; end
280
+ def f41; @f41 ||= f39/f40; end
281
+ def b42; "Amount of share auctioned in UK"; end
282
+ def f42; 0.9; end
283
+ def b43; "Actual UK share of auction revenues"; end
284
+ def f43; @f43 ||= f42*f41; end
285
+ def b45; "UK Auction revenues"; end
286
+ def f45; @f45 ||= f4; end
287
+ def g45; @g45 ||= g4; end
288
+ def h45; @h45 ||= h4; end
289
+ def i45; @i45 ||= i4; end
290
+ def j45; @j45 ||= j4; end
291
+ def k45; @k45 ||= k4; end
292
+ def l45; @l45 ||= l4; end
293
+ def m45; @m45 ||= m4; end
294
+ def b46; "Total"; end
295
+ def f46; @f46 ||= f43*f31; end
296
+ def g46; @g46 ||= f43*g31; end
297
+ def h46; @h46 ||= f43*h31; end
298
+ def i46; @i46 ||= f43*i31; end
299
+ def j46; @j46 ||= f43*j31; end
300
+ def k46; @k46 ||= f43*k31; end
301
+ def l46; @l46 ||= f43*l31; end
302
+ def m46; @m46 ||= f43*m31; end
303
+ def n46; "€bn"; end
304
+ end
305
+