Class: OoxmlParser::XlsxCell
- Inherits:
-
OOXMLDocumentObject
- Object
- OOXMLDocumentObject
- OoxmlParser::XlsxCell
- Defined in:
- lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb
Constant Summary
Constants inherited from OOXMLDocumentObject
OOXMLDocumentObject::DEFAULT_DIRECTORY_FOR_MEDIA
Instance Attribute Summary collapse
-
#character ⇒ Object
Returns the value of attribute character.
-
#formula ⇒ Object
Returns the value of attribute formula.
-
#raw_text ⇒ String
Text without applying any style modificators, like quote_prefix.
-
#style ⇒ Object
Returns the value of attribute style.
-
#text ⇒ Object
Returns the value of attribute text.
Class Method Summary collapse
-
.get_shared_string(value, cell) ⇒ Nothing
Get shared string by it’s number.
- .parse(cell_node) ⇒ Object
Instance Method Summary collapse
-
#initialize(style = nil, text = '') ⇒ XlsxCell
constructor
A new instance of XlsxCell.
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(style = nil, text = '') ⇒ XlsxCell
Returns a new instance of XlsxCell.
10 11 12 13 14 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 10 def initialize(style = nil, text = '') @style = style @text = text @raw_text = '' end |
Instance Attribute Details
#character ⇒ Object
Returns the value of attribute character.
5 6 7 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 5 def character @character end |
#formula ⇒ Object
Returns the value of attribute formula.
5 6 7 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 5 def formula @formula end |
#raw_text ⇒ String
Returns text without applying any style modificators, like quote_prefix.
8 9 10 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 8 def raw_text @raw_text end |
#style ⇒ Object
Returns the value of attribute style.
5 6 7 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 5 def style @style end |
#text ⇒ Object
Returns the value of attribute text.
5 6 7 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 5 def text @text end |
Class Method Details
.get_shared_string(value, cell) ⇒ Nothing
Get shared string by it’s number
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 35 def self.get_shared_string(value, cell) return '' if value == '' XLSXWorkbook.shared_strings[value.to_i].xpath('*').each do |si_node_child| case si_node_child.name when 'r' cell.character = ParagraphRun.parse(si_node_child) when 't' cell.raw_text = si_node_child.text end end end |
.parse(cell_node) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 16 def self.parse(cell_node) text_string_id = nil text_string_id = cell_node.attribute('s').value unless cell_node.attribute('s').nil? cell = XlsxCell.new(CellStyle.parse(text_string_id)) if cell_node.attribute('t').nil? cell.raw_text = cell_node.xpath('xmlns:v').text else cell_node.attribute('t').value == 's' ? get_shared_string(cell_node.xpath('xmlns:v').text, cell) : cell.raw_text = cell_node.xpath('xmlns:v').text end cell.formula = cell_node.xpath('xmlns:f').text unless cell_node.xpath('xmlns:f').text == '' cell.text = cell.raw_text.dup unless cell.raw_text.nil? cell.text.insert(0, "'") if cell.style.quote_prefix cell end |