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,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<a:theme xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main" name="Office Theme"><a:themeElements><a:clrScheme name="Office"><a:dk1><a:sysClr val="windowText" lastClr="000000"/></a:dk1><a:lt1><a:sysClr val="window" lastClr="FFFFFF"/></a:lt1><a:dk2><a:srgbClr val="1F497D"/></a:dk2><a:lt2><a:srgbClr val="EEECE1"/></a:lt2><a:accent1><a:srgbClr val="4F81BD"/></a:accent1><a:accent2><a:srgbClr val="C0504D"/></a:accent2><a:accent3><a:srgbClr val="9BBB59"/></a:accent3><a:accent4><a:srgbClr val="8064A2"/></a:accent4><a:accent5><a:srgbClr val="4BACC6"/></a:accent5><a:accent6><a:srgbClr val="F79646"/></a:accent6><a:hlink><a:srgbClr val="0000FF"/></a:hlink><a:folHlink><a:srgbClr val="800080"/></a:folHlink></a:clrScheme><a:fontScheme name="Office"><a:majorFont><a:latin typeface="Cambria"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS Pゴシック"/><a:font script="Hang" typeface="맑은 고딕"/><a:font script="Hans" typeface="宋体"/><a:font script="Hant" typeface="新細明體"/><a:font script="Arab" typeface="Times New Roman"/><a:font script="Hebr" typeface="Times New Roman"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="MoolBoran"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Times New Roman"/><a:font script="Uigh" typeface="Microsoft Uighur"/></a:majorFont><a:minorFont><a:latin typeface="Calibri"/><a:ea typeface=""/><a:cs typeface=""/><a:font script="Jpan" typeface="MS Pゴシック"/><a:font script="Hang" typeface="맑은 고딕"/><a:font script="Hans" typeface="宋体"/><a:font script="Hant" typeface="新細明體"/><a:font script="Arab" typeface="Arial"/><a:font script="Hebr" typeface="Arial"/><a:font script="Thai" typeface="Tahoma"/><a:font script="Ethi" typeface="Nyala"/><a:font script="Beng" typeface="Vrinda"/><a:font script="Gujr" typeface="Shruti"/><a:font script="Khmr" typeface="DaunPenh"/><a:font script="Knda" typeface="Tunga"/><a:font script="Guru" typeface="Raavi"/><a:font script="Cans" typeface="Euphemia"/><a:font script="Cher" typeface="Plantagenet Cherokee"/><a:font script="Yiii" typeface="Microsoft Yi Baiti"/><a:font script="Tibt" typeface="Microsoft Himalaya"/><a:font script="Thaa" typeface="MV Boli"/><a:font script="Deva" typeface="Mangal"/><a:font script="Telu" typeface="Gautami"/><a:font script="Taml" typeface="Latha"/><a:font script="Syrc" typeface="Estrangelo Edessa"/><a:font script="Orya" typeface="Kalinga"/><a:font script="Mlym" typeface="Kartika"/><a:font script="Laoo" typeface="DokChampa"/><a:font script="Sinh" typeface="Iskoola Pota"/><a:font script="Mong" typeface="Mongolian Baiti"/><a:font script="Viet" typeface="Arial"/><a:font script="Uigh" typeface="Microsoft Uighur"/></a:minorFont></a:fontScheme><a:fmtScheme name="Office"><a:fillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="50000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="35000"><a:schemeClr val="phClr"><a:tint val="37000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:tint val="15000"/><a:satMod val="350000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="1"/></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:shade val="51000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="80000"><a:schemeClr val="phClr"><a:shade val="93000"/><a:satMod val="130000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="94000"/><a:satMod val="135000"/></a:schemeClr></a:gs></a:gsLst><a:lin ang="16200000" scaled="0"/></a:gradFill></a:fillStyleLst><a:lnStyleLst><a:ln w="9525" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"><a:shade val="95000"/><a:satMod val="105000"/></a:schemeClr></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="25400" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln><a:ln w="38100" cap="flat" cmpd="sng" algn="ctr"><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:prstDash val="solid"/></a:ln></a:lnStyleLst><a:effectStyleLst><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="20000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="38000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst></a:effectStyle><a:effectStyle><a:effectLst><a:outerShdw blurRad="40000" dist="23000" dir="5400000" rotWithShape="0"><a:srgbClr val="000000"><a:alpha val="35000"/></a:srgbClr></a:outerShdw></a:effectLst><a:scene3d><a:camera prst="orthographicFront"><a:rot lat="0" lon="0" rev="0"/></a:camera><a:lightRig rig="threePt" dir="t"><a:rot lat="0" lon="0" rev="1200000"/></a:lightRig></a:scene3d><a:sp3d><a:bevelT w="63500" h="25400"/></a:sp3d></a:effectStyle></a:effectStyleLst><a:bgFillStyleLst><a:solidFill><a:schemeClr val="phClr"/></a:solidFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="40000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="40000"><a:schemeClr val="phClr"><a:tint val="45000"/><a:shade val="99000"/><a:satMod val="350000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="20000"/><a:satMod val="255000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="-80000" r="50000" b="180000"/></a:path></a:gradFill><a:gradFill rotWithShape="1"><a:gsLst><a:gs pos="0"><a:schemeClr val="phClr"><a:tint val="80000"/><a:satMod val="300000"/></a:schemeClr></a:gs><a:gs pos="100000"><a:schemeClr val="phClr"><a:shade val="30000"/><a:satMod val="200000"/></a:schemeClr></a:gs></a:gsLst><a:path path="circle"><a:fillToRect l="50000" t="50000" r="50000" b="50000"/></a:path></a:gradFill></a:bgFillStyleLst></a:fmtScheme></a:themeElements><a:objectDefaults/><a:extraClrSchemeLst/></a:theme>
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<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 defaultThemeVersion="124226"/><bookViews><workbookView xWindow="120" yWindow="45" windowWidth="14175" windowHeight="5325"/></bookViews><sheets><sheet name="Sheet1" sheetId="1" r:id="rId1"/><sheet name="Sheet2" sheetId="2" r:id="rId2"/><sheet name="Sheet3" sheetId="3" r:id="rId3"/></sheets><calcPr calcId="125725"/></workbook>
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"><Relationship Id="rId2" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/table" Target="../tables/table1.xml"/><Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/printerSettings" Target="../printerSettings/printerSettings1.bin"/></Relationships>
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="B2:D5"/><sheetViews><sheetView tabSelected="1" workbookViewId="0"><selection activeCell="B15" sqref="B15"/></sheetView></sheetViews><sheetFormatPr defaultRowHeight="12.75"/><cols><col min="2" max="2" width="11.28515625" customWidth="1"/><col min="3" max="3" width="11.85546875" customWidth="1"/><col min="4" max="4" width="11.28515625" customWidth="1"/></cols><sheetData><row r="2" spans="2:4"><c r="B2" t="s"><v>0</v></c><c r="C2" t="s"><v>1</v></c><c r="D2" t="s"><v>2</v></c></row><row r="3" spans="2:4"><c r="B3"><v>1</v></c><c r="C3"><v>2</v></c><c r="D3" s="1"><f>[Column A]+[[Column B ]]</f><v>3</v></c></row><row r="4" spans="2:4"><c r="B4"><v>3</v></c><c r="C4"><v>4</v></c><c r="D4" s="1"><f>[Column A]+[[Column B ]]</f><v>7</v></c></row><row r="5" spans="2:4"><c r="B5"><v>5</v></c><c r="C5"><v>6</v></c><c r="D5" s="1"><f>[Column A]+[[Column B ]]</f><v>11</v></c></row></sheetData><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/><pageSetup paperSize="9" orientation="portrait" r:id="rId1"/><tableParts count="1"><tablePart r:id="rId2"/></tableParts></worksheet>
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1"/><sheetViews><sheetView workbookViewId="0"><selection activeCell="B5" sqref="B5"/></sheetView></sheetViews><sheetFormatPr defaultRowHeight="12.75"/><sheetData/><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
2
|
+
<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"><dimension ref="A1"/><sheetViews><sheetView workbookViewId="0"/></sheetViews><sheetFormatPr defaultRowHeight="12.75"/><sheetData/><pageMargins left="0.7" right="0.7" top="0.75" bottom="0.75" header="0.3" footer="0.3"/></worksheet>
|
@@ -0,0 +1,58 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
class ArrayFormulaBuilder < FormulaBuilder
|
3
|
+
|
4
|
+
def sum_function(*args)
|
5
|
+
"sum(#{args.map {|a| a.visit(self)}.join(',')})"
|
6
|
+
end
|
7
|
+
|
8
|
+
def sumif_function(check_range,criteria,sum_range = nil)
|
9
|
+
if sum_range
|
10
|
+
"m(#{criteria.visit(self)}) { |r1| sumif(#{check_range.visit(self)},r1,#{sum_range.visit(self)}) }"
|
11
|
+
else
|
12
|
+
"m(#{criteria.visit(self)}) { |r1| sumif(#{check_range.visit(self)},r1) }"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def sumifs_function(sum_range,*args)
|
17
|
+
checks = Hash[*args]
|
18
|
+
"m(#{checks.values.map {|a| a.visit(self) }.join(',')}) { |#{checks.values.map.with_index {|a,i| "r#{i+1}"}.join(',')}| sumifs(#{sum_range.visit(self)},#{checks.map.with_index { |a,i| "#{a.first.visit(self)},r#{i+1}" }.join(',')}) }"
|
19
|
+
end
|
20
|
+
|
21
|
+
def standard_function(name_to_use_in_ruby,args)
|
22
|
+
arg_names = (1..(args.size)).map { |i| "r#{i}" }
|
23
|
+
"m(#{args.map {|a| a.visit(self) }.join(',')}) { |#{arg_names.join(',')}| #{name_to_use_in_ruby}(#{arg_names.join(',')}) }"
|
24
|
+
end
|
25
|
+
|
26
|
+
def index_function(index_range,*args)
|
27
|
+
arg_names = (1..(args.size)).map { |i| "r#{i}" }
|
28
|
+
"m(#{args.map {|a| a.visit(self) }.join(',')}) { |#{arg_names.join(',')}| index(#{index_range.visit(self)},#{arg_names.join(',')}) }"
|
29
|
+
end
|
30
|
+
|
31
|
+
def match_function(lookup_value,lookup_array,match_type = nil)
|
32
|
+
if match_type
|
33
|
+
"m(#{lookup_value.visit(self)},#{match_type.visit(self)}) { |r1,r2| match(r1,#{lookup_array.visit(self)},r2) }"
|
34
|
+
else
|
35
|
+
"m(#{lookup_value.visit(self)}) { |r1| match(r1,#{lookup_array.visit(self)}) }"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def comparison(left,comparison,right)
|
40
|
+
"m(#{left.visit(self)},#{right.visit(self)}) { |r1,r2| r1#{comparison.visit(self)}r2 }"
|
41
|
+
end
|
42
|
+
|
43
|
+
def arithmetic(*strings)
|
44
|
+
matrix_strings = []
|
45
|
+
matrix_string_references = []
|
46
|
+
strings = strings.map do |s|
|
47
|
+
if s.type == :operator
|
48
|
+
s.visit(self)
|
49
|
+
else
|
50
|
+
matrix_strings << s.visit(self)
|
51
|
+
matrix_string_references << "r#{matrix_string_references.size+1}"
|
52
|
+
matrix_string_references.last
|
53
|
+
end
|
54
|
+
end
|
55
|
+
"m(#{matrix_strings.join(',')}) { |#{matrix_string_references.join(',')}| #{strings.join} }"
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
class ArrayFormulaCell < FormulaCell
|
3
|
+
|
4
|
+
def ArrayFormulaCell.from_other_cell(cell)
|
5
|
+
afc = ArrayFormulaCell.new(cell.worksheet)
|
6
|
+
afc.reference = cell.reference
|
7
|
+
afc.xml_value = cell.xml_value
|
8
|
+
afc.xml_type = cell.xml_type
|
9
|
+
afc
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_accessor :array_formula_reference
|
13
|
+
attr_accessor :array_formula_offset
|
14
|
+
|
15
|
+
def parse_xml(xml)
|
16
|
+
# No
|
17
|
+
end
|
18
|
+
|
19
|
+
def work_out_dependencies
|
20
|
+
# No
|
21
|
+
end
|
22
|
+
|
23
|
+
def ruby_value
|
24
|
+
"@#{reference.to_ruby} ||= #{array_formula_reference}.array_formula_offset(#{array_formula_offset.join(',')})"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require_relative 'array_formula_builder'
|
2
|
+
|
3
|
+
module RubyFromExcel
|
4
|
+
class ArrayingFormulaCell < FormulaCell
|
5
|
+
|
6
|
+
attr_accessor :array_range
|
7
|
+
attr_accessor :array_formula_reference
|
8
|
+
attr_accessor :array_formula_offset
|
9
|
+
|
10
|
+
def parse_xml(xml)
|
11
|
+
super
|
12
|
+
self.array_range = Area.new(worksheet,*xml.at_css("f")['ref'].split(':'))
|
13
|
+
end
|
14
|
+
|
15
|
+
def alter_other_cells_if_required
|
16
|
+
self.array_formula_offset = [0,0]
|
17
|
+
self.array_formula_reference = reference.to_ruby + "_array"
|
18
|
+
array_formula_from_this_cell_onto_range
|
19
|
+
end
|
20
|
+
|
21
|
+
def array_formula_from_this_cell_onto_range
|
22
|
+
each_array_formula do |array_formula_reference,value_cell|
|
23
|
+
array_cell = ArrayFormulaCell.from_other_cell(value_cell)
|
24
|
+
array_formula_onto_cell array_cell
|
25
|
+
worksheet.replace_cell(array_formula_reference,array_cell)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def array_formula_onto_cell(cell)
|
30
|
+
cell.array_formula_reference = self.array_formula_reference
|
31
|
+
cell.array_formula_offset = offset_from(cell)
|
32
|
+
end
|
33
|
+
|
34
|
+
def offset_from(cell)
|
35
|
+
cell.reference - self.reference
|
36
|
+
end
|
37
|
+
|
38
|
+
def work_out_dependencies
|
39
|
+
super
|
40
|
+
each_array_formula do |array_formula_reference,array_cell|
|
41
|
+
next unless array_cell
|
42
|
+
array_cell.dependencies = self.dependencies
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def each_array_formula
|
47
|
+
array_range.to_reference_enum.each do |array_formula_reference|
|
48
|
+
next if array_formula_reference == reference.to_s
|
49
|
+
yield array_formula_reference, worksheet.cell(array_formula_reference)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def to_ruby(r = RubyScriptWriter.new)
|
54
|
+
r.put_simple_method array_formula_reference, "@#{array_formula_reference} ||= #{ruby_array_value}"
|
55
|
+
r.put_simple_method reference.to_ruby, ruby_value
|
56
|
+
r.to_s
|
57
|
+
end
|
58
|
+
|
59
|
+
def ruby_value
|
60
|
+
"@#{reference.to_ruby} ||= #{array_formula_reference}.array_formula_offset(#{array_formula_offset.join(',')})"
|
61
|
+
end
|
62
|
+
|
63
|
+
def ruby_array_value
|
64
|
+
ast.visit(ArrayFormulaBuilder.new(self))
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/cells/cell.rb
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
class Cell
|
3
|
+
|
4
|
+
attr_accessor :worksheet, :reference, :dependencies, :xml_value, :xml_type
|
5
|
+
|
6
|
+
def initialize(worksheet,xml = nil)
|
7
|
+
self.worksheet = worksheet
|
8
|
+
parse_xml xml
|
9
|
+
end
|
10
|
+
|
11
|
+
def parse_xml(xml)
|
12
|
+
return nil unless xml
|
13
|
+
self.reference = Reference.new(xml['r'],worksheet)
|
14
|
+
self.xml_value = xml.at_css("v").content
|
15
|
+
self.xml_type = xml['t']
|
16
|
+
end
|
17
|
+
|
18
|
+
def alter_other_cells_if_required
|
19
|
+
# nil
|
20
|
+
end
|
21
|
+
|
22
|
+
def work_out_dependencies
|
23
|
+
self.dependencies = []
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_ruby(r = RubyScriptWriter.new)
|
27
|
+
r.put_simple_method reference.to_ruby, ruby_value
|
28
|
+
r.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_test(r = RubySpecWriter.new)
|
32
|
+
r.put_spec "cell #{reference.to_ruby} should equal #{value}" do
|
33
|
+
r.puts "#{worksheet}.#{reference.to_ruby}.should #{test}"
|
34
|
+
end
|
35
|
+
r.to_s
|
36
|
+
end
|
37
|
+
|
38
|
+
def test
|
39
|
+
return "== #{value}" if xml_type
|
40
|
+
"be_close(#{value.to_f},#{tolerance_for(value.to_f)})"
|
41
|
+
end
|
42
|
+
|
43
|
+
def tolerance_for(value,tolerance = 0.1, maximum = 1e-8)
|
44
|
+
tolerance = value.abs * tolerance
|
45
|
+
tolerance = maximum if tolerance < maximum
|
46
|
+
tolerance
|
47
|
+
end
|
48
|
+
|
49
|
+
def can_be_replaced_with_value?
|
50
|
+
false
|
51
|
+
end
|
52
|
+
|
53
|
+
def value
|
54
|
+
value = xml_value
|
55
|
+
case xml_type
|
56
|
+
when 'str'
|
57
|
+
return value.inspect
|
58
|
+
when 's'
|
59
|
+
return SharedStrings.shared_string_for(value.to_i).inspect
|
60
|
+
when 'e'
|
61
|
+
return ":#{value.gsub(/[^a-zA-Z]/,'').downcase}"
|
62
|
+
when 'b'
|
63
|
+
return 'true' if value == '1'
|
64
|
+
return 'false' if value == '0'
|
65
|
+
return Formula.parse(value).visit(FormulaBuilder.new)
|
66
|
+
else
|
67
|
+
return Formula.parse(value).visit(FormulaBuilder.new)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def value_for_including
|
72
|
+
value = xml_value
|
73
|
+
case xml_type
|
74
|
+
when 'str'
|
75
|
+
return value
|
76
|
+
when 's'
|
77
|
+
return SharedStrings.shared_string_for(value.to_i)
|
78
|
+
when 'e'
|
79
|
+
return ":#{value.gsub(/[^a-zA-Z]/,'').downcase}"
|
80
|
+
when 'b'
|
81
|
+
return 'true' if value == '1'
|
82
|
+
return 'false' if value == '0'
|
83
|
+
return Formula.parse(value).visit(FormulaBuilder.new)
|
84
|
+
else
|
85
|
+
return Formula.parse(value).visit(FormulaBuilder.new)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def to_s
|
90
|
+
"#{worksheet}.#{reference}"
|
91
|
+
end
|
92
|
+
|
93
|
+
def inspect
|
94
|
+
"(cell: #{to_s} with formula:#{respond_to?(:ast) ? ast.inspect : "na"} and value '#{value}' of type '#{xml_type}')"
|
95
|
+
end
|
96
|
+
|
97
|
+
end
|
98
|
+
end
|
data/lib/cells/cells.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
require_relative 'cell'
|
2
|
+
require_relative 'value/value_cell'
|
3
|
+
require_relative 'formula/formula_cell'
|
4
|
+
require_relative 'formula/simple_formula_cell'
|
5
|
+
require_relative 'shared/sharing_formula_cell'
|
6
|
+
require_relative 'shared/shared_formula_cell'
|
7
|
+
require_relative 'array/arraying_formula_cell'
|
8
|
+
require_relative 'array/array_formula_cell'
|
9
|
+
require_relative 'array/single_cell_array_formula_cell'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
class FormulaCell < Cell
|
3
|
+
attr_accessor :ast
|
4
|
+
|
5
|
+
def parse_xml(xml)
|
6
|
+
super
|
7
|
+
self.ast = Formula.parse(xml.at_css("f").content)
|
8
|
+
end
|
9
|
+
|
10
|
+
def work_out_dependencies
|
11
|
+
self.dependencies ||= ast.visit(DependencyBuilder.new(self))
|
12
|
+
end
|
13
|
+
|
14
|
+
def ruby_value
|
15
|
+
"@#{reference.to_ruby} ||= #{ast.visit(FormulaBuilder.new(self))}"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
class SharedFormulaBuilder < FormulaBuilder
|
3
|
+
attr_accessor :shared_formula_offset
|
4
|
+
|
5
|
+
def initialize(formula_cell = nil, shared_formula_offset = nil)
|
6
|
+
super formula_cell
|
7
|
+
self.shared_formula_offset = shared_formula_offset
|
8
|
+
end
|
9
|
+
|
10
|
+
def cell(reference)
|
11
|
+
Reference.new(reference).shift!(shared_formula_offset).to_ruby
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative 'shared_formula_builder'
|
2
|
+
|
3
|
+
module RubyFromExcel
|
4
|
+
class SharedFormulaCell < FormulaCell
|
5
|
+
attr_accessor :shared_formula
|
6
|
+
attr_accessor :shared_formula_offset
|
7
|
+
|
8
|
+
def parse_formula
|
9
|
+
# No
|
10
|
+
end
|
11
|
+
|
12
|
+
def work_out_dependencies
|
13
|
+
self.dependencies ||= shared_formula.visit(SharedFormulaDependencyBuilder.new(self,shared_formula_offset))
|
14
|
+
end
|
15
|
+
|
16
|
+
def ruby_value
|
17
|
+
"@#{reference.to_ruby} ||= #{shared_formula.visit(SharedFormulaBuilder.new(self, shared_formula_offset))}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
class SharingFormulaCell < FormulaCell
|
3
|
+
|
4
|
+
attr_accessor :sharing_range
|
5
|
+
|
6
|
+
def parse_xml(xml)
|
7
|
+
super
|
8
|
+
sharing_range = xml.at_css("f")['ref']
|
9
|
+
sharing_range = "#{sharing_range}:#{sharing_range}" unless sharing_range =~ /:/
|
10
|
+
self.sharing_range = Area.new(worksheet,*sharing_range.split(':'))
|
11
|
+
end
|
12
|
+
|
13
|
+
def alter_other_cells_if_required
|
14
|
+
share_formula
|
15
|
+
end
|
16
|
+
|
17
|
+
def share_formula
|
18
|
+
sharing_range.to_reference_enum.each do |shared_formula_reference|
|
19
|
+
next if shared_formula_reference == reference.to_s
|
20
|
+
share_formula_with_cell worksheet.cell(shared_formula_reference)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def share_formula_with_cell(cell)
|
25
|
+
return unless cell
|
26
|
+
return unless cell.is_a?(SharedFormulaCell)
|
27
|
+
cell.shared_formula = self.ast
|
28
|
+
cell.shared_formula_offset = offset_from(cell)
|
29
|
+
end
|
30
|
+
|
31
|
+
def offset_from(cell)
|
32
|
+
cell.reference - self.reference
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
class ValueCell < Cell
|
3
|
+
|
4
|
+
def self.for(other_cell)
|
5
|
+
vc = ValueCell.new(other_cell.worksheet)
|
6
|
+
vc.reference = other_cell.reference
|
7
|
+
vc.xml_value = other_cell.xml_value
|
8
|
+
vc.xml_type = other_cell.xml_type
|
9
|
+
vc
|
10
|
+
end
|
11
|
+
|
12
|
+
def ruby_value
|
13
|
+
value
|
14
|
+
end
|
15
|
+
|
16
|
+
def can_be_replaced_with_value?
|
17
|
+
true
|
18
|
+
end
|
19
|
+
|
20
|
+
def to_test( r = RubySpecWriter.new)
|
21
|
+
nil # i.e., don't bother with tests for simple_values
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
class Relationships < Hash
|
3
|
+
|
4
|
+
attr_reader :shared_strings
|
5
|
+
|
6
|
+
def self.for_file(filename)
|
7
|
+
root_directory = File.dirname(filename)
|
8
|
+
relationships_xml_file = File.join(root_directory,'_rels',"#{File.basename(filename)}.rels")
|
9
|
+
return Relationships.new unless File.exist?(relationships_xml_file)
|
10
|
+
xml = File.open(relationships_xml_file) { |f| Nokogiri::XML(f) }
|
11
|
+
Relationships.new(xml,root_directory)
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(xml = nil, root_directory = nil)
|
15
|
+
return unless xml
|
16
|
+
xml.css("Relationship").each do |relationship|
|
17
|
+
filename = root_directory ? File.expand_path(File.join(root_directory,relationship['Target'])) : relationship['Target']
|
18
|
+
self[relationship['Id']] = filename
|
19
|
+
@shared_strings = filename if relationship['Type'] == "http://schemas.openxmlformats.org/officeDocument/2006/relationships/sharedStrings"
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# FIXME: This is obviously bad programming. What if we multithread?!
|
2
|
+
module RubyFromExcel
|
3
|
+
class SharedStrings < Array
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
def self.shared_string_for(index)
|
7
|
+
self.instance.shared_string_for(index)
|
8
|
+
end
|
9
|
+
|
10
|
+
def load_strings_from_xml(xml)
|
11
|
+
xml.css("si").each do |si|
|
12
|
+
push si.css("t").map(&:content).join
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def shared_string_for(index)
|
17
|
+
at(index.to_i)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,116 @@
|
|
1
|
+
module RubyFromExcel
|
2
|
+
|
3
|
+
class TableNotFoundException < Exception
|
4
|
+
end
|
5
|
+
|
6
|
+
class Table
|
7
|
+
|
8
|
+
def self.reference_for(table_name,structured_reference,cell_making_the_reference = nil)
|
9
|
+
return ":ref" unless tables.include?(table_name)
|
10
|
+
tables[table_name].reference_for(structured_reference,cell_making_the_reference)
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.reference_for_local_reference(cell,structured_reference)
|
14
|
+
table = tables.find { |n,t| t.include?(cell) }
|
15
|
+
return ":ref" unless table
|
16
|
+
table.last.reference_for(structured_reference,cell.reference)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.tables
|
20
|
+
@@tables ||= {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.add(table)
|
24
|
+
tables[table.name] = table
|
25
|
+
end
|
26
|
+
|
27
|
+
attr_reader :worksheet, :name, :reference, :column_name_array, :number_of_total_rows, :all, :data, :headers, :totals, :column_names
|
28
|
+
|
29
|
+
def self.from_xml(worksheet,xml)
|
30
|
+
Table.new(worksheet,xml['name'],xml['ref'],xml.css('tableColumn').map {|c| c['name']}.to_a,xml['totalsRowCount'])
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(worksheet,name,reference,column_name_array,number_of_total_rows)
|
34
|
+
@worksheet = worksheet
|
35
|
+
@name = name
|
36
|
+
@reference = reference
|
37
|
+
@column_name_array = column_name_array
|
38
|
+
@number_of_total_rows = number_of_total_rows
|
39
|
+
@all = Area.new(worksheet,*reference.split(':'))
|
40
|
+
index_of_first_total_row = -number_of_total_rows.to_i
|
41
|
+
@data = @all.rows(1,index_of_first_total_row - 1)
|
42
|
+
@headers = @all.row(0)
|
43
|
+
@totals = @all.rows(index_of_first_total_row,-1)
|
44
|
+
@column_names = {}
|
45
|
+
column_name_array.each_with_index do |name,index|
|
46
|
+
@column_names[name.strip] = index # column['id'].to_i
|
47
|
+
end
|
48
|
+
Table.add(self)
|
49
|
+
end
|
50
|
+
|
51
|
+
def column(name)
|
52
|
+
name = $1 if name.to_s =~ /^(\d+)\.0+$/
|
53
|
+
return :na unless column = column_names[name]
|
54
|
+
data.column(column)
|
55
|
+
end
|
56
|
+
|
57
|
+
def reference_for(structured_reference,cell_making_the_reference = nil)
|
58
|
+
structured_reference.strip!
|
59
|
+
return this_row(cell_making_the_reference) if structured_reference == '#This Row'
|
60
|
+
if structured_reference =~ /\[(.*?)\],\[(.*?)\]/
|
61
|
+
return this_row_intersection(cell_making_the_reference,area_for_simple_reference($2)) if $1 == '#This Row'
|
62
|
+
return all.column(column_names[$2]) if $1 == '#All'
|
63
|
+
return intersection(area_for_simple_reference($1),area_for_simple_reference($2))
|
64
|
+
end
|
65
|
+
if cell_making_the_reference
|
66
|
+
if cell_making_the_reference.worksheet == self.worksheet
|
67
|
+
if data.include?(cell_making_the_reference)
|
68
|
+
case structured_reference
|
69
|
+
when /#totals/i, /#headers/i
|
70
|
+
return this_column_intersection(cell_making_the_reference,area_for_simple_reference(structured_reference))
|
71
|
+
when /^#/i
|
72
|
+
return area_for_simple_reference(structured_reference)
|
73
|
+
else
|
74
|
+
return this_row_intersection(cell_making_the_reference,area_for_simple_reference(structured_reference))
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
return area_for_simple_reference(structured_reference)
|
80
|
+
end
|
81
|
+
|
82
|
+
def inspect
|
83
|
+
%Q{'Table.new(#{worksheet},#{name.inspect},#{reference.inspect},#{column_name_array.inspect},#{number_of_total_rows})'}
|
84
|
+
end
|
85
|
+
|
86
|
+
def include?(cell)
|
87
|
+
@all.include_cell?(cell)
|
88
|
+
end
|
89
|
+
|
90
|
+
private
|
91
|
+
|
92
|
+
def this_row(cell_making_the_reference)
|
93
|
+
data.row(cell_making_the_reference.row_number - data.start_cell.row_number)
|
94
|
+
end
|
95
|
+
|
96
|
+
def this_row_intersection(cell_making_the_reference,column_area)
|
97
|
+
"#{worksheet}.#{Reference.ruby_for(column_area.start_cell.column_number,cell_making_the_reference.row_number)}"
|
98
|
+
end
|
99
|
+
|
100
|
+
def this_column_intersection(cell_making_the_reference,row_area)
|
101
|
+
"#{worksheet}.#{Reference.ruby_for(cell_making_the_reference.column_number,row_area.start_cell.row_number)}"
|
102
|
+
end
|
103
|
+
|
104
|
+
def intersection(row_area,colum_area)
|
105
|
+
row_area, colum_area = colum_area, row_area unless row_area.single_row?
|
106
|
+
"#{worksheet}.#{Reference.ruby_for(colum_area.start_cell.column_number,row_area.start_cell.row_number)}"
|
107
|
+
end
|
108
|
+
|
109
|
+
def area_for_simple_reference(structured_reference)
|
110
|
+
structured_reference.strip!
|
111
|
+
return self.send(structured_reference.downcase[1..-1]) if structured_reference.start_with?('#')
|
112
|
+
column(structured_reference)
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
end
|