Method: Spreadsheet::Excel::Writer::Workbook#collect_formats

Defined in:
lib/spreadsheet/excel/writer/workbook.rb

#collect_formats(workbook, opts = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/spreadsheet/excel/writer/workbook.rb', line 51

def collect_formats workbook, opts={}
  # The default cell format is always present in an Excel file, described by
  # the XF record with the fixed index 15 (0-based). By default, it uses the
  # worksheet/workbook default cell style, described by the very first XF
  # record (index 0).
  formats = []
  unless opts[:existing_document]
    15.times do
      formats.push Format.new(self, workbook, workbook.default_format,
                              :type => :style)
    end
    formats.push Format.new(self, workbook)
  end
  workbook.formats.each do |fmt|
    formats.push Format.new(self, workbook, fmt)
  end
  formats.each_with_index do |fmt, idx|
    fmt.xf_index = idx
  end
  @formats[workbook] = formats
end