class Axlsx::CellSerializer
The Cell Serializer class contains the logic for serializing cells based on their type.
def array_formula_serialization(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def array_formula_serialization(cell, str = '') str << ('t="str">' << '<f t="array" ref="' << cell.r << '">' << cell.clean_value.to_s.sub('{=', '').sub(/}$/, '') << '</f>') str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil? end
def boolean(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def boolean(cell, str = '') value_serialization 'b', cell.value.to_s, str end
def date(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def date(cell, str = '') value_serialization false, DateTimeConverter::date_to_serial(cell.value).to_s, str end
def float(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def float(cell, str = '') numeric cell, str end
def formula_serialization(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def formula_serialization(cell, str = '') str << ('t="str"><f>' << cell.clean_value.to_s.sub('=', '') << '</f>') str << ('<v>' << cell.formula_value.to_s << '</v>') unless cell.formula_value.nil? end
def inline_string_serialization(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def inline_string_serialization(cell, str = '') str << 't="inlineStr"><is>' run_xml_string cell, str str << '</is>' end
def integer(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def integer(cell, str = '') numeric cell, str end
def iso_8601(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def iso_8601(cell, str = '') value_serialization 'd', cell.value, str end
def numeric(cell, str = '')
def numeric(cell, str = '') value_serialization 'n', cell.value, str end
def richtext(cell, str)
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def richtext(cell, str) if cell.ssti.nil? inline_string_serialization cell, str else value_serialization 's', cell.ssti, str end end
def run_xml_string(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string instance this run will be concated to.
def run_xml_string(cell, str = '') if cell.is_text_run? valid = RichTextRun::INLINE_STYLES - [:value, :type] data = Hash[Axlsx.instance_values_for(cell).map { |k, v| [k.to_sym, v] }] data = data.select { |key, value| valid.include?(key) && !value.nil? } RichText.new(cell.value.to_s, data).to_xml_string(str) elsif cell.contains_rich_text? cell.value.to_xml_string(str) else str << ('<t>' << cell.clean_value << '</t>') end str end
def string(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def string(cell, str = '') if cell.is_array_formula? array_formula_serialization cell, str elsif cell.is_formula? formula_serialization cell, str elsif !cell.ssti.nil? value_serialization 's', cell.ssti, str else inline_string_serialization cell, str end end
def text(cell, str)
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def text(cell, str) if cell.ssti.nil? inline_string_serialization cell, str else value_serialization 's', cell.ssti, str end end
def time(cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string the serialized content will be appended to. -
cell(Cell) -- The cell that is being serialized
def time(cell, str = '') value_serialization false, DateTimeConverter::time_to_serial(cell.value).to_s, str end
def to_xml_string(row_index, column_index, cell, str = '')
-
(String)-
Parameters:
-
str(String) -- The string to apend serialization to. -
column_index(Integer) -- The index of the cell's column -
row_index(Integer) -- The index of the cell's row
def to_xml_string(row_index, column_index, cell, str = '') str << ('<c r="' << Axlsx::cell_r(column_index, row_index) << '" s="' << cell.style.to_s << '" ') return str << '/>' if cell.value.nil? method = cell.type self.send(method, cell, str) str << '</c>' end
def value_serialization(serialization_type, serialization_value, str = '')
def value_serialization(serialization_type, serialization_value, str = '') str << ('t="' << serialization_type.to_s << '"') if serialization_type str << ('><v>' << serialization_value.to_s << '</v>') end