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,27 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe WorkbookPruner do
|
4
|
+
|
5
|
+
it "should initialize with a workbook and ensure that all the worksheets in that workbook check their dependencies" do
|
6
|
+
workbook = mock(:workbook)
|
7
|
+
WorkbookPruner.new(workbook)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "should be able prune any cells not required" do
|
11
|
+
workbook = mock(:workbook)
|
12
|
+
workbook.should_receive(:work_out_dependencies)
|
13
|
+
sheet1 = mock(:worksheet)
|
14
|
+
workbook.should_receive(:worksheets).at_least(:once).and_return({'sheet1' => sheet1})
|
15
|
+
workbook.should_receive(:total_cells).and_return(2)
|
16
|
+
cell1 = mock(:cell)
|
17
|
+
sheet1.should_receive(:cells).at_least(:once).and_return({'a1' => cell1})
|
18
|
+
cell1.should_receive(:dependencies).and_return(['sheet1.a2'])
|
19
|
+
cell2 = mock(:cell)
|
20
|
+
workbook.should_receive(:cell).with('sheet1.a2').and_return(cell2)
|
21
|
+
cell2.should_receive(:dependencies).and_return([])
|
22
|
+
SheetNames.instance.clear
|
23
|
+
SheetNames.instance['Output Sheet'] = 'sheet1'
|
24
|
+
wb = WorkbookPruner.new(workbook)
|
25
|
+
wb.prune_cells_not_needed_for_output_sheets('Output Sheet')
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,283 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe Workbook do
|
4
|
+
|
5
|
+
workbook_xml =<<END
|
6
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
7
|
+
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
8
|
+
<fileVersion appName="xl" lastEdited="5" lowestEdited="5" rupBuild="9114"/>
|
9
|
+
<workbookPr defaultThemeVersion="124226"/>
|
10
|
+
<bookViews>
|
11
|
+
<workbookView xWindow="240" yWindow="90" windowWidth="9435" windowHeight="2070"/>
|
12
|
+
</bookViews>
|
13
|
+
<sheets>
|
14
|
+
<sheet name="First sheet" sheetId="1" r:id="rId1"/>
|
15
|
+
<sheet name="Sheet2" sheetId="2" r:id="rId2"/>
|
16
|
+
<sheet name="Sheet3" sheetId="3" r:id="rId3"/>
|
17
|
+
</sheets>
|
18
|
+
<definedNames>
|
19
|
+
<definedName name="OneAnd2">Sheet2!$A$2:$A$3</definedName>
|
20
|
+
<definedName name="Reference.2">Sheet2!$A$3</definedName>
|
21
|
+
<definedName name="ReferenceOne" localSheetId="1">'First sheet'!$A$1</definedName>
|
22
|
+
<definedName name="ReferenceOne">Sheet2!$A$2</definedName>
|
23
|
+
</definedNames>
|
24
|
+
<calcPr calcId="144315"/>
|
25
|
+
</workbook>
|
26
|
+
END
|
27
|
+
|
28
|
+
workbook_relationship_xml =<<END
|
29
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
30
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
|
31
|
+
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet3.xml"/>
|
32
|
+
<Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain" Target="calcChain.xml"/>
|
33
|
+
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet2.xml"/>
|
34
|
+
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/>
|
35
|
+
<Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/>
|
36
|
+
<Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/>
|
37
|
+
<Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/>
|
38
|
+
</Relationships>
|
39
|
+
END
|
40
|
+
|
41
|
+
simple_worksheet_xml =<<END
|
42
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
43
|
+
<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:*">
|
44
|
+
<dimension ref="A1:A2"/>
|
45
|
+
<sheetViews>
|
46
|
+
<sheetView view="pageLayout" workbookViewId="0"/>
|
47
|
+
</sheetViews>
|
48
|
+
<sheetFormatPr baseColWidth="10" defaultRowHeight="13"/>
|
49
|
+
<sheetData>
|
50
|
+
<row r="1" spans="1:1">
|
51
|
+
<c r="A1" t="str">
|
52
|
+
<f>IF(A2="Hello","hello",Sheet2!B4)</f>
|
53
|
+
<v>hello</v>
|
54
|
+
</c>
|
55
|
+
</row>
|
56
|
+
<row r="2" spans="1:1">
|
57
|
+
<c r="A2" t="s">
|
58
|
+
<v>0</v>
|
59
|
+
</c>
|
60
|
+
</row>
|
61
|
+
</sheetData>
|
62
|
+
<sheetCalcPr fullCalcOnLoad="1"/>
|
63
|
+
<phoneticPr fontId="2" type="noConversion"/>
|
64
|
+
<pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/>
|
65
|
+
<pageSetup paperSize="10" orientation="portrait" horizontalDpi="4294967292" verticalDpi="4294967292"/>
|
66
|
+
<extLst>
|
67
|
+
<ext xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" uri="http://schemas.microsoft.com/office/mac/excel/2008/main">
|
68
|
+
<mx:PLV Mode="1" OnePage="0" WScale="0"/>
|
69
|
+
</ext>
|
70
|
+
</extLst>
|
71
|
+
</worksheet>
|
72
|
+
END
|
73
|
+
|
74
|
+
simple_worksheet_ruby =<<END
|
75
|
+
# coding: utf-8
|
76
|
+
# First sheet
|
77
|
+
class Sheet1 < Spreadsheet
|
78
|
+
def a1; @a1 ||= excel_if(a2=="Hello","hello",sheet2.b4); end
|
79
|
+
def a2; "Hello"; end
|
80
|
+
end
|
81
|
+
|
82
|
+
END
|
83
|
+
|
84
|
+
shared_strings_xml =<<END
|
85
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
86
|
+
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="1" uniqueCount="1">
|
87
|
+
<si>
|
88
|
+
<t>Hello</t>
|
89
|
+
<phoneticPr fontId="3" type="noConversion"/>
|
90
|
+
</si>
|
91
|
+
</sst>
|
92
|
+
END
|
93
|
+
|
94
|
+
workbook_ruby =<<END
|
95
|
+
# coding: utf-8
|
96
|
+
require 'rubyfromexcel'
|
97
|
+
|
98
|
+
class Spreadsheet
|
99
|
+
include RubyFromExcel::ExcelFunctions
|
100
|
+
|
101
|
+
def initialize
|
102
|
+
@worksheet_names = {"First sheet"=>"sheet1", "Sheet2"=>"sheet2", "Sheet3"=>"sheet3"}
|
103
|
+
@workbook_tables = {}
|
104
|
+
end
|
105
|
+
|
106
|
+
def one_and2; sheet2.a('a2','a3'); end
|
107
|
+
def reference_2; sheet2.a3; end
|
108
|
+
def reference_one; sheet2.a2; end
|
109
|
+
end
|
110
|
+
|
111
|
+
Dir[File.join(File.dirname(__FILE__),"sheets/","sheet*.rb")].each {|f| Spreadsheet.autoload(File.basename(f,".rb").capitalize,f)}
|
112
|
+
END
|
113
|
+
|
114
|
+
workbook_no_indirects_ruby =<<END
|
115
|
+
# coding: utf-8
|
116
|
+
require 'rubyfromexcel'
|
117
|
+
|
118
|
+
class Spreadsheet
|
119
|
+
include RubyFromExcel::ExcelFunctions
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
Dir[File.join(File.dirname(__FILE__),"sheets/","sheet*.rb")].each {|f| Spreadsheet.autoload(File.basename(f,".rb").capitalize,f)}
|
124
|
+
END
|
125
|
+
|
126
|
+
|
127
|
+
it "should load its relationships, and therefore create the requisite worksheets and shared strings" do
|
128
|
+
SharedStrings.instance.clear
|
129
|
+
Table.tables.clear
|
130
|
+
SheetNames.instance.clear
|
131
|
+
{
|
132
|
+
'/usr/local/excel/xl/workbook.xml' => workbook_xml,
|
133
|
+
'/usr/local/excel/xl/_rels/workbook.xml.rels' => workbook_relationship_xml,
|
134
|
+
'/usr/local/excel/xl/worksheets/sheet1.xml' => simple_worksheet_xml,
|
135
|
+
'/usr/local/excel/xl/worksheets/sheet2.xml' => simple_worksheet_xml,
|
136
|
+
'/usr/local/excel/xl/worksheets/sheet3.xml' => simple_worksheet_xml,
|
137
|
+
'/usr/local/excel/xl/sharedStrings.xml' => shared_strings_xml,
|
138
|
+
'/usr/local/excel/xl/worksheets/_rels/sheet1.xml.rels' => '',
|
139
|
+
'/usr/local/excel/xl/worksheets/_rels/sheet2.xml.rels' => '',
|
140
|
+
'/usr/local/excel/xl/worksheets/_rels/sheet3.xml.rels' => ''
|
141
|
+
}.each do |filename,xml|
|
142
|
+
File.should_receive(:open).with(filename).and_yield(StringIO.new(xml))
|
143
|
+
end
|
144
|
+
File.stub!(:exist?).and_return(true)
|
145
|
+
workbook = Workbook.new('/usr/local/excel/xl/workbook.xml')
|
146
|
+
workbook.worksheets['sheet1'].to_ruby.should == simple_worksheet_ruby
|
147
|
+
SheetNames.instance['First sheet'].should == 'sheet1'
|
148
|
+
workbook.to_ruby.should == workbook_no_indirects_ruby
|
149
|
+
workbook.indirects_used = true
|
150
|
+
workbook.to_ruby.should == workbook_ruby
|
151
|
+
end
|
152
|
+
|
153
|
+
end
|
154
|
+
|
155
|
+
describe Worksheet, "in pruning mode" do
|
156
|
+
pruning_workbook_xml =<<END
|
157
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
158
|
+
<workbook xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><fileVersion appName="xl" lastEdited="4" lowestEdited="4" rupBuild="4505"/><workbookPr date1904="1" showInkAnnotation="0" autoCompressPictures="0"/><bookViews><workbookView xWindow="-20" yWindow="-20" windowWidth="20760" windowHeight="14600" tabRatio="500"/></bookViews><sheets><sheet name="Outputs" sheetId="1" r:id="rId1"/><sheet name="Calcs" sheetId="2" r:id="rId2"/><sheet name="Inputs" sheetId="3" r:id="rId3"/></sheets><definedNames><definedName name="In_result">Inputs!$A$3</definedName></definedNames><calcPr calcId="130407" concurrentCalc="0"/><extLst><ext xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" uri="http://schemas.microsoft.com/office/mac/excel/2008/main"><mx:ArchID Flags="2"/></ext></extLst></workbook>
|
159
|
+
END
|
160
|
+
|
161
|
+
pruning_workbook_relationships_xml =<<END
|
162
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
163
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet3.xml"/><Relationship Id="rId4" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/theme" Target="theme/theme1.xml"/><Relationship Id="rId5" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles" Target="styles.xml"/><Relationship Id="rId6" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings" Target="sharedStrings.xml"/><Relationship Id="rId7" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/calcChain" Target="calcChain.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet1.xml"/><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/worksheet" Target="worksheets/sheet2.xml"/></Relationships>
|
164
|
+
END
|
165
|
+
|
166
|
+
pruning_shared_strings_xml =<<END
|
167
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
168
|
+
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="7" uniqueCount="6"><si><t>Result</t><phoneticPr fontId="1" type="noConversion"/></si><si><t>Input</t><phoneticPr fontId="1" type="noConversion"/></si><si><t>Not in result</t><phoneticPr fontId="1" type="noConversion"/></si><si><t>In result</t><phoneticPr fontId="1" type="noConversion"/></si><si><t>Inputs</t><phoneticPr fontId="1" type="noConversion"/></si><si><t>Doesn't depend on an input</t><phoneticPr fontId="1" type="noConversion"/></si></sst>
|
169
|
+
END
|
170
|
+
|
171
|
+
pruning_output_sheet_xml =<<END
|
172
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
173
|
+
<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:B4"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="B5" sqref="B5"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="13"/><sheetData><row r="1" spans="1:2"><c r="A1" t="s"><v>0</v></c><c r="B1"><f>Calcs!A1</f><v>121</v></c></row><row r="2" spans="1:2"><c r="A2" t="s"><v>1</v></c><c r="B2"><f>Inputs!A1</f><v>99</v></c></row><row r="3" spans="1:2"><c r="B3" t="str"><f ca="1">Calcs!C9</f><v>In result</v></c></row><row r="4" spans="1:2"><c r="B4" t="str"><f>Calcs!C13</f><v>Doesn't depend on an input</v></c></row></sheetData><sheetCalcPr fullCalcOnLoad="1"/><phoneticPr fontId="1" type="noConversion"/><pageMargins left="0.75" right="0.75" top="1" bottom="1" header="0.5" footer="0.5"/><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="0" OnePage="0" WScale="0"/></ext></extLst></worksheet>
|
174
|
+
END
|
175
|
+
|
176
|
+
pruning_calc_sheet_xml =<<END
|
177
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
178
|
+
<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:D13"/><sheetViews><sheetView view="pageLayout" workbookViewId="0"><selection activeCell="C14" sqref="C14"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="13"/><sheetData><row r="1" spans="1:4"><c r="A1"><f>SUM(A2:A7)</f><v>121</v></c></row><row r="2" spans="1:4"><c r="A2"><v>1</v></c><c r="C2" t="s"><v>2</v></c></row><row r="3" spans="1:4"><c r="A3"><v>2</v></c><c r="C3"><f>Inputs!A1*10</f><v>990</v></c></row><row r="4" spans="1:4"><c r="A4"><f>Inputs!A1</f><v>99</v></c></row><row r="5" spans="1:4"><c r="A5"><v>4</v></c></row><row r="6" spans="1:4"><c r="A6"><f>C6</f><v>10</v></c><c r="C6"><v>10</v></c></row><row r="7" spans="1:4"><c r="A7"><v>5</v></c></row><row r="8" spans="1:4"><c r="C8" t="s"><v>4</v></c></row><row r="9" spans="1:4"><c r="C9" t="str"><f ca="1">INDIRECT("'"&C8&"'!In_result")</f><v>In result</v></c></row><row r="10" spans="1:4"><c r="C10" t="str"><f ca="1">INDIRECT("'"&C8&"'!A2")</f><v>Not in result</v></c></row><row r="13" spans="1:4"><c r="C13" t="str"><f>D13</f><v>Doesn't depend on an input</v></c><c r="D13" t="s"><v>5</v></c></row></sheetData><sheetCalcPr fullCalcOnLoad="1"/><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>
|
179
|
+
END
|
180
|
+
|
181
|
+
pruning_input_sheet_xml =<<END
|
182
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
183
|
+
<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:A3"/><sheetViews><sheetView view="pageLayout" workbookViewId="0"><selection activeCell="A3" sqref="A3"/></sheetView></sheetViews><sheetFormatPr baseColWidth="10" defaultRowHeight="13"/><sheetData><row r="1" spans="1:1"><c r="A1"><v>99</v></c></row><row r="2" spans="1:1"><c r="A2" t="s"><v>2</v></c></row><row r="3" spans="1:1"><c r="A3" t="s"><v>3</v></c></row></sheetData><sheetCalcPr fullCalcOnLoad="1"/><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>
|
184
|
+
END
|
185
|
+
|
186
|
+
pruning_calc_sheet_ruby_no_prune =<<END
|
187
|
+
# coding: utf-8
|
188
|
+
# Calcs
|
189
|
+
class Sheet2 < Spreadsheet
|
190
|
+
def a1; @a1 ||= sum(a('a2','a7')); end
|
191
|
+
def a2; 1.0; end
|
192
|
+
def c2; "Not in result"; end
|
193
|
+
def a3; 2.0; end
|
194
|
+
def c3; @c3 ||= sheet3.a1*10.0; end
|
195
|
+
def a4; @a4 ||= sheet3.a1; end
|
196
|
+
def a5; 4.0; end
|
197
|
+
def a6; @a6 ||= c6; end
|
198
|
+
def c6; 10.0; end
|
199
|
+
def a7; 5.0; end
|
200
|
+
def c8; "Inputs"; end
|
201
|
+
def c9; @c9 ||= sheet3.a3; end
|
202
|
+
def c10; @c10 ||= sheet3.a2; end
|
203
|
+
def c13; @c13 ||= d13; end
|
204
|
+
def d13; "Doesn't depend on an input"; end
|
205
|
+
end
|
206
|
+
|
207
|
+
END
|
208
|
+
|
209
|
+
pruning_calc_sheet_ruby_output_prune =<<END
|
210
|
+
# coding: utf-8
|
211
|
+
# Calcs
|
212
|
+
class Sheet2 < Spreadsheet
|
213
|
+
def a1; @a1 ||= sum(a('a2','a7')); end
|
214
|
+
def a2; 1.0; end
|
215
|
+
def a3; 2.0; end
|
216
|
+
def a4; @a4 ||= sheet3.a1; end
|
217
|
+
def a5; 4.0; end
|
218
|
+
def a6; @a6 ||= c6; end
|
219
|
+
def c6; 10.0; end
|
220
|
+
def a7; 5.0; end
|
221
|
+
def c8; "Inputs"; end
|
222
|
+
def c9; @c9 ||= sheet3.a3; end
|
223
|
+
def c13; @c13 ||= d13; end
|
224
|
+
def d13; "Doesn't depend on an input"; end
|
225
|
+
end
|
226
|
+
|
227
|
+
END
|
228
|
+
|
229
|
+
pruning_calc_sheet_ruby_input_and_output_prune =<<END
|
230
|
+
# coding: utf-8
|
231
|
+
# Calcs
|
232
|
+
class Sheet2 < Spreadsheet
|
233
|
+
def a1; @a1 ||= sum(a('a2','a7')); end
|
234
|
+
def a2; 1.0; end
|
235
|
+
def a3; 2.0; end
|
236
|
+
def a4; @a4 ||= sheet3.a1; end
|
237
|
+
def a5; 4.0; end
|
238
|
+
def a6; 10.0; end
|
239
|
+
def a7; 5.0; end
|
240
|
+
def c8; "Inputs"; end
|
241
|
+
def c9; @c9 ||= sheet3.a3; end
|
242
|
+
end
|
243
|
+
|
244
|
+
END
|
245
|
+
|
246
|
+
before do
|
247
|
+
SharedStrings.instance.clear
|
248
|
+
Table.tables.clear
|
249
|
+
SheetNames.instance.clear
|
250
|
+
{
|
251
|
+
'/usr/local/excel/xl/workbook.xml' => pruning_workbook_xml,
|
252
|
+
'/usr/local/excel/xl/_rels/workbook.xml.rels' => pruning_workbook_relationships_xml,
|
253
|
+
'/usr/local/excel/xl/worksheets/sheet1.xml' => pruning_output_sheet_xml,
|
254
|
+
'/usr/local/excel/xl/worksheets/sheet2.xml' => pruning_calc_sheet_xml,
|
255
|
+
'/usr/local/excel/xl/worksheets/sheet3.xml' => pruning_input_sheet_xml,
|
256
|
+
'/usr/local/excel/xl/sharedStrings.xml' => pruning_shared_strings_xml,
|
257
|
+
'/usr/local/excel/xl/worksheets/_rels/sheet1.xml.rels' => '',
|
258
|
+
'/usr/local/excel/xl/worksheets/_rels/sheet2.xml.rels' => '',
|
259
|
+
'/usr/local/excel/xl/worksheets/_rels/sheet3.xml.rels' => ''
|
260
|
+
}.each do |filename,xml|
|
261
|
+
File.should_receive(:open).with(filename).and_yield(StringIO.new(xml))
|
262
|
+
end
|
263
|
+
File.stub!(:exist?).and_return(true)
|
264
|
+
@workbook = Workbook.new('/usr/local/excel/xl/workbook.xml')
|
265
|
+
end
|
266
|
+
|
267
|
+
it "should work normally when no output sheets are identified" do
|
268
|
+
@workbook.total_cells.should == 24
|
269
|
+
@workbook.worksheets['sheet2'].to_ruby.should == pruning_calc_sheet_ruby_no_prune
|
270
|
+
end
|
271
|
+
|
272
|
+
it "should prune any cells that aren't needed for the output sheet calculations when output sheets have been specified" do
|
273
|
+
@workbook.prune_cells_not_needed_for_output_sheets('Outputs')
|
274
|
+
@workbook.worksheets['sheet2'].to_ruby.should == pruning_calc_sheet_ruby_output_prune
|
275
|
+
end
|
276
|
+
|
277
|
+
it "should convert cells to values where they don't depend on inputs, and then prune" do
|
278
|
+
@workbook.prune_cells_not_needed_for_output_sheets('Outputs')
|
279
|
+
@workbook.convert_cells_to_values_when_independent_of_input_sheets('Inputs')
|
280
|
+
@workbook.worksheets['sheet2'].to_ruby.should == pruning_calc_sheet_ruby_input_and_output_prune
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require_relative 'spec_helper'
|
2
|
+
|
3
|
+
describe "Worksheets that failed to compile" do
|
4
|
+
worksheet_1_xml =<<END
|
5
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
6
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships">
|
7
|
+
<sheetData>
|
8
|
+
<row r="9">
|
9
|
+
<c r="R9">
|
10
|
+
<f t="shared" ref="R9:R68" si="0">I9+J9+K9+P9+Q9</f>
|
11
|
+
<v>582.62431955664806</v>
|
12
|
+
</c>
|
13
|
+
</row>
|
14
|
+
<row r="10">
|
15
|
+
<c r="R10">
|
16
|
+
<f t="shared" si="0"/>
|
17
|
+
<v>436.4944796177661</v>
|
18
|
+
</c>
|
19
|
+
</row>
|
20
|
+
</sheetData>
|
21
|
+
</worksheet>
|
22
|
+
END
|
23
|
+
|
24
|
+
worksheet_1_ruby =<<END
|
25
|
+
# coding: utf-8
|
26
|
+
#
|
27
|
+
class Sheet1 < Spreadsheet
|
28
|
+
def r9; @r9 ||= i9+j9+k9+p9+q9; end
|
29
|
+
def r10; @r10 ||= i10+j10+k10+p10+q10; end
|
30
|
+
end
|
31
|
+
|
32
|
+
END
|
33
|
+
it "2050 failed sheet should compile" do
|
34
|
+
SheetNames.instance['Sheet2'] = 'sheet2'
|
35
|
+
# SharedStrings.instance[24] = 'A shared string'
|
36
|
+
worksheet = Worksheet.new(Nokogiri::XML(worksheet_1_xml))
|
37
|
+
worksheet.workbook = mock(:workbook,:indirects_used => true)
|
38
|
+
worksheet.name = "sheet1"
|
39
|
+
worksheet.to_ruby.should == worksheet_1_ruby
|
40
|
+
end
|
41
|
+
end
|