class Xlsxrb::TableBuilder
Builder context for configuring an Excel Table (ListObject) in block form.
Public Class Methods
(?String? ref, ?columns: untyped, ?name: String?, ?display_name: String?, ?style: String?, **untyped opts) → void
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2551 def initialize(ref = nil, columns: nil, name: nil, display_name: nil, style: nil, **opts) @options = opts.dup @options[:ref] = ref if ref @options[:columns] = columns.is_a?(Array) ? columns.dup : [columns] if columns @options[:name] = name if name @options[:display_name] = display_name if display_name @options[:style] = style if style end
@param ref [String, nil] Table range (e.g. “A1:D10”). @param columns [Array, nil] Column header names or definition hashes. @param name [String, nil] Table name identifier. @param display_name [String, nil] Table display name. @param style [String, nil] Built-in table style name (e.g. “TableStyleMedium2”). @param opts [Hash] Additional table properties.
Public Instance Methods
(bool val) → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2726 def auto_filter=(val) @options[:auto_filter] = val ? true : false end
() → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2721 def auto_filter? @options[:auto_filter] != false end
(String | Symbol name, String formula, **untyped opts) → void
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2617 def calculated_column(name, formula, **opts) column(name, formula: formula, **opts) end
Appends a calculated column with formula and options.
@param name [String, Symbol] The column name. @param formula [String] The formula for the calculated column (e.g. “[@Qty]*[@Price]”). @param opts [Hash] Additional column options. @return [void]
(String | Symbol | Hash[Symbol, untyped] col, **untyped opts) → void
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2598 def column(col, **opts) col_spec = if opts.empty? col elsif col.is_a?(Hash) col.merge(opts) else opts.merge(name: col.to_s) end (@options[:columns] ||= []) << col_spec nil end
Appends a single column name or column definition.
@param col [String, Hash, Symbol] Column header name or definition. @param opts [Hash] Column options (e.g. totals_row_function, totals_row_label, formula, totals_row_formula). @return [void]
() → Array[Elements::TableColumn]
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2575 def columns (@options[:columns] || []).each_with_index.map do |c, idx| if c.is_a?(Elements::TableColumn) c elsif c.is_a?(Hash) Elements::TableColumn.new(id: idx + 1, **c) else Elements::TableColumn.new(id: idx + 1, name: c.to_s) end end end
Returns column definitions for the table.
@return [Array<Elements::TableColumn>] @api public
(untyped cols) → untyped
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2588 def columns=(cols) @options[:columns] = cols.is_a?(Array) ? cols : [cols] end
() → String?
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2632 def display_name @options[:display_name] end
(String val) → String
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2637 def display_name=(val) @options[:display_name] = val.to_s end
() → String?
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2622 def name @options[:name] end
(String val) → String
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2627 def name=(val) @options[:name] = val.to_s end
() → String?
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2561 def ref @options[:ref] end
(String val) → String
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2566 def ref=(val) @options[:ref] = val.to_s end
(bool val) → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2667 def show_column_stripes=(val) @options[:show_column_stripes] = val ? true : false end
() → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2662 def show_column_stripes? @options[:show_column_stripes] ? true : false end
(bool val) → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2677 def show_first_column=(val) @options[:show_first_column] = val ? true : false end
() → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2672 def show_first_column? @options[:show_first_column] ? true : false end
(bool val) → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2687 def show_last_column=(val) @options[:show_last_column] = val ? true : false end
() → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2682 def show_last_column? @options[:show_last_column] ? true : false end
(bool val) → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2657 def show_row_stripes=(val) @options[:show_row_stripes] = val ? true : false end
() → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2652 def show_row_stripes? @options[:show_row_stripes] ? true : false end
() → String?
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2642 def style @options[:style] end
(String val) → String
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2647 def style=(val) @options[:style] = val.to_s end
() → Hash[Symbol, untyped]
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2731 def to_h @options.dup end
(bool val) → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2715 def totals_row=(val) @options[:totals_row_count] = val ? 1 : 0 val end
() → bool
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2705 def totals_row? rc = @options[:totals_row_count] if rc rc.positive? else @options[:totals_row] ? true : false end end
Returns whether the table has a totals row.
@return [Boolean]
() → Integer?
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2692 def totals_row_count @options[:totals_row_count] end
(Integer val) → Integer
Source
# File lib/xlsxrb/worksheet_builder.rb, line 2697 def totals_row_count=(val) @options[:totals_row_count] = val.to_i end