Method: Axlsx::Workbook#to_xml_string
- Defined in:
- lib/axlsx/workbook/workbook.rb
#to_xml_string(str = '') ⇒ String
Serialize the workbook
345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/axlsx/workbook/workbook.rb', line 345 def to_xml_string(str='') add_worksheet(name: 'Sheet1') unless worksheets.size > 0 str << '<?xml version="1.0" encoding="UTF-8"?>' str << ('<workbook xmlns="' << XML_NS << '" xmlns:r="' << XML_NS_R << '">') str << ('<workbookPr date1904="' << @@date1904.to_s << '"/>') views.to_xml_string(str) str << '<sheets>' if is_reversed worksheets.reverse_each { |sheet| sheet.to_sheet_node_xml_string(str) } else worksheets.each { |sheet| sheet.to_sheet_node_xml_string(str) } end str << '</sheets>' defined_names.to_xml_string(str) unless pivot_tables.empty? str << '<pivotCaches>' pivot_tables.each do |pivot_table| str << ('<pivotCache cacheId="' << pivot_table.cache_definition.cache_id.to_s << '" r:id="' << pivot_table.cache_definition.rId << '"/>') end str << '</pivotCaches>' end str << '</workbook>' end |