Class: OoxmlParser::XlsxCell

Inherits:
OOXMLDocumentObject show all
Defined in:
lib/ooxml_parser/xlsx_parser/xlsx_data/view_model/workbook/worksheet/xlsx_row/xlsx_cell.rb

Instance Attribute Summary collapse

Attributes inherited from OOXMLDocumentObject

#parent

Class Method Summary collapse

Instance Method Summary collapse

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

#to_hash

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

#characterObject

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

#formulaObject

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_textString

Returns text without applying any style modificators, like quote_prefix.

Returns:

  • (String)

    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

#styleObject

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

#textObject

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

Parameters:

  • value (String)

    number of shared string

  • cell (XlsxCell)

    to write value of string

Returns:

  • (Nothing)


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

Parameters:

  • node (Nokogiri::XML:Element)

    node to parse

Returns:



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