rubyfromexcel 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README +22 -0
- data/bin/rubyfromexcel +20 -0
- data/examples/create_and_test_examples.rb +37 -0
- data/examples/ruby-versions/array-formulas-ruby/sheets/sheet1.rb +59 -0
- data/examples/ruby-versions/array-formulas-ruby/sheets/sheet2.rb +9 -0
- data/examples/ruby-versions/array-formulas-ruby/specs/sheet1_rspec.rb +156 -0
- data/examples/ruby-versions/array-formulas-ruby/specs/sheet2_rspec.rb +8 -0
- data/examples/ruby-versions/array-formulas-ruby/spreadsheet.rb +9 -0
- data/examples/ruby-versions/complex-test-ruby/sheets/sheet1.rb +305 -0
- data/examples/ruby-versions/complex-test-ruby/sheets/sheet2.rb +147 -0
- data/examples/ruby-versions/complex-test-ruby/specs/sheet1_rspec.rb +876 -0
- data/examples/ruby-versions/complex-test-ruby/specs/sheet2_rspec.rb +412 -0
- data/examples/ruby-versions/complex-test-ruby/spreadsheet.rb +9 -0
- data/examples/ruby-versions/namedReferenceTest-ruby/sheets/sheet1.rb +9 -0
- data/examples/ruby-versions/namedReferenceTest-ruby/sheets/sheet2.rb +8 -0
- data/examples/ruby-versions/namedReferenceTest-ruby/specs/sheet1_rspec.rb +16 -0
- data/examples/ruby-versions/namedReferenceTest-ruby/specs/sheet2_rspec.rb +16 -0
- data/examples/ruby-versions/namedReferenceTest-ruby/spreadsheet.rb +9 -0
- data/examples/ruby-versions/pruning-ruby/sheets/sheet1.rb +11 -0
- data/examples/ruby-versions/pruning-ruby/sheets/sheet2.rb +14 -0
- data/examples/ruby-versions/pruning-ruby/sheets/sheet3.rb +7 -0
- data/examples/ruby-versions/pruning-ruby/specs/sheet1_rspec.rb +20 -0
- data/examples/ruby-versions/pruning-ruby/specs/sheet2_rspec.rb +20 -0
- data/examples/ruby-versions/pruning-ruby/specs/sheet3_rspec.rb +8 -0
- data/examples/ruby-versions/pruning-ruby/spreadsheet.rb +9 -0
- data/examples/ruby-versions/sharedFormulaTest-ruby/sheets/sheet1.rb +15 -0
- data/examples/ruby-versions/sharedFormulaTest-ruby/specs/sheet1_rspec.rb +44 -0
- data/examples/ruby-versions/sharedFormulaTest-ruby/spreadsheet.rb +9 -0
- data/examples/ruby-versions/table-test-ruby/sheets/sheet1.rb +17 -0
- data/examples/ruby-versions/table-test-ruby/sheets/sheet2.rb +5 -0
- data/examples/ruby-versions/table-test-ruby/sheets/sheet3.rb +5 -0
- data/examples/ruby-versions/table-test-ruby/specs/sheet1_rspec.rb +20 -0
- data/examples/ruby-versions/table-test-ruby/specs/sheet2_rspec.rb +8 -0
- data/examples/ruby-versions/table-test-ruby/specs/sheet3_rspec.rb +8 -0
- data/examples/ruby-versions/table-test-ruby/spreadsheet.rb +9 -0
- data/examples/sheets/array-formulas.xlsx +0 -0
- data/examples/sheets/complex-test.xlsx +0 -0
- data/examples/sheets/namedReferenceTest.xlsx +0 -0
- data/examples/sheets/pruning.xlsx +0 -0
- data/examples/sheets/sharedFormulaTest.xlsx +0 -0
- data/examples/sheets/table-test.xlsx +0 -0
- data/examples/sheets/~$array-formulas.xlsx +0 -0
- data/examples/unzipped-sheets/array-formulas/[Content_Types].xml +2 -0
- data/examples/unzipped-sheets/array-formulas/docProps/app.xml +2 -0
- data/examples/unzipped-sheets/array-formulas/docProps/core.xml +2 -0
- data/examples/unzipped-sheets/array-formulas/docProps/thumbnail.jpeg +0 -0
- data/examples/unzipped-sheets/array-formulas/xl/_rels/workbook.xml.rels +2 -0
- data/examples/unzipped-sheets/array-formulas/xl/calcChain.xml +2 -0
- data/examples/unzipped-sheets/array-formulas/xl/sharedStrings.xml +2 -0
- data/examples/unzipped-sheets/array-formulas/xl/styles.xml +2 -0
- data/examples/unzipped-sheets/array-formulas/xl/theme/theme1.xml +2 -0
- data/examples/unzipped-sheets/array-formulas/xl/workbook.xml +2 -0
- data/examples/unzipped-sheets/array-formulas/xl/worksheets/sheet1.xml +2 -0
- data/examples/unzipped-sheets/array-formulas/xl/worksheets/sheet2.xml +2 -0
- data/examples/unzipped-sheets/complex-test/[Content_Types].xml +2 -0
- data/examples/unzipped-sheets/complex-test/docProps/app.xml +2 -0
- data/examples/unzipped-sheets/complex-test/docProps/core.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/_rels/workbook.xml.rels +2 -0
- data/examples/unzipped-sheets/complex-test/xl/calcChain.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/charts/chart1.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/charts/chart2.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/comments1.xml +5 -0
- data/examples/unzipped-sheets/complex-test/xl/comments2.xml +5 -0
- data/examples/unzipped-sheets/complex-test/xl/drawings/_rels/drawing1.xml.rels +2 -0
- data/examples/unzipped-sheets/complex-test/xl/drawings/_rels/drawing2.xml.rels +2 -0
- data/examples/unzipped-sheets/complex-test/xl/drawings/drawing1.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/drawings/drawing2.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/drawings/vmlDrawing1.vml +46 -0
- data/examples/unzipped-sheets/complex-test/xl/drawings/vmlDrawing2.vml +46 -0
- data/examples/unzipped-sheets/complex-test/xl/sharedStrings.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/styles.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/theme/theme1.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/workbook.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/worksheets/_rels/sheet1.xml.rels +2 -0
- data/examples/unzipped-sheets/complex-test/xl/worksheets/_rels/sheet2.xml.rels +2 -0
- data/examples/unzipped-sheets/complex-test/xl/worksheets/sheet1.xml +2 -0
- data/examples/unzipped-sheets/complex-test/xl/worksheets/sheet2.xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/[Content_Types].xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/docProps/app.xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/docProps/core.xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/docProps/thumbnail.jpeg +0 -0
- data/examples/unzipped-sheets/namedReferenceTest/xl/_rels/workbook.xml.rels +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/xl/calcChain.xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/xl/styles.xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/xl/theme/theme1.xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/xl/workbook.xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/xl/worksheets/sheet1.xml +2 -0
- data/examples/unzipped-sheets/namedReferenceTest/xl/worksheets/sheet2.xml +2 -0
- data/examples/unzipped-sheets/pruning/[Content_Types].xml +2 -0
- data/examples/unzipped-sheets/pruning/docProps/app.xml +2 -0
- data/examples/unzipped-sheets/pruning/docProps/core.xml +2 -0
- data/examples/unzipped-sheets/pruning/docProps/thumbnail.jpeg +0 -0
- data/examples/unzipped-sheets/pruning/xl/_rels/workbook.xml.rels +2 -0
- data/examples/unzipped-sheets/pruning/xl/calcChain.xml +2 -0
- data/examples/unzipped-sheets/pruning/xl/sharedStrings.xml +2 -0
- data/examples/unzipped-sheets/pruning/xl/styles.xml +2 -0
- data/examples/unzipped-sheets/pruning/xl/theme/theme1.xml +2 -0
- data/examples/unzipped-sheets/pruning/xl/workbook.xml +2 -0
- data/examples/unzipped-sheets/pruning/xl/worksheets/sheet1.xml +2 -0
- data/examples/unzipped-sheets/pruning/xl/worksheets/sheet2.xml +2 -0
- data/examples/unzipped-sheets/pruning/xl/worksheets/sheet3.xml +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/[Content_Types].xml +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/docProps/app.xml +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/docProps/core.xml +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/docProps/thumbnail.jpeg +0 -0
- data/examples/unzipped-sheets/sharedFormulaTest/xl/_rels/workbook.xml.rels +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/xl/calcChain.xml +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/xl/styles.xml +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/xl/theme/theme1.xml +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/xl/workbook.xml +2 -0
- data/examples/unzipped-sheets/sharedFormulaTest/xl/worksheets/sheet1.xml +2 -0
- data/examples/unzipped-sheets/table-test/[Content_Types].xml +2 -0
- data/examples/unzipped-sheets/table-test/docProps/app.xml +2 -0
- data/examples/unzipped-sheets/table-test/docProps/core.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/_rels/workbook.xml.rels +2 -0
- data/examples/unzipped-sheets/table-test/xl/calcChain.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/printerSettings/printerSettings1.bin +0 -0
- data/examples/unzipped-sheets/table-test/xl/sharedStrings.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/styles.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/tables/table1.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/theme/theme1.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/workbook.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/worksheets/_rels/sheet1.xml.rels +2 -0
- data/examples/unzipped-sheets/table-test/xl/worksheets/sheet1.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/worksheets/sheet2.xml +2 -0
- data/examples/unzipped-sheets/table-test/xl/worksheets/sheet3.xml +2 -0
- data/lib/cells/array/array_formula_builder.rb +58 -0
- data/lib/cells/array/array_formula_cell.rb +27 -0
- data/lib/cells/array/arraying_formula_cell.rb +67 -0
- data/lib/cells/array/single_cell_array_formula_builder.rb +9 -0
- data/lib/cells/array/single_cell_array_formula_cell.rb +11 -0
- data/lib/cells/cell.rb +98 -0
- data/lib/cells/cells.rb +9 -0
- data/lib/cells/formula/formula_cell.rb +18 -0
- data/lib/cells/formula/simple_formula_cell.rb +4 -0
- data/lib/cells/shared/shared_formula_builder.rb +15 -0
- data/lib/cells/shared/shared_formula_cell.rb +20 -0
- data/lib/cells/shared/sharing_formula_cell.rb +36 -0
- data/lib/cells/value/value_cell.rb +24 -0
- data/lib/excelfile/excelfile.rb +6 -0
- data/lib/excelfile/relationships.rb +24 -0
- data/lib/excelfile/shared_strings.rb +21 -0
- data/lib/excelfile/sheet_names.rb +6 -0
- data/lib/excelfile/table.rb +116 -0
- data/lib/excelfile/workbook.rb +108 -0
- data/lib/excelfile/worksheet.rb +122 -0
- data/lib/formulae/compile/formula_builder.rb +316 -0
- data/lib/formulae/formulae.rb +6 -0
- data/lib/formulae/parse/formula_peg.rb +213 -0
- data/lib/formulae/parse/formula_peg.txt +40 -0
- data/lib/formulae/run/excel_functions.rb +375 -0
- data/lib/formulae/run/excel_matrix.rb +114 -0
- data/lib/formulae/run/excel_range.rb +256 -0
- data/lib/formulae/run/reference.rb +79 -0
- data/lib/optimiser/dependency_builder.rb +86 -0
- data/lib/optimiser/optimiser.rb +3 -0
- data/lib/optimiser/shared_formula_dependency_builder.rb +43 -0
- data/lib/optimiser/workbook_pruner.rb +80 -0
- data/lib/rubyfromexcel.rb +105 -0
- data/lib/runtime/runtime_formula_builder.rb +32 -0
- data/spec/array_formula_builder_spec.rb +35 -0
- data/spec/array_formula_cell_spec.rb +17 -0
- data/spec/arraying_formula_cell_spec.rb +38 -0
- data/spec/dependency_builder_spec.rb +71 -0
- data/spec/excel_functions_spec.rb +381 -0
- data/spec/excel_matrix_spec.rb +92 -0
- data/spec/excel_range_spec.rb +161 -0
- data/spec/formula_builder_spec.rb +230 -0
- data/spec/formula_peg_spec.rb +165 -0
- data/spec/reference_spec.rb +72 -0
- data/spec/relationships_spec.rb +51 -0
- data/spec/runtime_formula_builder_spec.rb +55 -0
- data/spec/shared_formula_builder_spec.rb +29 -0
- data/spec/shared_formula_cell_spec.rb +23 -0
- data/spec/shared_formula_dependency_builder_spec.rb +48 -0
- data/spec/shared_strings_spec.rb +14 -0
- data/spec/sharing_formula_cell_spec.rb +79 -0
- data/spec/simple_formula_cell_spec.rb +78 -0
- data/spec/single_cell_array_formula_builder_spec.rb +19 -0
- data/spec/single_cell_array_formula_cell_spec.rb +25 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/table_spec.rb +100 -0
- data/spec/value_cell_spec.rb +49 -0
- data/spec/workbook_pruner_spec.rb +27 -0
- data/spec/workbook_spec.rb +283 -0
- data/spec/worksheet_failiures_spec.rb +41 -0
- data/spec/worksheet_spec.rb +486 -0
- metadata +291 -0
@@ -0,0 +1,486 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Worksheet do
|
4
|
+
|
5
|
+
simple_worksheet_xml =<<END
|
6
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
7
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" mc:Ignorable="mv" mc:PreserveAttributes="mv:*"><dimension ref="A1:A2"/><sheetViews><sheetView view="pageLayout" workbookViewId="0"/></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="13"/><sheetData><row r="1" spans="1:1"><c r="A1" t="str"><f>IF(A2="Hello","hello",Sheet2!B4)</f><v>hello</v></c></row><row r="2" spans="1:1"><c r="A2" t="s"><v>24</v></c></row></sheetData><sheetCalcPr fullCalcOnLoad="1"/><phoneticPr fontId="2" type="noConversion"/><pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/><pageSetup paperSize="10" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/><extLst><ext xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" uri="http://schemas.microsoft.com/office/mac/excel/2008/main"><mx:PLV Mode="1" OnePage="0" WScale="0"/></ext></extLst></worksheet>
|
8
|
+
END
|
9
|
+
|
10
|
+
simple_worksheet_ruby =<<END
|
11
|
+
# coding: utf-8
|
12
|
+
#
|
13
|
+
class Sheet1 < Spreadsheet
|
14
|
+
def a1; @a1 ||= excel_if(a2=="Hello","hello",sheet2.b4); end
|
15
|
+
def a2; "A shared string"; end
|
16
|
+
end
|
17
|
+
|
18
|
+
END
|
19
|
+
|
20
|
+
simple_worksheet_test =<<END
|
21
|
+
# coding: utf-8
|
22
|
+
require_relative '../spreadsheet'
|
23
|
+
#
|
24
|
+
describe 'Sheet1' do
|
25
|
+
def sheet1; $spreadsheet ||= Spreadsheet.new; $spreadsheet.sheet1; end
|
26
|
+
|
27
|
+
it 'cell a1 should equal "hello"' do
|
28
|
+
sheet1.a1.should == "hello"
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
END
|
34
|
+
|
35
|
+
it 'should create a ruby file from xml, complete with properly interpreted cells' do
|
36
|
+
SheetNames.instance['Sheet2'] = 'sheet2'
|
37
|
+
SharedStrings.instance[24] = 'A shared string'
|
38
|
+
worksheet = Worksheet.new(Nokogiri::XML(simple_worksheet_xml))
|
39
|
+
worksheet.workbook = mock(:workbook,:indirects_used => true)
|
40
|
+
worksheet.name = 'sheet1'
|
41
|
+
worksheet.to_ruby.should == simple_worksheet_ruby
|
42
|
+
worksheet.to_test.should == simple_worksheet_test
|
43
|
+
end
|
44
|
+
|
45
|
+
named_reference_simple_worksheet_ruby =<<END
|
46
|
+
# coding: utf-8
|
47
|
+
#
|
48
|
+
class Sheet1 < Spreadsheet
|
49
|
+
def a1; @a1 ||= excel_if(a2=="Hello","hello",sheet2.b4); end
|
50
|
+
def a2; "A shared string"; end
|
51
|
+
def reference_one; sheet2.a1; end
|
52
|
+
end
|
53
|
+
|
54
|
+
END
|
55
|
+
|
56
|
+
it 'should add any named references that apply just to this sheet' do
|
57
|
+
SheetNames.instance['Sheet2'] = 'sheet2'
|
58
|
+
SharedStrings.instance[24] = 'A shared string'
|
59
|
+
worksheet = Worksheet.new(Nokogiri::XML(simple_worksheet_xml))
|
60
|
+
worksheet.workbook = mock(:workbook,:indirects_used => true)
|
61
|
+
worksheet.named_references['reference_one'] = 'sheet2.a1'
|
62
|
+
worksheet.name = 'sheet1'
|
63
|
+
worksheet.to_ruby.should == named_reference_simple_worksheet_ruby
|
64
|
+
end
|
65
|
+
|
66
|
+
shared_formula_worksheet_xml =<<END
|
67
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
68
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" mc:Ignorable="mv" mc:PreserveAttributes="mv:*"><dimension ref="A1:A10"/><sheetViews><sheetView tabSelected="1" view="pageLayout" workbookViewId="0"><selection activeCell="B5" sqref="B5"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="13"/><sheetData><row r="1" spans="1:1"><c r="A1"><v>1</v></c></row><row r="2" spans="1:1"><c r="A2"><f>A1*2</f><v>2</v></c></row><row r="3" spans="1:1"><c r="A3"><f t="shared" ref="A3:A9" si="0">A2*2</f><v>4</v></c></row><row r="4" spans="1:1"><c r="A4"><f t="shared" si="0"/><v>8</v></c></row><row r="5" spans="1:1"><c r="A5"><f t="shared" si="0"/><v>16</v></c></row><row r="6" spans="1:1"><c r="A6"><f t="shared" si="0"/><v>32</v></c></row><row r="7" spans="1:1"><c r="A7"><f t="shared" si="0"/><v>64</v></c></row><row r="8" spans="1:1"><c r="A8"><f t="shared" si="0"/><v>128</v></c></row><row r="9" spans="1:1"><c r="A9"><f t="shared" si="0"/><v>256</v></c></row><row r="10" spans="1:1"><c r="A10"><f>A9*2</f><v>512</v></c></row></sheetData><phoneticPr fontId="1" type="noConversion"/><pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/><pageSetup paperSize="10" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/><extLst><ext xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" uri="http://schemas.microsoft.com/office/mac/excel/2008/main"><mx:PLV Mode="1" OnePage="0" WScale="0"/></ext></extLst></worksheet>
|
69
|
+
END
|
70
|
+
shared_formula_worksheet_ruby =<<END
|
71
|
+
# coding: utf-8
|
72
|
+
#
|
73
|
+
class Sheet1 < Spreadsheet
|
74
|
+
def a1; 1.0; end
|
75
|
+
def a2; @a2 ||= a1*2.0; end
|
76
|
+
def a3; @a3 ||= a2*2.0; end
|
77
|
+
def a4; @a4 ||= a3*2.0; end
|
78
|
+
def a5; @a5 ||= a4*2.0; end
|
79
|
+
def a6; @a6 ||= a5*2.0; end
|
80
|
+
def a7; @a7 ||= a6*2.0; end
|
81
|
+
def a8; @a8 ||= a7*2.0; end
|
82
|
+
def a9; @a9 ||= a8*2.0; end
|
83
|
+
def a10; @a10 ||= a9*2.0; end
|
84
|
+
end
|
85
|
+
|
86
|
+
END
|
87
|
+
|
88
|
+
shared_formula_worksheet_test =<<END
|
89
|
+
# coding: utf-8
|
90
|
+
require_relative '../spreadsheet'
|
91
|
+
#
|
92
|
+
describe 'Sheet1' do
|
93
|
+
def sheet1; $spreadsheet ||= Spreadsheet.new; $spreadsheet.sheet1; end
|
94
|
+
|
95
|
+
it 'cell a2 should equal 2.0' do
|
96
|
+
sheet1.a2.should be_close(2.0,0.2)
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'cell a3 should equal 4.0' do
|
100
|
+
sheet1.a3.should be_close(4.0,0.4)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'cell a4 should equal 8.0' do
|
104
|
+
sheet1.a4.should be_close(8.0,0.8)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'cell a5 should equal 16.0' do
|
108
|
+
sheet1.a5.should be_close(16.0,1.6)
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'cell a6 should equal 32.0' do
|
112
|
+
sheet1.a6.should be_close(32.0,3.2)
|
113
|
+
end
|
114
|
+
|
115
|
+
it 'cell a7 should equal 64.0' do
|
116
|
+
sheet1.a7.should be_close(64.0,6.4)
|
117
|
+
end
|
118
|
+
|
119
|
+
it 'cell a8 should equal 128.0' do
|
120
|
+
sheet1.a8.should be_close(128.0,12.8)
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'cell a9 should equal 256.0' do
|
124
|
+
sheet1.a9.should be_close(256.0,25.6)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'cell a10 should equal 512.0' do
|
128
|
+
sheet1.a10.should be_close(512.0,51.2)
|
129
|
+
end
|
130
|
+
|
131
|
+
end
|
132
|
+
|
133
|
+
END
|
134
|
+
|
135
|
+
it 'should create a ruby file from xml, dealing correctly with shared formulas' do
|
136
|
+
worksheet = Worksheet.new(Nokogiri::XML(shared_formula_worksheet_xml))
|
137
|
+
worksheet.name = 'sheet1'
|
138
|
+
worksheet.workbook = mock(:workbook,:indirects_used => true)
|
139
|
+
worksheet.to_ruby.should == shared_formula_worksheet_ruby
|
140
|
+
worksheet.to_test.should == shared_formula_worksheet_test
|
141
|
+
end
|
142
|
+
|
143
|
+
array_formula_worksheet_xml =<<END
|
144
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
145
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" mc:Ignorable="mv" mc:PreserveAttributes="mv:*"><dimension ref="A1:B5"/><sheetViews><sheetView tabSelected="1" view="pageLayout" workbookViewId="0"><selection activeCell="B6" sqref="B6"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="13"/><sheetData><row r="1" spans="1:2"><c r="A1"><v>1</v></c><c r="B1"><f t="array" ref="B1:B5">A1:A5</f><v>1</v></c></row><row r="2" spans="1:2"><c r="A2"><v>2</v></c><c r="B2"><v>2</v></c></row><row r="3" spans="1:2"><c r="A3"><v>3</v></c><c r="B3"><v>3</v></c></row><row r="4" spans="1:2"><c r="A4"><v>4</v></c><c r="B4"><v>4</v></c></row><row r="5" spans="1:2"><c r="A5"><v>5</v></c><c r="B5"><v>5</v></c></row></sheetData><phoneticPr fontId="1" type="noConversion"/><pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/><pageSetup paperSize="10" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/><extLst><ext xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" uri="http://schemas.microsoft.com/office/mac/excel/2008/main"><mx:PLV Mode="1" OnePage="0" WScale="0"/></ext></extLst></worksheet>
|
146
|
+
END
|
147
|
+
|
148
|
+
array_formula_worksheet_ruby =<<END
|
149
|
+
# coding: utf-8
|
150
|
+
#
|
151
|
+
class Sheet1 < Spreadsheet
|
152
|
+
def a1; 1.0; end
|
153
|
+
def b1_array; @b1_array ||= a('a1','a5'); end
|
154
|
+
def b1; @b1 ||= b1_array.array_formula_offset(0,0); end
|
155
|
+
def a2; 2.0; end
|
156
|
+
def b2; @b2 ||= b1_array.array_formula_offset(1,0); end
|
157
|
+
def a3; 3.0; end
|
158
|
+
def b3; @b3 ||= b1_array.array_formula_offset(2,0); end
|
159
|
+
def a4; 4.0; end
|
160
|
+
def b4; @b4 ||= b1_array.array_formula_offset(3,0); end
|
161
|
+
def a5; 5.0; end
|
162
|
+
def b5; @b5 ||= b1_array.array_formula_offset(4,0); end
|
163
|
+
end
|
164
|
+
|
165
|
+
END
|
166
|
+
|
167
|
+
array_formula_worksheet_test =<<END
|
168
|
+
# coding: utf-8
|
169
|
+
require_relative '../spreadsheet'
|
170
|
+
#
|
171
|
+
describe 'Sheet1' do
|
172
|
+
def sheet1; $spreadsheet ||= Spreadsheet.new; $spreadsheet.sheet1; end
|
173
|
+
|
174
|
+
it 'cell b1 should equal 1.0' do
|
175
|
+
sheet1.b1.should be_close(1.0,0.1)
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'cell b2 should equal 2.0' do
|
179
|
+
sheet1.b2.should be_close(2.0,0.2)
|
180
|
+
end
|
181
|
+
|
182
|
+
it 'cell b3 should equal 3.0' do
|
183
|
+
sheet1.b3.should be_close(3.0,0.3)
|
184
|
+
end
|
185
|
+
|
186
|
+
it 'cell b4 should equal 4.0' do
|
187
|
+
sheet1.b4.should be_close(4.0,0.4)
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'cell b5 should equal 5.0' do
|
191
|
+
sheet1.b5.should be_close(5.0,0.5)
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
195
|
+
|
196
|
+
END
|
197
|
+
|
198
|
+
it 'should create a ruby file from xml, dealing correctly with array formulas' do
|
199
|
+
worksheet = Worksheet.new(Nokogiri::XML(array_formula_worksheet_xml))
|
200
|
+
worksheet.name = 'sheet1'
|
201
|
+
worksheet.workbook = mock(:workbook,:indirects_used => true)
|
202
|
+
worksheet.to_ruby.should == array_formula_worksheet_ruby
|
203
|
+
worksheet.to_test.should == array_formula_worksheet_test
|
204
|
+
end
|
205
|
+
|
206
|
+
table_xml =<<-END
|
207
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
208
|
+
<table xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" id="1" name="FirstTable" displayName="FirstTable" ref="B3:D7" totalsRowCount="1">
|
209
|
+
<autoFilter ref="B3:D6"/>
|
210
|
+
<tableColumns count="3">
|
211
|
+
<tableColumn id="1" name="ColA" totalsRowLabel="Total"/>
|
212
|
+
<tableColumn id="2" name="ColB" totalsRowFunction="custom" dataDxfId="1">
|
213
|
+
<calculatedColumnFormula>FirstTable[[#This Row],[ColA]]+FirstTable[[#This Row],[ColC]]</calculatedColumnFormula>
|
214
|
+
<totalsRowFormula>AVERAGE(FirstTable[ColB])</totalsRowFormula>
|
215
|
+
</tableColumn>
|
216
|
+
<tableColumn id="3" name="ColC" totalsRowFunction="count" dataDxfId="0">
|
217
|
+
<calculatedColumnFormula>3*FirstTable[[#This Row],[ColA]]</calculatedColumnFormula>
|
218
|
+
</tableColumn>
|
219
|
+
</tableColumns>
|
220
|
+
<tableStyleInfo name="TableStyleLight16" showFirstColumn="1" showLastColumn="1" showRowStripes="1" showColumnStripes="1"/>
|
221
|
+
</table>
|
222
|
+
END
|
223
|
+
|
224
|
+
table_worksheet_xml =<<END
|
225
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
226
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" mc:Ignorable="x14ac">
|
227
|
+
<dimension ref="B3:H10"/>
|
228
|
+
<sheetViews>
|
229
|
+
<sheetView tabSelected="1" workbookViewId="0">
|
230
|
+
<selection activeCell="H4" sqref="H4"/>
|
231
|
+
</sheetView>
|
232
|
+
</sheetViews>
|
233
|
+
<sheetFormatPr defaultRowHeight="15" x14ac:dyDescent="0.25"/>
|
234
|
+
<sheetData>
|
235
|
+
<row r="3" spans="2:8" x14ac:dyDescent="0.25">
|
236
|
+
<c r="B3" t="s">
|
237
|
+
<v>0</v>
|
238
|
+
</c>
|
239
|
+
<c r="C3" t="s">
|
240
|
+
<v>1</v>
|
241
|
+
</c>
|
242
|
+
<c r="D3" t="s">
|
243
|
+
<v>2</v>
|
244
|
+
</c>
|
245
|
+
<c r="F3" t="str">
|
246
|
+
<f>FirstTable[[#Headers],[ColB]]</f>
|
247
|
+
<v>ColB</v>
|
248
|
+
</c>
|
249
|
+
<c r="H3">
|
250
|
+
<f>+MATCH("ColC",FirstTable[#Headers])</f>
|
251
|
+
<v>3</v>
|
252
|
+
</c>
|
253
|
+
</row>
|
254
|
+
<row r="4" spans="2:8" x14ac:dyDescent="0.25">
|
255
|
+
<c r="B4">
|
256
|
+
<v>1</v>
|
257
|
+
</c>
|
258
|
+
<c r="C4">
|
259
|
+
<f>FirstTable[[#This Row],[ColA]]+FirstTable[[#This Row],[ColC]]</f>
|
260
|
+
<v>4</v>
|
261
|
+
</c>
|
262
|
+
<c r="D4">
|
263
|
+
<f>3*FirstTable[[#This Row],[ColA]]</f>
|
264
|
+
<v>3</v>
|
265
|
+
</c>
|
266
|
+
<c r="F4">
|
267
|
+
<f>SUM(FirstTable[#This Row])</f>
|
268
|
+
<v>8</v>
|
269
|
+
</c>
|
270
|
+
<c r="H4">
|
271
|
+
<f>MATCH(8,FirstTable[[#All],[ColB]])</f>
|
272
|
+
<v>3</v>
|
273
|
+
</c>
|
274
|
+
</row>
|
275
|
+
<row r="5" spans="2:8" x14ac:dyDescent="0.25">
|
276
|
+
<c r="B5">
|
277
|
+
<v>2</v>
|
278
|
+
</c>
|
279
|
+
<c r="C5">
|
280
|
+
<f>FirstTable[[#This Row],[ColA]]+FirstTable[[#This Row],[ColC]]</f>
|
281
|
+
<v>8</v>
|
282
|
+
</c>
|
283
|
+
<c r="D5">
|
284
|
+
<f>3*FirstTable[[#This Row],[ColA]]</f>
|
285
|
+
<v>6</v>
|
286
|
+
</c>
|
287
|
+
<c r="F5">
|
288
|
+
<f>FirstTable[[#This Row],[ColB]]</f>
|
289
|
+
<v>8</v>
|
290
|
+
</c>
|
291
|
+
</row>
|
292
|
+
<row r="6" spans="2:8" x14ac:dyDescent="0.25">
|
293
|
+
<c r="B6">
|
294
|
+
<v>3</v>
|
295
|
+
</c>
|
296
|
+
<c r="C6">
|
297
|
+
<f>FirstTable[[#This Row],[ColA]]+FirstTable[[#This Row],[ColC]]</f>
|
298
|
+
<v>12</v>
|
299
|
+
</c>
|
300
|
+
<c r="D6">
|
301
|
+
<f>3*FirstTable[[#This Row],[ColA]]</f>
|
302
|
+
<v>9</v>
|
303
|
+
</c>
|
304
|
+
</row>
|
305
|
+
<row r="7" spans="2:8" x14ac:dyDescent="0.25">
|
306
|
+
<c r="B7" t="s">
|
307
|
+
<v>3</v>
|
308
|
+
</c>
|
309
|
+
<c r="C7">
|
310
|
+
<f>AVERAGE(FirstTable[ColB])</f>
|
311
|
+
<v>8</v>
|
312
|
+
</c>
|
313
|
+
<c r="D7">
|
314
|
+
<f>SUBTOTAL(103,FirstTable[ColC])</f>
|
315
|
+
<v>3</v>
|
316
|
+
</c>
|
317
|
+
</row>
|
318
|
+
<row r="10" spans="2:8" x14ac:dyDescent="0.25">
|
319
|
+
<c r="B10">
|
320
|
+
<f>SUM(FirstTable[ColA])</f>
|
321
|
+
<v>6</v>
|
322
|
+
</c>
|
323
|
+
<c r="C10">
|
324
|
+
<f>FirstTable[[#Totals],[ColB]]</f>
|
325
|
+
<v>8</v>
|
326
|
+
</c>
|
327
|
+
<c r="D10">
|
328
|
+
<f>FirstTable[[#Totals],[ColC]]</f>
|
329
|
+
<v>3</v>
|
330
|
+
</c>
|
331
|
+
</row>
|
332
|
+
</sheetData>
|
333
|
+
<pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/>
|
334
|
+
<tableParts count="1">
|
335
|
+
<tablePart r:id="rId1"/>
|
336
|
+
</tableParts>
|
337
|
+
</worksheet>
|
338
|
+
END
|
339
|
+
|
340
|
+
table_worksheet_shared_strings =<<END
|
341
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
342
|
+
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="4" uniqueCount="4"><si><t>ColA</t></si><si><t>ColB</t></si><si><t>ColC</t></si><si><t>Total</t></si></sst>
|
343
|
+
END
|
344
|
+
|
345
|
+
table_worksheet_ruby =<<END
|
346
|
+
# coding: utf-8
|
347
|
+
#
|
348
|
+
class Sheet1 < Spreadsheet
|
349
|
+
def b3; "ColA"; end
|
350
|
+
def c3; "ColB"; end
|
351
|
+
def d3; "ColC"; end
|
352
|
+
def f3; @f3 ||= sheet1.c3; end
|
353
|
+
def h3; @h3 ||= +3.0; end
|
354
|
+
def b4; 1.0; end
|
355
|
+
def c4; @c4 ||= sheet1.b4+sheet1.d4; end
|
356
|
+
def d4; @d4 ||= 3.0*sheet1.b4; end
|
357
|
+
def f4; @f4 ||= sum(sheet1.a('b4','d4')); end
|
358
|
+
def h4; @h4 ||= match(8.0,sheet1.a('c3','c7')); end
|
359
|
+
def b5; 2.0; end
|
360
|
+
def c5; @c5 ||= sheet1.b5+sheet1.d5; end
|
361
|
+
def d5; @d5 ||= 3.0*sheet1.b5; end
|
362
|
+
def f5; @f5 ||= sheet1.c5; end
|
363
|
+
def b6; 3.0; end
|
364
|
+
def c6; @c6 ||= sheet1.b6+sheet1.d6; end
|
365
|
+
def d6; @d6 ||= 3.0*sheet1.b6; end
|
366
|
+
def b7; "Total"; end
|
367
|
+
def c7; @c7 ||= average(sheet1.a('c4','c6')); end
|
368
|
+
def d7; @d7 ||= subtotal(103.0,sheet1.a('d4','d6')); end
|
369
|
+
def b10; @b10 ||= sum(sheet1.a('b4','b6')); end
|
370
|
+
def c10; @c10 ||= sheet1.c7; end
|
371
|
+
def d10; @d10 ||= sheet1.d7; end
|
372
|
+
end
|
373
|
+
|
374
|
+
END
|
375
|
+
|
376
|
+
table_worksheet_test =<<END
|
377
|
+
# coding: utf-8
|
378
|
+
require_relative '../spreadsheet'
|
379
|
+
#
|
380
|
+
describe 'Sheet1' do
|
381
|
+
def sheet1; $spreadsheet ||= Spreadsheet.new; $spreadsheet.sheet1; end
|
382
|
+
|
383
|
+
it 'cell f3 should equal "ColB"' do
|
384
|
+
sheet1.f3.should == "ColB"
|
385
|
+
end
|
386
|
+
|
387
|
+
it 'cell h3 should equal 3.0' do
|
388
|
+
sheet1.h3.should be_close(3.0,0.3)
|
389
|
+
end
|
390
|
+
|
391
|
+
it 'cell c4 should equal 4.0' do
|
392
|
+
sheet1.c4.should be_close(4.0,0.4)
|
393
|
+
end
|
394
|
+
|
395
|
+
it 'cell d4 should equal 3.0' do
|
396
|
+
sheet1.d4.should be_close(3.0,0.3)
|
397
|
+
end
|
398
|
+
|
399
|
+
it 'cell f4 should equal 8.0' do
|
400
|
+
sheet1.f4.should be_close(8.0,0.8)
|
401
|
+
end
|
402
|
+
|
403
|
+
it 'cell h4 should equal 3.0' do
|
404
|
+
sheet1.h4.should be_close(3.0,0.3)
|
405
|
+
end
|
406
|
+
|
407
|
+
it 'cell c5 should equal 8.0' do
|
408
|
+
sheet1.c5.should be_close(8.0,0.8)
|
409
|
+
end
|
410
|
+
|
411
|
+
it 'cell d5 should equal 6.0' do
|
412
|
+
sheet1.d5.should be_close(6.0,0.6)
|
413
|
+
end
|
414
|
+
|
415
|
+
it 'cell f5 should equal 8.0' do
|
416
|
+
sheet1.f5.should be_close(8.0,0.8)
|
417
|
+
end
|
418
|
+
|
419
|
+
it 'cell c6 should equal 12.0' do
|
420
|
+
sheet1.c6.should be_close(12.0,1.2)
|
421
|
+
end
|
422
|
+
|
423
|
+
it 'cell d6 should equal 9.0' do
|
424
|
+
sheet1.d6.should be_close(9.0,0.9)
|
425
|
+
end
|
426
|
+
|
427
|
+
it 'cell c7 should equal 8.0' do
|
428
|
+
sheet1.c7.should be_close(8.0,0.8)
|
429
|
+
end
|
430
|
+
|
431
|
+
it 'cell d7 should equal 3.0' do
|
432
|
+
sheet1.d7.should be_close(3.0,0.3)
|
433
|
+
end
|
434
|
+
|
435
|
+
it 'cell b10 should equal 6.0' do
|
436
|
+
sheet1.b10.should be_close(6.0,0.6)
|
437
|
+
end
|
438
|
+
|
439
|
+
it 'cell c10 should equal 8.0' do
|
440
|
+
sheet1.c10.should be_close(8.0,0.8)
|
441
|
+
end
|
442
|
+
|
443
|
+
it 'cell d10 should equal 3.0' do
|
444
|
+
sheet1.d10.should be_close(3.0,0.3)
|
445
|
+
end
|
446
|
+
|
447
|
+
end
|
448
|
+
|
449
|
+
END
|
450
|
+
|
451
|
+
it 'should create a ruby file from xml, dealing correctly with tables' do
|
452
|
+
worksheet = Worksheet.new(Nokogiri::XML(table_worksheet_xml))
|
453
|
+
Table.from_xml(worksheet,Nokogiri::XML(table_xml).root)
|
454
|
+
worksheet.workbook = mock(:workbook,:indirects_used => true, :worksheets => { 'sheet1' => worksheet})
|
455
|
+
SharedStrings.instance.clear
|
456
|
+
SharedStrings.instance.load_strings_from_xml(Nokogiri::XML(table_worksheet_shared_strings))
|
457
|
+
worksheet.name = 'sheet1'
|
458
|
+
worksheet.to_ruby.should == table_worksheet_ruby
|
459
|
+
worksheet.to_test.should == table_worksheet_test
|
460
|
+
end
|
461
|
+
|
462
|
+
table_worksheet_relationships =<<END
|
463
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
464
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
465
|
+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/table" Target="../tables/table1.xml"/>
|
466
|
+
</Relationships>
|
467
|
+
END
|
468
|
+
|
469
|
+
it 'should have a Worksheet#from_file method that also loads the tables' do
|
470
|
+
{ '/usr/local/excel/xl/worksheets/sheet1.xml' => table_worksheet_xml,
|
471
|
+
'/usr/local/excel/xl/worksheets/_rels/sheet1.xml.rels' => table_worksheet_relationships,
|
472
|
+
'/usr/local/excel/xl/tables/table1.xml' => table_xml
|
473
|
+
}.each do |filename,xml|
|
474
|
+
File.should_receive(:open).with(filename).and_yield(StringIO.new(xml))
|
475
|
+
end
|
476
|
+
File.should_receive(:exist?).with('/usr/local/excel/xl/worksheets/_rels/sheet1.xml.rels').and_return(true)
|
477
|
+
|
478
|
+
Table.tables.clear
|
479
|
+
worksheet = Worksheet.from_file('/usr/local/excel/xl/worksheets/sheet1.xml')
|
480
|
+
SharedStrings.instance.clear
|
481
|
+
SharedStrings.instance.load_strings_from_xml(Nokogiri::XML(table_worksheet_shared_strings))
|
482
|
+
worksheet.workbook = mock(:workbook,:indirects_used => true, :worksheets => { 'sheet1' => worksheet})
|
483
|
+
worksheet.name = 'sheet1'
|
484
|
+
worksheet.to_ruby.should == table_worksheet_ruby
|
485
|
+
end
|
486
|
+
end
|