diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/axlsx/workbook/workbook.rb | 5 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/break.rb | 11 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/col_breaks.rb | 21 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/row_breaks.rb | 25 | ||||
| -rw-r--r-- | lib/axlsx/workbook/worksheet/worksheet.rb | 21 |
5 files changed, 75 insertions, 8 deletions
diff --git a/lib/axlsx/workbook/workbook.rb b/lib/axlsx/workbook/workbook.rb index 3356b9de..0f70f37f 100644 --- a/lib/axlsx/workbook/workbook.rb +++ b/lib/axlsx/workbook/workbook.rb @@ -35,6 +35,11 @@ require 'axlsx/workbook/worksheet/worksheet_comments.rb' require 'axlsx/workbook/worksheet/worksheet_hyperlink' require 'axlsx/workbook/worksheet/worksheet_hyperlinks' require 'axlsx/workbook/worksheet/break' +require 'axlsx/workbook/worksheet/row_breaks' +require 'axlsx/workbook/worksheet/col_breaks' + + + require 'axlsx/workbook/worksheet/worksheet.rb' require 'axlsx/workbook/shared_strings_table.rb' require 'axlsx/workbook/defined_name.rb' diff --git a/lib/axlsx/workbook/worksheet/break.rb b/lib/axlsx/workbook/worksheet/break.rb index 9de2c84c..493aeafd 100644 --- a/lib/axlsx/workbook/worksheet/break.rb +++ b/lib/axlsx/workbook/worksheet/break.rb @@ -16,26 +16,23 @@ module Axlsx # @option options [Integer] max Zero-based index of end row or column of the break. For row breaks, specifies column index; for column breaks, specifies row index. # @option options [Boolean] man Manual Break flag. 1 means the break is a manually inserted break. # @option option [Boolean] pt Flag indicating that a PivotTable created this break. - def initialize(worksheet, options={}) - @worksheet = worksheet + def initialize(options={}) parse_options options yield self if block_given? end unsigned_int_attr_accessor :id, :min, :max + boolean_attr_accessor :man, :pt - serializable_attributes :id, :min, :max, :man, :pt - attr_reader :worksheet + serializable_attributes :id, :min, :max, :man, :pt # serializes the break to xml def to_xml_string(str='') - str << '<brk' + str << '<brk ' serialized_attributes str str << '></brk>' end - end - end diff --git a/lib/axlsx/workbook/worksheet/col_breaks.rb b/lib/axlsx/workbook/worksheet/col_breaks.rb new file mode 100644 index 00000000..2bf927e1 --- /dev/null +++ b/lib/axlsx/workbook/worksheet/col_breaks.rb @@ -0,0 +1,21 @@ +module Axlsx + + class ColBreaks < SimpleTypedList + + def initialize + super Break + end + + def add_break(options) + options.merge max: 1048575, man: true + @list << Break.new(options) + end + + def to_xml_string(str='') + return if empty? + str << '<colBreaks count="' << @list.size << '" manualBreakCount="' << @list.size << '">' + each { |brk| brk.to_xml_string(str) } + str << '</rowBreaks>' + end + end +end diff --git a/lib/axlsx/workbook/worksheet/row_breaks.rb b/lib/axlsx/workbook/worksheet/row_breaks.rb new file mode 100644 index 00000000..b8158a89 --- /dev/null +++ b/lib/axlsx/workbook/worksheet/row_breaks.rb @@ -0,0 +1,25 @@ +module Axlsx + + # A collection of break objects that define row breaks (page breaks) for printing and preview + + class RowBreaks < SimpleTypedList + + def initialize + super Break + end + + def add_break(options) + # force feed the excel default + options.merge max: 16383, man: true + @list << Break.new(options) + last + end + + def to_xml_string(str='') + return if empty? + str << '<rowBreaks count="' << @list.size << '" manualBreakCount="' << @list.size << '">' + each { |brk| brk.to_xml_string(str) } + str << '</rowBreaks>' + end + end +end diff --git a/lib/axlsx/workbook/worksheet/worksheet.rb b/lib/axlsx/workbook/worksheet/worksheet.rb index df755abf..0e0f751a 100644 --- a/lib/axlsx/workbook/worksheet/worksheet.rb +++ b/lib/axlsx/workbook/worksheet/worksheet.rb @@ -37,6 +37,8 @@ module Axlsx @page_setup = PageSetup.new options[:page_setup] if options[:page_setup] @print_options = PrintOptions.new options[:print_options] if options[:print_options] @header_footer = HeaderFooter.new options[:header_footer] if options[:header_footer] + @row_breaks = RowBreaks.new + @col_breaks = ColBreaks.new end # The name of the worksheet @@ -94,6 +96,14 @@ module Axlsx @pivot_tables ||= PivotTables.new self end + def col_breaks + @col_breaks ||= ColBreaks.new + end + + def row_breaks + @row_breaks ||= RowBreaks.new + end + # A typed collection of hyperlinks associated with this worksheet # @return [WorksheetHyperlinks] def hyperlinks @@ -498,6 +508,15 @@ module Axlsx image end + # Adds a page break (row break) to the worksheet + # @param row_index Zero-based row index of the page break. + def add_page_break(row_index, col_index=0) + row_breaks.add_break(id: row_index) + if col_index > 0 + col_breaks.add_break(id: col_index) + end + end + # This is a helper method that Lets you specify a fixed width for multiple columns in a worksheet in one go. # Axlsx is sparse, so if you have not set data for a column, you cannot set the width. # Setting a fixed column width to nil will revert the behaviour back to calculating the width for you on the next call to add_row. @@ -652,7 +671,7 @@ module Axlsx sheet_data, sheet_calc_pr, @sheet_protection, protected_ranges, auto_filter, merged_cells, conditional_formattings, data_validations, hyperlinks, print_options, page_margins, - page_setup, header_footer, worksheet_drawing, worksheet_comments, + page_setup, header_footer, row_breaks, col_breaks, worksheet_drawing, worksheet_comments, tables] end |
