Class: OoxmlParser::Worksheet
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::Worksheet
- Defined in:
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb
Constant Summary
Constants inherited from OOXMLDocumentObject
OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA
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.
-
#drawings ⇒ Object
Returns the value of attribute drawings.
-
#hyperlinks ⇒ Object
Returns the value of attribute hyperlinks.
-
#merge ⇒ Object
Returns the value of attribute merge.
-
#name ⇒ Object
Returns the value of attribute name.
-
#relationships ⇒ Relationships
Array of relationships.
-
#rows ⇒ Object
Returns the value of attribute rows.
-
#sheet_format_properties ⇒ Object
Returns the value of attribute sheet_format_properties.
-
#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.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ Worksheet
constructor
A new instance of Worksheet.
- #parse_relationships ⇒ Object
Methods inherited from OOXMLDocumentObject
#==, add_to_xmls_stack, copy_file_and_rename_to_zip, copy_media_file, current_xml, dir, encrypted_file?, get_link_from_rels, media_folder, option_enabled?, unzip_file
Constructor Details
#initialize ⇒ Worksheet
Returns a new instance of Worksheet.
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 18 def initialize @columns = [] @name = '' @rows = [] @merge = [] @charts = [] @hyperlinks = [] @drawings = [] @sheet_views = [] @table_parts = [] end |
Instance Attribute Details
#autofilter ⇒ Object
Returns the value of attribute autofilter.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def autofilter @autofilter end |
#charts ⇒ Object
Returns the value of attribute charts.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def charts @charts end |
#columns ⇒ Object
Returns the value of attribute columns.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def columns @columns end |
#comments ⇒ Object
Returns the value of attribute comments.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def comments @comments end |
#drawings ⇒ Object
Returns the value of attribute drawings.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def drawings @drawings end |
#hyperlinks ⇒ Object
Returns the value of attribute hyperlinks.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def hyperlinks @hyperlinks end |
#merge ⇒ Object
Returns the value of attribute merge.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def merge @merge end |
#name ⇒ Object
Returns the value of attribute name.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def name @name end |
#relationships ⇒ Relationships
Returns array of relationships.
16 17 18 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 16 def relationships @relationships end |
#rows ⇒ Object
Returns the value of attribute rows.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def rows @rows end |
#sheet_format_properties ⇒ Object
Returns the value of attribute sheet_format_properties.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def sheet_format_properties @sheet_format_properties end |
#sheet_views ⇒ Object
Returns the value of attribute sheet_views.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def sheet_views @sheet_views end |
#table_parts ⇒ Object
Returns the value of attribute table_parts.
11 12 13 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 11 def table_parts @table_parts end |
#xml_name ⇒ String
Returns xml name of sheet.
14 15 16 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 14 def xml_name @xml_name end |
Class Method Details
.parse(path_to_xml_file) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 36 def self.parse(path_to_xml_file) worksheet = Worksheet.new worksheet.xml_name = File.basename path_to_xml_file worksheet.parse_relationships OOXMLDocumentObject.add_to_xmls_stack("#{OOXMLDocumentObject.root_subfolder}/worksheets/#{File.basename(path_to_xml_file)}") doc = Nokogiri::XML(File.open(OOXMLDocumentObject.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| worksheet.rows[row_node.attribute('r').value.to_i - 1] = XlsxRow.parse(row_node) worksheet.rows[row_node.attribute('r').value.to_i - 1].style = CellStyle.parse(row_node.attribute('s').value) unless row_node.attribute('s').nil? end when 'sheetFormatPr' if !worksheet_node_child.attribute('defaultColWidth').nil? && !worksheet_node_child.attribute('defaultRowHeight').nil? worksheet.sheet_format_properties = SheetFormatProperties.parse(worksheet_node_child) end when 'mergeCells' worksheet_node_child.xpath('xmlns:mergeCell').each do |merge_node| worksheet.merge << merge_node.attribute('ref').value.to_s end when 'drawing' path_to_drawing = OOXMLDocumentObject.get_link_from_rels(worksheet_node_child.attribute('id').value) unless path_to_drawing.nil? OOXMLDocumentObject.add_to_xmls_stack(path_to_drawing) XlsxDrawing.parse_list(worksheet) OOXMLDocumentObject.xmls_stack.pop end when 'hyperlinks' worksheet_node_child.xpath('xmlns:hyperlink').each do |hyperlink_node| worksheet.hyperlinks << Hyperlink.parse(hyperlink_node).dup end when 'cols' worksheet.columns = XlsxColumnProperties.parse_list(worksheet_node_child) when 'autoFilter' worksheet.autofilter = Coordinates.parser_coordinates_range(worksheet_node_child.attribute('ref').value.to_s) when 'tableParts' worksheet.table_parts = [] worksheet_node_child.xpath('xmlns:tablePart').each { |table_part_node| worksheet.table_parts << XlsxTable.parse(table_part_node) } when 'sheetViews' worksheet_node_child.xpath('xmlns:sheetView').each { |sheet_view_node| worksheet.sheet_views << SheetView.parse(sheet_view_node) } end end worksheet.comments = ExcelComments.parse_file(File.basename(path_to_xml_file), OOXMLDocumentObject.path_to_folder) OOXMLDocumentObject.xmls_stack.pop worksheet end |
Instance Method Details
#parse_relationships ⇒ Object
30 31 32 33 34 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet.rb', line 30 def parse_relationships OOXMLDocumentObject.add_to_xmls_stack("#{OOXMLDocumentObject.root_subfolder}/worksheets/_rels/#{@xml_name}.rels") @relationships = Relationships.parse(Nokogiri::XML(File.open(OOXMLDocumentObject.current_xml)).xpath('*').first) if File.exist?(OOXMLDocumentObject.current_xml) OOXMLDocumentObject.xmls_stack.pop end |