rubyXL 2.1.1 → 2.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/rubyXL.rb +1 -0
- data/lib/rubyXL/objects/border.rb +3 -4
- data/lib/rubyXL/objects/calculation_chain.rb +1 -1
- data/lib/rubyXL/objects/cell_style.rb +3 -4
- data/lib/rubyXL/objects/chartsheet.rb +78 -0
- data/lib/rubyXL/objects/container_nodes.rb +2 -3
- data/lib/rubyXL/objects/data_validation.rb +5 -10
- data/lib/rubyXL/objects/document_properties.rb +1 -1
- data/lib/rubyXL/objects/fill.rb +3 -6
- data/lib/rubyXL/objects/filters.rb +120 -0
- data/lib/rubyXL/objects/formula.rb +2 -2
- data/lib/rubyXL/objects/ooxml_object.rb +116 -56
- data/lib/rubyXL/objects/relationships.rb +5 -1
- data/lib/rubyXL/objects/shared_strings.rb +1 -1
- data/lib/rubyXL/objects/sheet_common.rb +50 -0
- data/lib/rubyXL/objects/sheet_data.rb +6 -1
- data/lib/rubyXL/objects/simple_types.rb +78 -0
- data/lib/rubyXL/objects/stylesheet.rb +15 -3
- data/lib/rubyXL/objects/text.rb +4 -5
- data/lib/rubyXL/objects/workbook.rb +151 -26
- data/lib/rubyXL/objects/worksheet.rb +329 -107
- data/lib/rubyXL/parser.rb +12 -11
- data/lib/rubyXL/workbook.rb +3 -2
- data/rdoc/README_rdoc.html +404 -0
- data/rdoc/RubyXL.html +337 -0
- data/rdoc/RubyXL/AExtensionStorageArea.html +105 -0
- data/rdoc/RubyXL/Alignment.html +108 -0
- data/rdoc/RubyXL/AlternateContent.html +105 -0
- data/rdoc/RubyXL/AutoFilter.html +105 -0
- data/rdoc/RubyXL/AutoFilterColumn.html +105 -0
- data/rdoc/RubyXL/BooleanNode.html +105 -0
- data/rdoc/RubyXL/BooleanValue.html +105 -0
- data/rdoc/RubyXL/Border.html +105 -0
- data/rdoc/RubyXL/BorderContainer.html +105 -0
- data/rdoc/RubyXL/BorderEdge.html +156 -0
- data/rdoc/RubyXL/Break.html +105 -0
- data/rdoc/RubyXL/BreakList.html +105 -0
- data/rdoc/RubyXL/CalculationChain.html +159 -0
- data/rdoc/RubyXL/CalculationChainCell.html +108 -0
- data/rdoc/RubyXL/CalculationProperties.html +105 -0
- data/rdoc/RubyXL/Cell.html +428 -0
- data/rdoc/RubyXL/CellSmartTag.html +105 -0
- data/rdoc/RubyXL/CellSmartTagContainer.html +105 -0
- data/rdoc/RubyXL/CellSmartTagProperty.html +105 -0
- data/rdoc/RubyXL/CellStyle.html +108 -0
- data/rdoc/RubyXL/CellStyleContainer.html +105 -0
- data/rdoc/RubyXL/CellStyleXFContainer.html +105 -0
- data/rdoc/RubyXL/CellValue.html +108 -0
- data/rdoc/RubyXL/CellWatch.html +105 -0
- data/rdoc/RubyXL/CellWatchContainer.html +105 -0
- data/rdoc/RubyXL/CellXFContainer.html +105 -0
- data/rdoc/RubyXL/Chartsheet.html +105 -0
- data/rdoc/RubyXL/ChartsheetPageSetup.html +105 -0
- data/rdoc/RubyXL/ChartsheetProperties.html +108 -0
- data/rdoc/RubyXL/ChartsheetProtection.html +108 -0
- data/rdoc/RubyXL/ChartsheetView.html +105 -0
- data/rdoc/RubyXL/ChartsheetViewContainer.html +105 -0
- data/rdoc/RubyXL/Color.html +163 -0
- data/rdoc/RubyXL/ColorFilter.html +105 -0
- data/rdoc/RubyXL/ColorScale.html +105 -0
- data/rdoc/RubyXL/ColorScheme.html +105 -0
- data/rdoc/RubyXL/ColorSet.html +105 -0
- data/rdoc/RubyXL/Colors.html +105 -0
- data/rdoc/RubyXL/ColumnRange.html +233 -0
- data/rdoc/RubyXL/ColumnRanges.html +275 -0
- data/rdoc/RubyXL/ConditionalFormatValue.html +105 -0
- data/rdoc/RubyXL/ConditionalFormatting.html +105 -0
- data/rdoc/RubyXL/ConditionalFormattingRule.html +105 -0
- data/rdoc/RubyXL/CustomFilter.html +105 -0
- data/rdoc/RubyXL/CustomFilterContainer.html +105 -0
- data/rdoc/RubyXL/CustomProperty.html +105 -0
- data/rdoc/RubyXL/CustomPropertyContainer.html +105 -0
- data/rdoc/RubyXL/CustomSheetView.html +105 -0
- data/rdoc/RubyXL/CustomSheetViews.html +105 -0
- data/rdoc/RubyXL/CustomWorkbookView.html +105 -0
- data/rdoc/RubyXL/CustomWorkbookViewContainer.html +105 -0
- data/rdoc/RubyXL/DXF.html +105 -0
- data/rdoc/RubyXL/DXFs.html +105 -0
- data/rdoc/RubyXL/DataBar.html +105 -0
- data/rdoc/RubyXL/DataConsolidate.html +105 -0
- data/rdoc/RubyXL/DataConsolidationReference.html +105 -0
- data/rdoc/RubyXL/DataConsolidationReferences.html +105 -0
- data/rdoc/RubyXL/DataValidation.html +108 -0
- data/rdoc/RubyXL/DataValidations.html +105 -0
- data/rdoc/RubyXL/DateGroupItem.html +108 -0
- data/rdoc/RubyXL/DefinedName.html +105 -0
- data/rdoc/RubyXL/DefinedNames.html +105 -0
- data/rdoc/RubyXL/DocumentProperties.html +271 -0
- data/rdoc/RubyXL/DynamicFilter.html +105 -0
- data/rdoc/RubyXL/EmbeddedControl.html +105 -0
- data/rdoc/RubyXL/EmbeddedControlContainer.html +105 -0
- data/rdoc/RubyXL/Extension.html +228 -0
- data/rdoc/RubyXL/ExtensionStorageArea.html +108 -0
- data/rdoc/RubyXL/ExternalReference.html +105 -0
- data/rdoc/RubyXL/ExternalReferences.html +105 -0
- data/rdoc/RubyXL/FieldItem.html +105 -0
- data/rdoc/RubyXL/FileRecoveryProperties.html +105 -0
- data/rdoc/RubyXL/FileSharing.html +108 -0
- data/rdoc/RubyXL/FileVersion.html +108 -0
- data/rdoc/RubyXL/Fill.html +105 -0
- data/rdoc/RubyXL/FillContainer.html +105 -0
- data/rdoc/RubyXL/FilterContainer.html +105 -0
- data/rdoc/RubyXL/FloatNode.html +105 -0
- data/rdoc/RubyXL/FloatValue.html +105 -0
- data/rdoc/RubyXL/Font.html +655 -0
- data/rdoc/RubyXL/FontContainer.html +105 -0
- data/rdoc/RubyXL/FontScheme.html +105 -0
- data/rdoc/RubyXL/FormatScheme.html +105 -0
- data/rdoc/RubyXL/Formula.html +108 -0
- data/rdoc/RubyXL/FunctionGroup.html +105 -0
- data/rdoc/RubyXL/FunctionGroupContainer.html +105 -0
- data/rdoc/RubyXL/GenericStorage.html +344 -0
- data/rdoc/RubyXL/GradientFill.html +105 -0
- data/rdoc/RubyXL/HeaderFooterSettings.html +105 -0
- data/rdoc/RubyXL/Hyperlink.html +105 -0
- data/rdoc/RubyXL/HyperlinkContainer.html +105 -0
- data/rdoc/RubyXL/IconFilter.html +105 -0
- data/rdoc/RubyXL/IconSet.html +105 -0
- data/rdoc/RubyXL/IgnoredError.html +105 -0
- data/rdoc/RubyXL/IgnoredErrorContainer.html +105 -0
- data/rdoc/RubyXL/IndexedColorContainer.html +105 -0
- data/rdoc/RubyXL/InputCells.html +105 -0
- data/rdoc/RubyXL/IntegerNode.html +105 -0
- data/rdoc/RubyXL/IntegerValue.html +105 -0
- data/rdoc/RubyXL/LegacyCell.html +1498 -0
- data/rdoc/RubyXL/LegacyWorkbook.html +1283 -0
- data/rdoc/RubyXL/LegacyWorksheet.html +3291 -0
- data/rdoc/RubyXL/MRUColorContainer.html +105 -0
- data/rdoc/RubyXL/MergedCell.html +105 -0
- data/rdoc/RubyXL/MergedCells.html +105 -0
- data/rdoc/RubyXL/NumFmt.html +105 -0
- data/rdoc/RubyXL/NumberFormat.html +160 -0
- data/rdoc/RubyXL/NumberFormatContainer.html +173 -0
- data/rdoc/RubyXL/OLEObject.html +105 -0
- data/rdoc/RubyXL/OLEObjects.html +105 -0
- data/rdoc/RubyXL/OLESize.html +105 -0
- data/rdoc/RubyXL/OOXMLObject.html +862 -0
- data/rdoc/RubyXL/OOXMLTopLevelObject.html +105 -0
- data/rdoc/RubyXL/OutlineProperties.html +108 -0
- data/rdoc/RubyXL/PageMargins.html +105 -0
- data/rdoc/RubyXL/PageSetup.html +105 -0
- data/rdoc/RubyXL/PageSetupProperties.html +108 -0
- data/rdoc/RubyXL/Pane.html +105 -0
- data/rdoc/RubyXL/Parser.html +348 -0
- data/rdoc/RubyXL/PatternFill.html +105 -0
- data/rdoc/RubyXL/PhoneticProperties.html +105 -0
- data/rdoc/RubyXL/PhoneticRun.html +105 -0
- data/rdoc/RubyXL/PivotArea.html +105 -0
- data/rdoc/RubyXL/PivotCache.html +105 -0
- data/rdoc/RubyXL/PivotCaches.html +105 -0
- data/rdoc/RubyXL/PivotReference.html +105 -0
- data/rdoc/RubyXL/PivotReferenceContainer.html +105 -0
- data/rdoc/RubyXL/PivotTableSelection.html +105 -0
- data/rdoc/RubyXL/PrintOptions.html +105 -0
- data/rdoc/RubyXL/ProtectedRange.html +105 -0
- data/rdoc/RubyXL/ProtectedRanges.html +105 -0
- data/rdoc/RubyXL/Protection.html +105 -0
- data/rdoc/RubyXL/RID.html +105 -0
- data/rdoc/RubyXL/RawOOXML.html +225 -0
- data/rdoc/RubyXL/Reference.html +642 -0
- data/rdoc/RubyXL/Relationship.html +105 -0
- data/rdoc/RubyXL/RichText.html +105 -0
- data/rdoc/RubyXL/RichTextRun.html +105 -0
- data/rdoc/RubyXL/Row.html +105 -0
- data/rdoc/RubyXL/RunProperties.html +108 -0
- data/rdoc/RubyXL/Scenario.html +105 -0
- data/rdoc/RubyXL/ScenarioContainer.html +105 -0
- data/rdoc/RubyXL/Selection.html +105 -0
- data/rdoc/RubyXL/SharedStringsTable.html +397 -0
- data/rdoc/RubyXL/Sheet.html +105 -0
- data/rdoc/RubyXL/SheetCalculationProperties.html +105 -0
- data/rdoc/RubyXL/SheetData.html +105 -0
- data/rdoc/RubyXL/Sheets.html +105 -0
- data/rdoc/RubyXL/SmartTagContainer.html +105 -0
- data/rdoc/RubyXL/SmartTagProperties.html +105 -0
- data/rdoc/RubyXL/SmartTagType.html +105 -0
- data/rdoc/RubyXL/SmartTagTypeContainer.html +105 -0
- data/rdoc/RubyXL/SortCondition.html +105 -0
- data/rdoc/RubyXL/SortState.html +105 -0
- data/rdoc/RubyXL/Sqref.html +199 -0
- data/rdoc/RubyXL/Stop.html +108 -0
- data/rdoc/RubyXL/StringNode.html +105 -0
- data/rdoc/RubyXL/StringValue.html +105 -0
- data/rdoc/RubyXL/Stylesheet.html +105 -0
- data/rdoc/RubyXL/TableParts.html +105 -0
- data/rdoc/RubyXL/TableStyle.html +105 -0
- data/rdoc/RubyXL/TableStyles.html +105 -0
- data/rdoc/RubyXL/Text.html +195 -0
- data/rdoc/RubyXL/Theme.html +105 -0
- data/rdoc/RubyXL/ThemeElements.html +105 -0
- data/rdoc/RubyXL/Top10.html +105 -0
- data/rdoc/RubyXL/Variant.html +108 -0
- data/rdoc/RubyXL/Vector.html +105 -0
- data/rdoc/RubyXL/VectorValue.html +105 -0
- data/rdoc/RubyXL/WebPublishObject.html +105 -0
- data/rdoc/RubyXL/WebPublishObjectContainer.html +105 -0
- data/rdoc/RubyXL/WebPublishingItem.html +108 -0
- data/rdoc/RubyXL/WebPublishingItemContainer.html +105 -0
- data/rdoc/RubyXL/WebPublishingProperties.html +105 -0
- data/rdoc/RubyXL/Workbook.html +105 -0
- data/rdoc/RubyXL/WorkbookProperties.html +108 -0
- data/rdoc/RubyXL/WorkbookProtection.html +105 -0
- data/rdoc/RubyXL/WorkbookRelationships.html +316 -0
- data/rdoc/RubyXL/WorkbookView.html +105 -0
- data/rdoc/RubyXL/WorkbookViews.html +105 -0
- data/rdoc/RubyXL/Worksheet.html +105 -0
- data/rdoc/RubyXL/WorksheetDimensions.html +105 -0
- data/rdoc/RubyXL/WorksheetFormatProperties.html +105 -0
- data/rdoc/RubyXL/WorksheetProperties.html +108 -0
- data/rdoc/RubyXL/WorksheetProtection.html +105 -0
- data/rdoc/RubyXL/WorksheetView.html +105 -0
- data/rdoc/RubyXL/WorksheetViews.html +105 -0
- data/rdoc/RubyXL/Writer.html +98 -0
- data/rdoc/RubyXL/Writer/ContentTypesWriter.html +289 -0
- data/rdoc/RubyXL/Writer/CoreWriter.html +210 -0
- data/rdoc/RubyXL/Writer/GenericWriter.html +348 -0
- data/rdoc/RubyXL/Writer/RootRelsWriter.html +193 -0
- data/rdoc/RubyXL/Writer/StylesWriter.html +191 -0
- data/rdoc/RubyXL/Writer/ThemeWriter.html +511 -0
- data/rdoc/RubyXL/Writer/WorkbookWriter.html +249 -0
- data/rdoc/RubyXL/Writer/WorksheetWriter.html +236 -0
- data/rdoc/RubyXL/XF.html +105 -0
- data/rdoc/created.rid +24 -21
- data/rdoc/index.html +216 -0
- data/rdoc/js/search_index.js +1 -1
- data/rdoc/table_of_contents.html +1496 -0
- data/rubyXL.gemspec +211 -4
- data/spec/lib/parser_spec.rb +18 -6
- data/test/input/.gitkeep +0 -0
- data/test/output/.gitkeep +0 -0
- data/test/test_parse_write.rb +15 -0
- metadata +211 -4
- data/lib/rubyXL/objects/sheet_view.rb +0 -71
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.
|
1
|
+
2.2.0
|
data/lib/rubyXL.rb
CHANGED
@@ -6,6 +6,7 @@ require 'rubyXL/objects/column_range'
|
|
6
6
|
require 'rubyXL/objects/stylesheet'
|
7
7
|
require 'rubyXL/objects/shared_strings'
|
8
8
|
require 'rubyXL/objects/worksheet'
|
9
|
+
require 'rubyXL/objects/chartsheet'
|
9
10
|
require 'rubyXL/objects/calculation_chain'
|
10
11
|
require 'rubyXL/objects/workbook'
|
11
12
|
require 'rubyXL/objects/document_properties'
|
@@ -1,12 +1,11 @@
|
|
1
1
|
require 'rubyXL/objects/ooxml_object'
|
2
|
+
require 'rubyXL/objects/simple_types'
|
2
3
|
|
3
4
|
module RubyXL
|
4
5
|
|
5
6
|
class BorderEdge < OOXMLObject
|
6
|
-
define_attribute(:style,
|
7
|
-
define_child_node(RubyXL::Color
|
8
|
-
%w{ none thin medium dashed dotted thick double hair
|
9
|
-
mediumDashed dashDot mediumDashDot dashDotDot slantDashDot } )
|
7
|
+
define_attribute(:style, RubyXL::ST_BorderStyle, :default => 'none')
|
8
|
+
define_child_node(RubyXL::Color)
|
10
9
|
|
11
10
|
def ==(other)
|
12
11
|
style == other.style
|
@@ -14,7 +14,7 @@ module RubyXL
|
|
14
14
|
end
|
15
15
|
|
16
16
|
# http://www.schemacentral.com/sc/ooxml/e-ssml_calcChain.html
|
17
|
-
class CalculationChain <
|
17
|
+
class CalculationChain < OOXMLTopLevelObject
|
18
18
|
define_child_node(RubyXL::CalculationChainCell, :collection => true, :accessor => :cells)
|
19
19
|
define_child_node(RubyXL::ExtensionStorageArea)
|
20
20
|
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubyXL/objects/ooxml_object'
|
2
|
+
require 'rubyXL/objects/simple_types'
|
2
3
|
|
3
4
|
module RubyXL
|
4
5
|
|
@@ -15,10 +16,8 @@ module RubyXL
|
|
15
16
|
|
16
17
|
# http://www.schemacentral.com/sc/ooxml/e-ssml_alignment-1.html
|
17
18
|
class Alignment < OOXMLObject
|
18
|
-
define_attribute(:horizontal,
|
19
|
-
|
20
|
-
define_attribute(:vertical, :string,
|
21
|
-
:values => %w{top center bottom justify distributed})
|
19
|
+
define_attribute(:horizontal, RubyXL::ST_HorizontalAlignment)
|
20
|
+
define_attribute(:vertical, RubyXL::ST_VerticalAlignment)
|
22
21
|
define_attribute(:textRotation, :int)
|
23
22
|
define_attribute(:wrapText, :bool)
|
24
23
|
define_attribute(:indent, :int)
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'rubyXL/objects/ooxml_object'
|
2
|
+
require 'rubyXL/objects/simple_types'
|
3
|
+
require 'rubyXL/objects/extensions'
|
4
|
+
require 'rubyXL/objects/relationships'
|
5
|
+
require 'rubyXL/objects/sheet_common'
|
6
|
+
|
7
|
+
module RubyXL
|
8
|
+
|
9
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_sheetProtection-4.html
|
10
|
+
class ChartsheetProtection < OOXMLObject
|
11
|
+
define_attribute(:password, :string)
|
12
|
+
define_attribute(:content, :bool, :default => false)
|
13
|
+
define_attribute(:objects, :bool, :default => false)
|
14
|
+
define_element_name 'sheetProtection'
|
15
|
+
end
|
16
|
+
|
17
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_sheetPr-4.html
|
18
|
+
class ChartsheetProperties < OOXMLObject
|
19
|
+
define_attribute(:published, :bool, :default => true)
|
20
|
+
define_attribute(:codeName, :string)
|
21
|
+
define_child_node(RubyXL::Color, :node_name => :tabColor)
|
22
|
+
define_element_name 'sheetPr'
|
23
|
+
end
|
24
|
+
|
25
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_pageSetup-5.html
|
26
|
+
class ChartsheetPageSetup < OOXMLObject
|
27
|
+
define_attribute(:paperSize, :int, :default => 1)
|
28
|
+
define_attribute(:firstPageNumber, :int, :default => 1)
|
29
|
+
define_attribute(:orientation, RubyXL::ST_Orientation, :default => 'default')
|
30
|
+
define_attribute(:usePrinterDefaults, :bool, :default => true)
|
31
|
+
define_attribute(:blackAndWhite, :bool, :default => false)
|
32
|
+
define_attribute(:draft, :bool, :default => false)
|
33
|
+
define_attribute(:useFirstPageNumber, :bool, :default => false)
|
34
|
+
define_attribute(:horizontalDpi, :int, :default => 600)
|
35
|
+
define_attribute(:verticalDpi, :int, :default => 600)
|
36
|
+
define_attribute(:copies, :int, :default => 1)
|
37
|
+
define_attribute(:'r:id', :string)
|
38
|
+
define_element_name 'pageSetup'
|
39
|
+
end
|
40
|
+
|
41
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_sheetView-2.html
|
42
|
+
class ChartsheetView < OOXMLObject
|
43
|
+
define_attribute(:tabSelected, :bool, :default => false)
|
44
|
+
define_attribute(:zoomScale, :int, :default => 100)
|
45
|
+
define_attribute(:workbookViewId, :int, :required => true, :default => 0 )
|
46
|
+
define_attribute(:zoomToFit, :bool, :default => false)
|
47
|
+
define_child_node(RubyXL::ExtensionStorageArea)
|
48
|
+
define_element_name 'sheetView'
|
49
|
+
end
|
50
|
+
|
51
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_sheetViews-4.html
|
52
|
+
class ChartsheetViewContainer < OOXMLObject
|
53
|
+
define_child_node(RubyXL::ChartsheetView, :collection => true, :accessor => :sheet_views)
|
54
|
+
define_child_node(RubyXL::ExtensionStorageArea)
|
55
|
+
define_element_name 'sheetViews'
|
56
|
+
end
|
57
|
+
|
58
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_chartsheet.html
|
59
|
+
class Chartsheet < OOXMLTopLevelObject
|
60
|
+
define_child_node(RubyXL::ChartsheetProperties)
|
61
|
+
define_child_node(RubyXL::ChartsheetViewContainer, :accessor => :sheet_view_container)
|
62
|
+
define_child_node(RubyXL::ChartsheetProtection)
|
63
|
+
define_child_node(RubyXL::CustomSheetViews, :accessor => :custom_sheet_view_container)
|
64
|
+
define_child_node(RubyXL::PageMargins)
|
65
|
+
define_child_node(RubyXL::ChartsheetPageSetup)
|
66
|
+
define_child_node(RubyXL::HeaderFooterSettings)
|
67
|
+
define_child_node(RubyXL::RID, :node_name => :drawing)
|
68
|
+
define_child_node(RubyXL::RID, :node_name => :legacyDrawing)
|
69
|
+
define_child_node(RubyXL::RID, :node_name => :legacyDrawingHF)
|
70
|
+
define_child_node(RubyXL::RID, :node_name => :picture)
|
71
|
+
define_child_node(RubyXL::WebPublishingItemContainer, :accessor => :web_items_container)
|
72
|
+
define_child_node(RubyXL::ExtensionStorageArea)
|
73
|
+
define_element_name 'chartsheet'
|
74
|
+
set_namespaces('xmlns' => 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
|
75
|
+
'xmlns:r' => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships')
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubyXL/objects/ooxml_object'
|
2
|
+
require 'rubyXL/objects/simple_types'
|
2
3
|
|
3
4
|
module RubyXL
|
4
5
|
|
@@ -78,9 +79,7 @@ module RubyXL
|
|
78
79
|
|
79
80
|
# http://www.schemacentral.com/sc/ooxml/e-docPropsVTypes_vector.html
|
80
81
|
class Vector < OOXMLObject
|
81
|
-
define_attribute(:baseType,
|
82
|
-
%w{ variant i1 i2 i4 i8 ui1 ui2 ui4 ui8 r4 r8
|
83
|
-
lpstr lpwstr bstr date filetime bool cy error clsid cf })
|
82
|
+
define_attribute(:baseType, RubyXL::ST_VectorBaseType, :required => true)
|
84
83
|
define_attribute(:size, :int, :required => true)
|
85
84
|
define_child_node(RubyXL::Variant, :collection => true, :node_name => 'vt:variant')
|
86
85
|
define_child_node(RubyXL::IntegerNode, :collection => true, :node_name => 'vt:i1')
|
@@ -1,20 +1,15 @@
|
|
1
1
|
require 'rubyXL/objects/ooxml_object'
|
2
|
+
require 'rubyXL/objects/simple_types'
|
2
3
|
require 'rubyXL/objects/formula'
|
3
4
|
|
4
5
|
module RubyXL
|
5
6
|
|
6
7
|
# http://www.schemacentral.com/sc/ooxml/e-ssml_dataValidation-1.html
|
7
8
|
class DataValidation < OOXMLObject
|
8
|
-
define_attribute(:type,
|
9
|
-
|
10
|
-
define_attribute(:
|
11
|
-
|
12
|
-
define_attribute(:imeMode, :string, :default => 'noControl',
|
13
|
-
:values => %w{ noControl off on disabled hiragana fullKatakana halfKatakana
|
14
|
-
fullAlpha halfAlpha fullHangul halfHangul })
|
15
|
-
define_attribute(:operator, :string, :default => 'between',
|
16
|
-
:values => %w{ between notBetween equal notEqual lessThan lessThanOrEqual
|
17
|
-
greaterThan greaterThanOrEqual })
|
9
|
+
define_attribute(:type, RubyXL::ST_DataValidationType, :default => 'none')
|
10
|
+
define_attribute(:errorStyle, RubyXL::ST_DataValidationErrorStyle, :default => 'stop')
|
11
|
+
define_attribute(:imeMode, RubyXL::ST_DataValidationImeMode, :default => 'noControl')
|
12
|
+
define_attribute(:operator, RubyXL::ST_DataValidationOperator, :default => 'between')
|
18
13
|
define_attribute(:allowBlank, :bool, :default => false)
|
19
14
|
define_attribute(:showDropDown, :bool, :default => false)
|
20
15
|
define_attribute(:showInputMessage, :bool, :default => false)
|
@@ -4,7 +4,7 @@ require 'rubyXL/objects/container_nodes'
|
|
4
4
|
module RubyXL
|
5
5
|
|
6
6
|
# http://www.schemacentral.com/sc/ooxml/e-extended-properties_Properties.html
|
7
|
-
class DocumentProperties <
|
7
|
+
class DocumentProperties < OOXMLTopLevelObject
|
8
8
|
attr_accessor :workbook
|
9
9
|
|
10
10
|
define_child_node(RubyXL::StringNode, :node_name => :Template)
|
data/lib/rubyXL/objects/fill.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rubyXL/objects/ooxml_object'
|
2
|
+
require 'rubyXL/objects/simple_types'
|
2
3
|
|
3
4
|
module RubyXL
|
4
5
|
|
@@ -11,11 +12,7 @@ module RubyXL
|
|
11
12
|
|
12
13
|
# http://www.schemacentral.com/sc/ooxml/e-ssml_patternFill-1.html
|
13
14
|
class PatternFill < OOXMLObject
|
14
|
-
define_attribute(:patternType,
|
15
|
-
%w{ none solid mediumGray darkGray lightGray
|
16
|
-
darkHorizontal darkVertical darkDown darkUp darkGrid darkTrellis
|
17
|
-
lightHorizontal lightVertical lightDown lightUp lightGrid lightTrellis
|
18
|
-
gray125 gray0625 })
|
15
|
+
define_attribute(:patternType, RubyXL::ST_PatternType)
|
19
16
|
define_child_node(RubyXL::Color, :node_name => :fgColor )
|
20
17
|
define_child_node(RubyXL::Color, :node_name => :bgColor )
|
21
18
|
define_element_name 'patternFill'
|
@@ -23,7 +20,7 @@ module RubyXL
|
|
23
20
|
|
24
21
|
# http://www.schemacentral.com/sc/ooxml/e-ssml_gradientFill-1.html
|
25
22
|
class GradientFill < OOXMLObject
|
26
|
-
define_attribute(:type,
|
23
|
+
define_attribute(:type, RubyXL::ST_GradientType, :default => 'linear')
|
27
24
|
define_attribute(:degree, :float, :default => 0)
|
28
25
|
define_attribute(:left, :float, :default => 0)
|
29
26
|
define_attribute(:right, :float, :default => 0)
|
@@ -0,0 +1,120 @@
|
|
1
|
+
require 'rubyXL/objects/ooxml_object'
|
2
|
+
require 'rubyXL/objects/simple_types'
|
3
|
+
require 'rubyXL/objects/extensions'
|
4
|
+
|
5
|
+
module RubyXL
|
6
|
+
|
7
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_dateGroupItem-1.html
|
8
|
+
class DateGroupItem < OOXMLObject
|
9
|
+
define_attribute(:year, :int, :required => true)
|
10
|
+
define_attribute(:month, :int)
|
11
|
+
define_attribute(:day, :int)
|
12
|
+
define_attribute(:hour, :int)
|
13
|
+
define_attribute(:minute, :int)
|
14
|
+
define_attribute(:second, :int)
|
15
|
+
define_attribute(:dateTimeGrouping, RubyXL::ST_DateTimeGrouping)
|
16
|
+
define_element_name 'dateGroupItem'
|
17
|
+
end
|
18
|
+
|
19
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_filters-1.html
|
20
|
+
class FilterContainer < OOXMLObject
|
21
|
+
define_attribute(:blank, :bool, :default => false)
|
22
|
+
define_attribute(:calendarType, RubyXL::ST_CalendarType, :default => 'none')
|
23
|
+
define_child_node(RubyXL::StringValue, :node_name => :filter, :collection => true, :accessor => :filters)
|
24
|
+
define_child_node(RubyXL::DateGroupItem, :collection => true, :accessor => :date_group_items)
|
25
|
+
define_element_name 'filters'
|
26
|
+
end
|
27
|
+
|
28
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_top10-1.html
|
29
|
+
class Top10 < OOXMLObject
|
30
|
+
define_attribute(:top, :bool, :default => true)
|
31
|
+
define_attribute(:percent, :bool, :default => false)
|
32
|
+
define_attribute(:val, :float, :required => true)
|
33
|
+
define_attribute(:filterVal, :float)
|
34
|
+
define_element_name 'top10'
|
35
|
+
end
|
36
|
+
|
37
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_customFilter-1.html
|
38
|
+
class CustomFilter < OOXMLObject
|
39
|
+
define_attribute(:operator, RubyXL::ST_FilterOperator, :default => 'equal')
|
40
|
+
define_attribute(:val, :string)
|
41
|
+
define_element_name 'customFilter'
|
42
|
+
end
|
43
|
+
|
44
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_customFilters-1.html
|
45
|
+
class CustomFilterContainer < OOXMLObject
|
46
|
+
define_attribute(:and, :bool, :default => false)
|
47
|
+
define_child_node(RubyXL::CustomFilter, :collection => true, :accessor => :custom_filters)
|
48
|
+
define_element_name 'customFilters'
|
49
|
+
end
|
50
|
+
|
51
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_dynamicFilter-1.html
|
52
|
+
class DynamicFilter < OOXMLObject
|
53
|
+
define_attribute(:type, RubyXL::ST_DynamicFilterType, :required => true)
|
54
|
+
define_attribute(:val, :float)
|
55
|
+
define_attribute(:maxVal, :float)
|
56
|
+
define_element_name 'dynamicFilter'
|
57
|
+
end
|
58
|
+
|
59
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_colorFilter-1.html
|
60
|
+
class ColorFilter < OOXMLObject
|
61
|
+
define_attribute(:dxfId, :string)
|
62
|
+
define_attribute(:cellColor, :bool)
|
63
|
+
define_element_name 'colorFilter'
|
64
|
+
end
|
65
|
+
|
66
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_iconFilter-1.html
|
67
|
+
class IconFilter < OOXMLObject
|
68
|
+
define_attribute(:iconSet, RubyXL::ST_IconSetType)
|
69
|
+
define_attribute(:iconId, :int)
|
70
|
+
define_element_name 'iconFilter'
|
71
|
+
end
|
72
|
+
|
73
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_filterColumn-1.html
|
74
|
+
class AutoFilterColumn < OOXMLObject
|
75
|
+
define_attribute(:colId, :int, :required => true)
|
76
|
+
define_attribute(:hiddenButton, :bool, :default => false)
|
77
|
+
define_attribute(:showButton, :bool, :default => true)
|
78
|
+
define_child_node(RubyXL::FilterContainer)
|
79
|
+
define_child_node(RubyXL::Top10)
|
80
|
+
define_child_node(RubyXL::CustomFilterContainer, :accessor => :custom_filter_container)
|
81
|
+
define_child_node(RubyXL::DynamicFilter)
|
82
|
+
define_child_node(RubyXL::ColorFilter)
|
83
|
+
define_child_node(RubyXL::IconFilter)
|
84
|
+
define_child_node(RubyXL::ExtensionStorageArea)
|
85
|
+
define_element_name 'filterColumn'
|
86
|
+
end
|
87
|
+
|
88
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_sortCondition-1.html
|
89
|
+
class SortCondition < OOXMLObject
|
90
|
+
define_attribute(:descending, :bool, :default => false)
|
91
|
+
define_attribute(:sortBy, RubyXL::ST_SortBy, :default => 'value')
|
92
|
+
define_attribute(:ref, :ref, :required => true)
|
93
|
+
define_attribute(:customList, :string)
|
94
|
+
define_attribute(:dxfId, :int)
|
95
|
+
define_attribute(:iconSet, RubyXL::ST_IconSetType, :required => true, :default => '3Arrows')
|
96
|
+
define_attribute(:iconId, :int)
|
97
|
+
define_element_name 'sortCondition'
|
98
|
+
end
|
99
|
+
|
100
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_sortState-2.html
|
101
|
+
class SortState < OOXMLObject
|
102
|
+
define_attribute(:columnSort, :bool, :default => false)
|
103
|
+
define_attribute(:caseSensitive, :bool, :default => false)
|
104
|
+
define_attribute(:sortMethod, RubyXL::ST_SortMethod, :default => 'none')
|
105
|
+
define_attribute(:ref, :ref, :required => true)
|
106
|
+
define_child_node(RubyXL::SortCondition, :colection => true)
|
107
|
+
define_child_node(RubyXL::ExtensionStorageArea)
|
108
|
+
define_element_name 'sortState'
|
109
|
+
end
|
110
|
+
|
111
|
+
# http://www.schemacentral.com/sc/ooxml/e-ssml_autoFilter-2.html
|
112
|
+
class AutoFilter < OOXMLObject
|
113
|
+
define_attribute(:ref, :ref)
|
114
|
+
define_child_node(RubyXL::AutoFilterColumn)
|
115
|
+
define_child_node(RubyXL::SortState)
|
116
|
+
define_child_node(RubyXL::ExtensionStorageArea)
|
117
|
+
define_element_name 'autoFilter'
|
118
|
+
end
|
119
|
+
|
120
|
+
end
|
@@ -1,12 +1,12 @@
|
|
1
1
|
require 'rubyXL/objects/ooxml_object'
|
2
|
+
require 'rubyXL/objects/simple_types'
|
2
3
|
|
3
4
|
module RubyXL
|
4
5
|
|
5
6
|
# http://www.schemacentral.com/sc/ooxml/e-ssml_f-1.html
|
6
7
|
class Formula < OOXMLObject
|
7
8
|
define_attribute(:_, :string, :accessor => :expression)
|
8
|
-
define_attribute(:t,
|
9
|
-
%w{ normal array dataTable shared })
|
9
|
+
define_attribute(:t, RubyXL::ST_CellFormulaType, :default => 'normal')
|
10
10
|
define_attribute(:aca, :bool, :default => false)
|
11
11
|
define_attribute(:ref, :ref)
|
12
12
|
define_attribute(:dt2D, :bool, :default => false)
|
@@ -1,12 +1,9 @@
|
|
1
|
-
require 'pp'
|
2
|
-
|
3
1
|
module RubyXL
|
4
2
|
|
5
3
|
# Parent class for defining OOXML based objects (not unlike Rails' +ActiveRecord+!)
|
6
4
|
# Most importantly, provides functionality of parsing such objects from XML,
|
7
5
|
# and marshalling them to XML.
|
8
6
|
class OOXMLObject
|
9
|
-
|
10
7
|
# Get the value of a [sub]class variable if it exists, or create the respective variable
|
11
8
|
# with the passed-in +default+ (or +{}+, if not specified)
|
12
9
|
#
|
@@ -30,46 +27,73 @@ module RubyXL
|
|
30
27
|
|
31
28
|
# Defines an attribute of OOXML object.
|
32
29
|
# === Parameters
|
33
|
-
# * +attribute_name+ - Name of the element attribute as seen in the source XML. Can be either "String" or
|
34
|
-
# * Special attibute name '_' (underscore) denotes the value of the element rather than attribute.
|
30
|
+
# * +attribute_name+ - Name of the element attribute as seen in the source XML. Can be either <tt>"String"</tt> or <tt>:Symbol</tt>
|
31
|
+
# * Special attibute name <tt>'_'</tt> (underscore) denotes the value of the element rather than attribute.
|
35
32
|
# * +attribute_type+ - Specifies the conversion type for the attribute when parsing. Available options are:
|
36
|
-
# *
|
37
|
-
# *
|
38
|
-
# *
|
39
|
-
# *
|
40
|
-
# *
|
41
|
-
# *
|
33
|
+
# * +:int+ - <tt>Integer</tt>
|
34
|
+
# * +:float+ - <tt>Float</tt>
|
35
|
+
# * +:string+ - <tt>String</tt> (no conversion)
|
36
|
+
# * +:sqref+ - RubyXL::Sqref
|
37
|
+
# * +:ref+ - RubyXL::Reference
|
38
|
+
# * +:bool+ - <tt>Boolean</tt> ("1" and "true" convert to +true+, others to +false+)
|
39
|
+
# * one of +simple_types+ - <tt>String</tt>, plus the list of acceptable values is saved for future validation (not used yet).
|
42
40
|
# * +extra_parameters+ - Hash of optional parameters as follows:
|
43
|
-
# *
|
44
|
-
# *
|
45
|
-
# *
|
46
|
-
# * :values - List of acceptable values for this attribute (curently not used).
|
41
|
+
# * +:accessor+ - Name of the accessor for this attribute to be defined on the object. If not provided, defaults to classidied +attribute_name+.
|
42
|
+
# * +:default+ - Value this attribute defaults to if not explicitly provided.
|
43
|
+
# * +:required+ - Whether this attribute is required when writing XML. If the value of the attrinute is not explicitly provided, +:default+ is written instead.
|
47
44
|
# ==== Examples
|
48
45
|
# define_attribute(:outline, :bool, :default => true)
|
49
|
-
# A Boolean attribute 'outline' with default value +true+ will be accessible by calling +obj.outline+
|
46
|
+
# A <tt>Boolean</tt> attribute 'outline' with default value +true+ will be accessible by calling +obj.outline+
|
50
47
|
# define_attribute(:uniqueCount, :int)
|
51
|
-
# An Integer attribute 'uniqueCount' accessible as +obj.unique_count+
|
48
|
+
# An <tt>Integer</tt> attribute 'uniqueCount' accessible as +obj.unique_count+
|
52
49
|
# define_attribute(:_, :string, :accessor => :expression)
|
53
|
-
# The value of the element will be accessible as a String by calling +obj.expression+
|
50
|
+
# The value of the element will be accessible as a <tt>String</tt> by calling +obj.expression+
|
54
51
|
# define_attribute(:errorStyle, :string, :default => 'stop', :values => %w{ stop warning information })
|
55
|
-
# A String attribute named 'errorStyle' will be accessible as +obj.error_style+, valid values are "stop"
|
52
|
+
# A <tt>String</tt> attribute named 'errorStyle' will be accessible as +obj.error_style+, valid values are <tt>"stop"</tt>, <tt>"warning"</tt>, <tt>"information"</tt>
|
56
53
|
def self.define_attribute(attr_name, attr_type, extra_params = {})
|
57
54
|
attrs = obtain_class_variable(:@@ooxml_attributes)
|
58
55
|
|
59
56
|
accessor = extra_params[:accessor] || accessorize(attr_name)
|
60
57
|
attr_name = attr_name.to_s
|
61
58
|
|
62
|
-
|
59
|
+
attr_hash = {
|
63
60
|
:accessor => accessor,
|
64
61
|
:attr_type => attr_type,
|
65
62
|
:optional => !extra_params[:required],
|
66
63
|
:default => extra_params[:default],
|
67
|
-
:valies => extra_params[:values]
|
68
64
|
}
|
69
65
|
|
66
|
+
if attr_type.is_a?(Array) then
|
67
|
+
attr_hash[:values] = attr_type
|
68
|
+
attr_hash[:attr_type] = :string
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
attrs[attr_name] = attr_hash
|
73
|
+
|
70
74
|
self.send(:attr_accessor, accessor)
|
71
75
|
end
|
72
76
|
|
77
|
+
# Defines a child node of OOXML object.
|
78
|
+
# === Parameters
|
79
|
+
# * +klass+ - Class (descendant of RubyXL::OOXMLObject) of the child nodes. Child node objects will be produced by calling +parse+ method of that class.
|
80
|
+
# * +extra_parameters+ - Hash of optional parameters as follows:
|
81
|
+
# * +:accessor+ - Name of the accessor for this attribute to be defined on the object. If not provided, defaults to classidied +attribute_name+.
|
82
|
+
# * +:node_name+ - Node name for the child node, in case it does not match the one defined by the +klass+.
|
83
|
+
# * +:collection+ - Whether the child node should be treated as a single node or a collection of nodes:
|
84
|
+
# * +false+ (default) - child node is directly accessible through the respective accessor;
|
85
|
+
# * +true+ - a collection of child nodes is accessed as +Array+ through the respective accessor;
|
86
|
+
# * +:with_count+ - same as +true+, but in addition, the attribute +count+ is defined on the current object, that will be automatically set to the number of elements in the collection at the start of +write_xml+ call.
|
87
|
+
# ==== Examples
|
88
|
+
# define_child_node(RubyXL::Alignment)
|
89
|
+
# Define a singular child node parsed by the RubyXL::BorderEdge.parse() and accessed by the default <tt>obj.alignment</tt> accessor
|
90
|
+
# define_child_node(RubyXL::Hyperlink, :colection => true, :accessor => :hyperlinks)
|
91
|
+
# Define an array of nodes accessed by <tt>obj.hyperlinks</tt> accessor, each of which will be parsed by the RubyXL::Hyperlink.parse()
|
92
|
+
# define_child_node(RubyXL::BorderEdge, :node_name => :left)
|
93
|
+
# define_child_node(RubyXL::BorderEdge, :node_name => :right)
|
94
|
+
# Use class RubyXL::BorderEdge when parsing both the elements <tt><left ...></tt> and <tt><right ...></tt> elements.
|
95
|
+
# define_child_node(RubyXL::Font, :collection => :with_count, :accessor => :fonts)
|
96
|
+
# Upon writing of the object this was defined on, its <tt>count</tt> attribute will be set to the count of nodes in <tt>fonts</tt> array
|
73
97
|
def self.define_child_node(klass, extra_params = {})
|
74
98
|
child_nodes = obtain_class_variable(:@@ooxml_child_nodes)
|
75
99
|
child_node_name = (extra_params[:node_name] || klass.class_variable_get(:@@ooxml_tag_name)).to_s
|
@@ -88,25 +112,33 @@ module RubyXL
|
|
88
112
|
self.send(:attr_accessor, accessor)
|
89
113
|
end
|
90
114
|
|
91
|
-
|
92
|
-
|
115
|
+
# Defines the name of the element that represents the current OOXML object. Should only be used once per object.
|
116
|
+
# In case of different objects represented by the same class in different parts of OOXML tree, +:node_name+
|
117
|
+
# extra parameter can be used to override the default element name.
|
118
|
+
# === Parameters
|
119
|
+
# * +element_name+
|
120
|
+
# ==== Examples
|
121
|
+
# define_element_name 'externalReference'
|
122
|
+
def self.define_element_name(element_name)
|
123
|
+
self.class_variable_set(:@@ooxml_tag_name, element_name)
|
93
124
|
end
|
94
125
|
|
126
|
+
# #TODO# This method will eventually be obsoleted.
|
95
127
|
def self.set_countable
|
96
128
|
self.class_variable_set(:@@ooxml_countable, true)
|
97
129
|
self.send(:attr_accessor, :count)
|
98
130
|
end
|
99
131
|
|
100
|
-
#
|
132
|
+
# Recursively write the OOXML object and all its children out as Nokogiri::XML. Immediately before the actual
|
133
|
+
# generation, +before_write_xml()+ is called to perform last-minute cleanup and validation operations; if it
|
134
|
+
# returns +false+, an empty string is returned (rather than +nil+, so Nokogiri::XML's <tt><<</tt> operator
|
135
|
+
# can be used without additional +nil+ checking)
|
101
136
|
# === Parameters
|
102
|
-
# * +
|
137
|
+
# * +xml+ - Base Nokogiri::XML object used for building. If omitted, a blank document will be generated.
|
138
|
+
# * +node_name_override+ - if present, is used instead of the default element name for this object provided by +define_element_name+
|
103
139
|
# ==== Examples
|
104
|
-
#
|
105
|
-
#
|
106
|
-
def self.set_namespaces(namespace_hash)
|
107
|
-
self.class_variable_set(:@@ooxml_namespaces, namespace_hash)
|
108
|
-
end
|
109
|
-
|
140
|
+
# obj.write_xml
|
141
|
+
# Creates a new Nokogiti::XML and
|
110
142
|
def write_xml(xml = nil, node_name_override = nil)
|
111
143
|
if xml.nil? then
|
112
144
|
seed_xml = Nokogiri::XML('<?xml version = "1.0" standalone ="yes"?>')
|
@@ -172,20 +204,6 @@ module RubyXL
|
|
172
204
|
instance_variable_set("@count", 0) if obtain_class_variable(:@@ooxml_countable, false)
|
173
205
|
end
|
174
206
|
|
175
|
-
def self.process_attribute(obj, raw_value, params)
|
176
|
-
val = raw_value &&
|
177
|
-
case params[:attr_type]
|
178
|
-
when :int then Integer(raw_value)
|
179
|
-
when :float then Float(raw_value)
|
180
|
-
when :string then raw_value
|
181
|
-
when :sqref then RubyXL::Sqref.new(raw_value)
|
182
|
-
when :ref then RubyXL::Reference.new(raw_value)
|
183
|
-
when :bool then ['1', 'true'].include?(raw_value)
|
184
|
-
end
|
185
|
-
obj.send("#{params[:accessor]}=", val)
|
186
|
-
end
|
187
|
-
private_class_method :process_attribute
|
188
|
-
|
189
207
|
def self.parse(node)
|
190
208
|
node = Nokogiri::XML.parse(node) if node.is_a?(IO) || node.is_a?(String)
|
191
209
|
|
@@ -251,6 +269,9 @@ module RubyXL
|
|
251
269
|
new_copy
|
252
270
|
end
|
253
271
|
|
272
|
+
# Prototype method. For sparse collections (+Rows+, +Cells+, etc.) must return index at which this object
|
273
|
+
# is expected to reside in the collection. If +nil+ is returned, then object is simply added
|
274
|
+
# to the end of the collection.
|
254
275
|
def index_in_collection
|
255
276
|
nil
|
256
277
|
end
|
@@ -266,30 +287,69 @@ module RubyXL
|
|
266
287
|
true
|
267
288
|
end
|
268
289
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
290
|
+
private
|
291
|
+
def self.accessorize(str)
|
292
|
+
acc = str.to_s.dup
|
293
|
+
acc.gsub!(/([A-Z\d]+)([A-Z][a-z])/,'\1_\2')
|
294
|
+
acc.gsub!(/([a-z\d])([A-Z])/,'\1_\2')
|
295
|
+
acc.gsub!(':','_')
|
296
|
+
acc.downcase.to_sym
|
273
297
|
end
|
274
298
|
|
299
|
+
def self.process_attribute(obj, raw_value, params)
|
300
|
+
val = raw_value &&
|
301
|
+
case params[:attr_type]
|
302
|
+
when :int then Integer(raw_value)
|
303
|
+
when :float then Float(raw_value)
|
304
|
+
when :string then raw_value
|
305
|
+
when :sqref then RubyXL::Sqref.new(raw_value)
|
306
|
+
when :ref then RubyXL::Reference.new(raw_value)
|
307
|
+
when :bool then ['1', 'true'].include?(raw_value)
|
308
|
+
end
|
309
|
+
obj.send("#{params[:accessor]}=", val)
|
310
|
+
end
|
311
|
+
|
312
|
+
end
|
313
|
+
|
314
|
+
# Extension class providing functionality for top-level OOXML objects that are represented by
|
315
|
+
# their own <tt>.xml</tt> files in <tt>.xslx</tt> zip container.
|
316
|
+
|
317
|
+
class OOXMLTopLevelObject < OOXMLObject
|
318
|
+
# Prototype method. For top-level OOXML object, returns the path at which the current object's XML file
|
319
|
+
# is located within the <tt>.xslx</tt> zip container.
|
275
320
|
def self.filepath
|
276
321
|
raise 'Subclass responsebility'
|
277
322
|
end
|
278
323
|
|
324
|
+
# Sets the list of namespaces on this object to be added when writing out XML. Valid only on top-level objects.
|
325
|
+
# === Parameters
|
326
|
+
# * +namespace_hash+ - Hash of namespaces in the form of <tt>"prefix" => "url"</tt>
|
327
|
+
# ==== Examples
|
328
|
+
# set_namespaces('xmlns' => 'http://schemas.openxmlformats.org/spreadsheetml/2006/main',
|
329
|
+
# 'xmlns:r' => 'http://schemas.openxmlformats.org/officeDocument/2006/relationships')
|
330
|
+
def self.set_namespaces(namespace_hash)
|
331
|
+
self.class_variable_set(:@@ooxml_namespaces, namespace_hash)
|
332
|
+
end
|
333
|
+
|
334
|
+
# Generates the top-level OOXML object by parsing its XML file from the temporary
|
335
|
+
# directory containing the unzipped contents of <tt>.xslx</tt>
|
336
|
+
# === Parameters
|
337
|
+
# * +dirpath+ - path to the directory with the unzipped <tt>.xslx</tt> contents.
|
279
338
|
def self.parse_file(dirpath)
|
280
339
|
full_path = File.join(dirpath, filepath)
|
281
340
|
return nil unless File.exist?(full_path)
|
282
341
|
parse(File.open(full_path, 'r'))
|
283
342
|
end
|
284
343
|
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
344
|
+
# Saves the contents of the object as XML to respective location in <tt>.xslx</tt> zip container.
|
345
|
+
# === Parameters
|
346
|
+
# * +zipfile+ - ::Zip::File to which the resulting XNMML should be added.
|
347
|
+
def add_to_zip(zipfile)
|
348
|
+
xml_string = write_xml
|
349
|
+
return if xml_string.empty?
|
350
|
+
zipfile.get_output_stream(self.class.filepath) { |f| f << xml_string }
|
292
351
|
end
|
293
352
|
|
294
353
|
end
|
354
|
+
|
295
355
|
end
|