Class: OoxmlParser::Worksheet
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Worksheet
- Includes:
- WorksheetHelper
- Defined in:
- lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb
Overview
Properties of worksheet
Instance Attribute Summary collapse
-
#autofilter ⇒ Object
Returns the value of attribute autofilter.
-
#charts ⇒ Object
Returns the value of attribute charts.
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#comments ⇒ Object
Returns the value of attribute comments.
-
#conditional_formattings ⇒ Array<ConditionalFormatting>
readonly
List of conditional formattings.
-
#drawings ⇒ Object
Returns the value of attribute drawings.
-
#extension_list ⇒ ExtensionList
List of extensions.
-
#header_footer ⇒ XlsxHeaderFooter
readonly
Header and footer.
-
#hyperlinks ⇒ Object
Returns the value of attribute hyperlinks.
-
#merge ⇒ Object
Returns the value of attribute merge.
-
#name ⇒ Object
Returns the value of attribute name.
-
#ole_objects ⇒ Relationships
Array of ole objects.
-
#page_margins ⇒ PageMargins
readonly
Page margins settings.
-
#page_setup ⇒ PageSetup
readonly
Page setup settings.
-
#protected_ranges ⇒ Array<ProtectedRange>
readonly
List of protected ranges.
-
#relationships ⇒ Relationships
Array of relationships.
-
#rows_raw ⇒ Array<Row>
readonly
Rows in sheet, as in xml structure.
-
#sheet_format_properties ⇒ Object
Returns the value of attribute sheet_format_properties.
-
#sheet_protection ⇒ SheetProtection
readonly
Protection of sheet.
-
#sheet_views ⇒ Object
Returns the value of attribute sheet_views.
-
#table_parts ⇒ Object
Returns the value of attribute table_parts.
-
#xml_name ⇒ String
Xml name of sheet.
Attributes inherited from OOXMLDocumentObject
Instance Method Summary collapse
-
#initialize(parent: nil) ⇒ Worksheet
constructor
A new instance of Worksheet.
-
#parse(path_to_xml_file) ⇒ Worksheet
Parse data of Worksheet.
-
#parse_drawing ⇒ Object
Parse list of drawings in file.
-
#parse_relationships ⇒ nil
Perform parsing of relationships.
-
#rows ⇒ Array<XlsxRow, nil>
List of rows, with nil, if row data is not stored in xml.
-
#with_data? ⇒ True, false
If structure contain any user data.
Methods included from WorksheetHelper
Methods inherited from OOXMLDocumentObject
#==, #boolean_attribute_value, #parse_xml
Methods included from OoxmlObjectAttributeHelper
#attribute_enabled?, #option_enabled?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(parent: nil) ⇒ Worksheet
Returns a new instance of Worksheet.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 45 def initialize(parent: nil) @columns = [] @name = '' @rows = [] @rows_raw = [] @merge = [] @charts = [] @hyperlinks = [] @drawings = [] @sheet_views = [] @table_parts = [] @conditional_formattings = [] @protected_ranges = [] super end |
Instance Attribute Details
#autofilter ⇒ Object
Returns the value of attribute autofilter.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def autofilter @autofilter end |
#charts ⇒ Object
Returns the value of attribute charts.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def charts @charts end |
#columns ⇒ Object
Returns the value of attribute columns.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def columns @columns end |
#comments ⇒ Object
Returns the value of attribute comments.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def comments @comments end |
#conditional_formattings ⇒ Array<ConditionalFormatting> (readonly)
Returns list of conditional formattings.
37 38 39 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 37 def conditional_formattings @conditional_formattings end |
#drawings ⇒ Object
Returns the value of attribute drawings.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def drawings @drawings end |
#extension_list ⇒ ExtensionList
Returns list of extensions.
33 34 35 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 33 def extension_list @extension_list end |
#header_footer ⇒ XlsxHeaderFooter (readonly)
Returns header and footer.
35 36 37 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 35 def @header_footer end |
#hyperlinks ⇒ Object
Returns the value of attribute hyperlinks.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def hyperlinks @hyperlinks end |
#merge ⇒ Object
Returns the value of attribute merge.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def merge @merge end |
#name ⇒ Object
Returns the value of attribute name.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def name @name end |
#ole_objects ⇒ Relationships
Returns array of ole objects.
27 28 29 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 27 def ole_objects @ole_objects end |
#page_margins ⇒ PageMargins (readonly)
Returns page margins settings.
29 30 31 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 29 def page_margins @page_margins end |
#page_setup ⇒ PageSetup (readonly)
Returns page setup settings.
31 32 33 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 31 def page_setup @page_setup end |
#protected_ranges ⇒ Array<ProtectedRange> (readonly)
Returns list of protected ranges.
41 42 43 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 41 def protected_ranges @protected_ranges end |
#relationships ⇒ Relationships
Returns array of relationships.
25 26 27 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 25 def relationships @relationships end |
#rows_raw ⇒ Array<Row> (readonly)
Returns rows in sheet, as in xml structure.
43 44 45 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 43 def rows_raw @rows_raw end |
#sheet_format_properties ⇒ Object
Returns the value of attribute sheet_format_properties.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def sheet_format_properties @sheet_format_properties end |
#sheet_protection ⇒ SheetProtection (readonly)
Returns protection of sheet.
39 40 41 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 39 def sheet_protection @sheet_protection end |
#sheet_views ⇒ Object
Returns the value of attribute sheet_views.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def sheet_views @sheet_views end |
#table_parts ⇒ Object
Returns the value of attribute table_parts.
20 21 22 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 20 def table_parts @table_parts end |
#xml_name ⇒ String
Returns xml name of sheet.
23 24 25 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 23 def xml_name @xml_name end |
Instance Method Details
#parse(path_to_xml_file) ⇒ Worksheet
Parse data of Worksheet
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 91 def parse(path_to_xml_file) @xml_name = File.basename path_to_xml_file parse_relationships root_object.add_to_xmls_stack("#{root_object.root_subfolder}/worksheets/#{File.basename(path_to_xml_file)}") doc = parse_xml(root_object.current_xml) sheet = doc.search('//xmlns:worksheet').first sheet.xpath('*').each do |worksheet_node_child| case worksheet_node_child.name when 'sheetData' worksheet_node_child.xpath('xmlns:row').each do |row_node| @rows_raw << XlsxRow.new(parent: self).parse(row_node) end when 'sheetFormatPr' @sheet_format_properties = SheetFormatProperties.new(parent: self).parse(worksheet_node_child) when 'mergeCells' worksheet_node_child.xpath('xmlns:mergeCell').each do |merge_node| @merge << merge_node.attribute('ref').value.to_s end when 'drawing' @drawing = DocxDrawing.new(parent: self).parse(worksheet_node_child) path_to_drawing = root_object.get_link_from_rels(@drawing.id) unless path_to_drawing.nil? root_object.add_to_xmls_stack(path_to_drawing) parse_drawing root_object.xmls_stack.pop end when 'hyperlinks' worksheet_node_child.xpath('xmlns:hyperlink').each do |hyperlink_node| @hyperlinks << Hyperlink.new(parent: self).parse(hyperlink_node).dup end when 'cols' @columns = XlsxColumns.new(parent: self).parse(worksheet_node_child).elements when 'autoFilter' @autofilter = Autofilter.new(parent: self).parse(worksheet_node_child) when 'tableParts' worksheet_node_child.xpath('*').each do |part_node| @table_parts << TablePart.new(parent: self).parse(part_node) end when 'sheetViews' worksheet_node_child.xpath('*').each do |view_child| @sheet_views << SheetView.new(parent: self).parse(view_child) end when 'oleObjects' @ole_objects = OleObjects.new(parent: self).parse(worksheet_node_child) when 'pageMargins' @page_margins = PageMargins.new(parent: self).parse(worksheet_node_child, :inch) when 'pageSetup' @page_setup = PageSetup.new(parent: self).parse(worksheet_node_child) when 'extLst' @extension_list = ExtensionList.new(parent: self).parse(worksheet_node_child) when 'headerFooter' @header_footer = XlsxHeaderFooter.new(parent: self).parse(worksheet_node_child) when 'conditionalFormatting' @conditional_formattings << ConditionalFormatting.new(parent: self).parse(worksheet_node_child) when 'sheetProtection' @sheet_protection = SheetProtection.new(parent: self).parse(worksheet_node_child) when 'protectedRanges' worksheet_node_child.xpath('*').each do |protected_range_node| @protected_ranges << ProtectedRange.new(parent: self).parse(protected_range_node) end end end parse_comments root_object.xmls_stack.pop self end |
#parse_drawing ⇒ Object
Parse list of drawings in file
81 82 83 84 85 86 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 81 def parse_drawing drawing_node = parse_xml(root_object.current_xml) drawing_node.xpath('xdr:wsDr/*').each do |drawing_node_child| @drawings << XlsxDrawing.new(parent: self).parse(drawing_node_child) end end |
#parse_relationships ⇒ nil
Perform parsing of relationships
63 64 65 66 67 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 63 def parse_relationships root_object.add_to_xmls_stack("#{root_object.root_subfolder}/worksheets/_rels/#{@xml_name}.rels") @relationships = Relationships.new(parent: self).parse_file(root_object.current_xml) if File.exist?(root_object.current_xml) root_object.xmls_stack.pop end |
#rows ⇒ Array<XlsxRow, nil>
Returns list of rows, with nil, if row data is not stored in xml.
160 161 162 163 164 165 166 167 168 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 160 def rows return @rows if @rows.any? rows_raw.each do |row| @rows[row.index - 1] = row end @rows end |
#with_data? ⇒ True, false
Returns if structure contain any user data.
70 71 72 73 74 75 76 77 78 |
# File 'lib/ooxml_parser/xlsx_parser/workbook/worksheet.rb', line 70 def with_data? return true unless @rows_raw.empty? return true unless default_columns? return true unless @drawings.empty? return true unless @charts.empty? return true unless @hyperlinks.empty? false end |