summaryrefslogtreecommitdiffhomepage
path: root/lib/axlsx/workbook/worksheet/sheet_data.rb
blob: f6a27b0e662767918489272b9c19e07ed6e2bf1d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
module Axlsx
  # This class manages the serialization of rows for worksheets
  class SheetData
    # Creates a new SheetData object
    # @param [Worksheet] worksheet The worksheet that owns this sheet data.
    def initialize(worksheet)
      raise ArgumentError, "you must provide a worksheet" unless worksheet.is_a?(Worksheet)

      @worksheet = worksheet
    end

    attr_reader :worksheet

    # Serialize the sheet data
    # @param [String] str the string this objects serializaton will be concacted to.
    # @return [String]
    def to_xml_string(str = '')
      str << '<sheetData>'
      worksheet.rows.each_with_index do |row, index|
        row.to_xml_string(index, str)
      end
      str << '</sheetData>'
    end
  end
end