class ReadXls::WorkbookBuilder

Attributes

biff[RW]
extended_formats[RW]
formats[RW]
sst[RW]
worksheet_builders[RW]

Public Class Methods

new(biff) click to toggle source
# File lib/read_xls/workbook_builder.rb, line 5
def initialize(biff)
  self.biff               = biff
  self.worksheet_builders = []
  self.formats            = default_formats
  self.extended_formats   = []
end

Public Instance Methods

add_extended_format(extended_format) click to toggle source
# File lib/read_xls/workbook_builder.rb, line 20
def add_extended_format(extended_format)
  self.extended_formats.push(extended_format)
end
add_format(format_index, format_string) click to toggle source
# File lib/read_xls/workbook_builder.rb, line 16
def add_format(format_index, format_string)
  self.formats[format_index] = format_string
end
add_worksheet_builder(worksheet_builder) click to toggle source
# File lib/read_xls/workbook_builder.rb, line 12
def add_worksheet_builder(worksheet_builder)
  self.worksheet_builders.push(worksheet_builder)
end
build() click to toggle source
# File lib/read_xls/workbook_builder.rb, line 24
def build
  workbook                  = ::ReadXls::Workbook.new
  workbook.formats          = build_formats
  workbook.extended_formats = build_extended_formats
  workbook.worksheets       = build_worksheets
  workbook
end

Private Instance Methods

build_extended_formats() click to toggle source
# File lib/read_xls/workbook_builder.rb, line 39
def build_extended_formats
  @_extended_formats ||= extended_formats.map(&:evaluate)
end
build_formats() click to toggle source
# File lib/read_xls/workbook_builder.rb, line 35
def build_formats
  @_formats ||= formats.dup
end
build_worksheets() click to toggle source
# File lib/read_xls/workbook_builder.rb, line 43
def build_worksheets
  worksheet_builders.map do |worksheet_builder|
    raise "no sst found!" if sst.nil?

    worksheet_builder.sst              = sst
    worksheet_builder.formats          = build_formats
    worksheet_builder.extended_formats = build_extended_formats

    worksheet_builder.build
  end
end
default_formats() click to toggle source
# File lib/read_xls/workbook_builder.rb, line 55
def default_formats
  [
    "General",
    "0",
    "0.00",
    "#,##0",
    "#,##0.00",
    "$#,##0_);($#,##0)",
    "$#,##0_);[Red]($#,##0)",
    "$#,##0.00_);($#,##0.00)",
    "$#,##0.00_);[Red]($#,##0.00)",
    "0%",
    "0.00%",
    "0.00E+00",
    "# ?/?",
    "# ??/??",
    "M/D/YY",
    "D-MMM-YY",
    "D-MMM",
    "MMM-YY",
    "h:mm AM/PM",
    "h:mm:ss AM/PM",
    "h:mm",
    "h:mm:ss",
    "M/D/YY h:mm",
    "_(#,##0_);(#,##0)",
    "_(#,##0_);[Red](#,##0)",
    "_(#,##0.00_);(#,##0.00)",
    "_(#,##0.00_);[Red](#,##0.00)",
    '_($* #,##0_);_($* (#,##0);_($* "-"_);_(@_)',
    '_(* #,##0_);_(* (#,##0);_(* "-"_);_(@_)',
    '_($* #,##0.00_);_($* (#,##0.00);_($* "-"??_);_(@_)',
    '_(* #,##0.00_);_(* (#,##0.00);_(* "-"??_);_(@_)',
    "mm:ss",
    "[h]:mm:ss",
    "mm:ss.0",
    "##0.0E+0",
    "@"
  ]
end