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
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.
Attributes inherited from OOXMLDocumentObject
Class Method Summary collapse
-
.get_shared_string(value, cell) ⇒ Nothing
Get shared string by it’s number.
Instance Method Summary collapse
-
#initialize(style = nil, text = '', parent: nil) ⇒ XlsxCell
constructor
A new instance of XlsxCell.
-
#parse(node) ⇒ XlsxCell
Parse XlsxCell object.
Methods inherited from OOXMLDocumentObject
#==, add_to_xmls_stack, copy_file_and_rename_to_zip, current_xml, dir, encrypted_file?, get_link_from_rels, unzip_file, #with_data?
Methods included from OoxmlDocumentObjectHelper
Constructor Details
#initialize(style = nil, text = '', parent: nil) ⇒ XlsxCell
Returns a new instance of XlsxCell.
10 11 12 13 14 15 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 10 def initialize(style = nil, text = '', parent: nil) @style = style @text = text @raw_text = '' @parent = parent 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
39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 39 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.new(parent: cell).parse(si_node_child) when 't' cell.raw_text = si_node_child.text end end end |
Instance Method Details
#parse(node) ⇒ XlsxCell
Parse XlsxCell object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb', line 20 def parse(node) text_string_id = nil text_string_id = node.attribute('s').value unless node.attribute('s').nil? @style = CellStyle.new(parent: self).parse(text_string_id) if node.attribute('t').nil? @raw_text = node.xpath('xmlns:v').text else node.attribute('t').value == 's' ? XlsxCell.get_shared_string(node.xpath('xmlns:v').text, self) : @raw_text = node.xpath('xmlns:v').text end @formula = node.xpath('xmlns:f').text unless node.xpath('xmlns:f').text == '' @text = @raw_text.dup unless @raw_text.nil? @text.insert(0, "'") if @style.quote_prefix self end |