Class: LiquidXlsx::Workbook

Inherits:
Object
  • Object
show all
Defined in:
lib/liquid_xlsx/workbook.rb

Overview

Represents the workbook and orchestrates rendering across all sheets.

Constant Summary collapse

MAX_SHEET_NAME_LENGTH =

Maximum sheet name length in Excel.

31
FORBIDDEN_SHEET_NAME_CHARS =

Characters forbidden in Excel sheet names.

%r{[:/\\\?\*\[\]]}
SHEET_NAME_DEDUP_MAX =

Maximum deduplication attempts before giving up.

9999

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(package, options = {}) ⇒ Workbook

Returns a new instance of Workbook.



8
9
10
11
12
# File 'lib/liquid_xlsx/workbook.rb', line 8

def initialize(package, options = {})
  @package = package
  @options = options
  @shared_strings = SharedStrings.new(package.shared_strings_xml)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/liquid_xlsx/workbook.rb', line 6

def options
  @options
end

#packageObject (readonly)

Returns the value of attribute package.



6
7
8
# File 'lib/liquid_xlsx/workbook.rb', line 6

def package
  @package
end

#shared_stringsObject (readonly)

Returns the value of attribute shared_strings.



6
7
8
# File 'lib/liquid_xlsx/workbook.rb', line 6

def shared_strings
  @shared_strings
end

Instance Method Details

#render(data) ⇒ Package

Render all worksheets with the given data.

Parameters:

  • data (Hash, Liquid::Drop, #to_liquid)

    data to render (Hash/Drop, or any object whose #to_liquid returns one)

Returns:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/liquid_xlsx/workbook.rb', line 18

def render(data)
  all_image_ops = []

  if @options[:dynamic_sheets]
    render_with_dynamic_sheets(data, all_image_ops)
  else
    render_existing_sheets(data, all_image_ops)
  end

  # Phase: build drawings from collected image ops
  build_drawings(all_image_ops)

  # Handle recalculation
  if @options[:recalculate_formulas]
    package.remove_calc_chain if package.calc_chain_xml
    package.set_recalculation_flags
  end

  package
end