class Rubyxls::Sheet
Constants
- FIT_TO_WIDTH
- FOOTER
- GRID_LINES
- HEADER
- LETTER_PAPER_SIZE
- ORIENTATION
- PAGE_MARGIN_BOTTOM
- PAGE_MARGIN_LEFT
- PAGE_MARGIN_RIGHT
- PAGE_MARGIN_TOP
Attributes
sheet_name[R]
Public Class Methods
new(**opts)
click to toggle source
# File lib/rubyxls/sheet.rb, line 17 def initialize(**opts) @sheet_name = opts.fetch(:sheet_name, "Default Sheet") @style_manager = opts.fetch(:style_manager, Rubyxls::StyleManager.new) @paper_size = opts.fetch(:paper_size, LETTER_PAPER_SIZE) end
Public Instance Methods
build_charts()
click to toggle source
# File lib/rubyxls/sheet.rb, line 38 def build_charts [] end
build_options(*taken_names)
click to toggle source
# File lib/rubyxls/sheet.rb, line 23 def build_options(*taken_names) { page_setup: build_page_setup, print_options: build_print_options, page_margins: build_page_margins, name: unique_sheet_name(sanitize_sheet_name(@sheet_name), taken_names) } end
build_rows()
click to toggle source
# File lib/rubyxls/sheet.rb, line 30 def build_rows Rubyxls::Builders::RowBuilder.new(build_cells).rows.each do |row| row.each do |cell| cell[:style] = @style_manager.retrieve_style_attributes(cell[:style]) end end end
build_width_normalization()
click to toggle source
# File lib/rubyxls/sheet.rb, line 42 def build_width_normalization {} end
Private Instance Methods
build_cells()
click to toggle source
# File lib/rubyxls/sheet.rb, line 67 def build_cells Rubyxls::Builders::CellBuilder.new(model_data_rows: Rubyxls::ViewModel.new(title_row: true, header_row: true, additional_rows: 1, total_row: true).data_rows, start_row: 2, start_column: "B").cells end
build_page_margins()
click to toggle source
# File lib/rubyxls/sheet.rb, line 58 def build_page_margins { top: PAGE_MARGIN_TOP, left: PAGE_MARGIN_LEFT, bottom: PAGE_MARGIN_BOTTOM, right: PAGE_MARGIN_RIGHT, header: HEADER, footer: FOOTER } end
build_page_setup()
click to toggle source
# File lib/rubyxls/sheet.rb, line 48 def build_page_setup { fit_to_width: FIT_TO_WIDTH, orientation: ORIENTATION, paper_size: @paper_size } end
build_print_options()
click to toggle source
# File lib/rubyxls/sheet.rb, line 54 def build_print_options { grid_lines: GRID_LINES } end
sanitize_sheet_name(sheet_name)
click to toggle source
# File lib/rubyxls/sheet.rb, line 71 def sanitize_sheet_name(sheet_name) sheet_name.gsub(/[:\[\]\/\\\*\?]/, '-') end
unique_sheet_name(sheet_name, taken_names, index=1)
click to toggle source
# File lib/rubyxls/sheet.rb, line 75 def unique_sheet_name(sheet_name, taken_names, index=1) sliced_name = sheet_name.byteslice(0, 31) return sliced_name unless taken_names.include?(sliced_name) sheet_name = "#{sheet_name.byteslice(0, 28)}(#{index})" unique_sheet_name(sheet_name, taken_names, index + 1) end