Class: Axlsx::Worksheet
- Inherits:
-
Object
- Object
- Axlsx::Worksheet
- Includes:
- OptionsParser, SerializedAttributes
- Defined in:
- lib/axlsx/workbook/worksheet/worksheet.rb
Overview
The Worksheet class represents a worksheet in the workbook.
Instance Attribute Summary collapse
-
#escape_formulas ⇒ Boolean
Whether to treat values starting with an equals sign as formulas or as literal strings.
-
#preserve_spaces ⇒ Object
Accessor for controlling whether leading and trailing spaces in cells are preserved or ignored.
-
#workbook ⇒ Workbook
readonly
The workbook that owns this worksheet.
Instance Method Summary collapse
-
#[](cell_def) ⇒ Cell, Array
Returns the cell or cells defined using Excel style A1:B3 references.
-
#add_border(cell_refs, options = nil) ⇒ Object
Set the style for cells in a specific column.
-
#add_chart(chart_type, options = {}) {|chart| ... } ⇒ Object
Adds a chart to this worksheets drawing.
-
#add_comment(options = {}) ⇒ Object
Shortcut to worsksheet_comments#add_comment.
-
#add_conditional_formatting(cells, rules) ⇒ Object
Add conditional formatting to this worksheet.
-
#add_data_validation(cells, data_validation) ⇒ Object
Add data validation to this worksheet.
-
#add_hyperlink(options = {}) ⇒ WorksheetHyperlink
Adds a new hyperlink to the worksheet.
-
#add_image(options = {}) {|image| ... } ⇒ Object
Adds a media item to the worksheets drawing.
-
#add_page_break(cell) ⇒ Object
Adds a page break (row break) to the worksheet should be added to the sheet.
- #add_pivot_table(ref, range, options = {}) {|pivot_tables.last| ... } ⇒ Object
-
#add_row(values = [], options = {}) {|row| ... } ⇒ Row
(also: #<<)
Adds a row to the worksheet and updates auto fit data.
-
#add_style(cell_refs, *styles) ⇒ Object
Set the style for cells in a specific column.
-
#add_table(ref, options = {}) {|tables.last| ... } ⇒ Object
needs documentation.
-
#auto_filter ⇒ Object
A range that Excel will apply an auto-filter to "A1:B3" This will turn filtering on for the cells in the range.
-
#auto_filter=(v) ⇒ Object
The auto filter range for the worksheet.
-
#cells ⇒ Array
convenience method to access all cells in this worksheet.
-
#col_breaks ⇒ Object
A collection of column breaks added to this worksheet add_page_break.
-
#col_style(index, style, options = {}) ⇒ Object
Set the style for cells in a specific column.
-
#cols(&block) ⇒ Object
returns the sheet data as columns If you pass a block, it will be evaluated whenever a row does not have a cell at a specific index.
-
#column_info ⇒ SimpleTypedList
Column info for the sheet.
-
#column_styles(*styles) ⇒ Object
This is a helper method that lets you specify a default style for multiple columns in a worksheet in one go.
-
#column_widths(*widths) ⇒ Object
This is a helper method that Lets you specify a fixed width for multiple columns in a worksheet in one go.
-
#comments ⇒ Array|SimpleTypedList
The a shortcut to the worksheet_comments list of comments.
-
#dimension ⇒ Dimension
The dimensions of a worksheet.
-
#drawing ⇒ Drawing
The drawing associated with this worksheet.
-
#fit_to_page? ⇒ Boolean
Indicates if the worksheet will be fit by width or height to a specific number of pages.
-
#header_footer {|@header_footer| ... } ⇒ HeaderFooter
Options for headers and footers.
-
#hyperlinks ⇒ WorksheetHyperlinks
A typed collection of hyperlinks associated with this worksheet.
-
#index ⇒ Integer
The index of this worksheet in the owning Workbook's worksheets list.
-
#initialize(wb, options = {}) {|_self| ... } ⇒ Worksheet
constructor
Creates a new worksheet.
-
#initialize_page_options(options) ⇒ Object
Initializes page margin, setup and print options.
-
#merge_cells(cells) ⇒ Object
Creates merge information for this worksheet.
-
#name ⇒ String
The name of the worksheet.
-
#name=(name) ⇒ Object
The name of the worksheet The name of a worksheet must be unique in the workbook, and must not exceed the number of characters defined in Axlsx::WORKSHEET_MAX_NAME_LENGTH.
-
#name_to_cell(name) ⇒ Cell
returns the column and row index for a named based cell.
-
#outline_level_columns(start_index, end_index, level = 1, collapsed = true) ⇒ Object
shortcut level to specify the outline level for a series of columns Outlining is what lets you add collapse and expand to a data set.
-
#outline_level_rows(start_index, end_index, level = 1, collapsed = true) ⇒ Object
shortcut level to specify the outline level for a series of rows Outlining is what lets you add collapse and expand to a data set.
-
#page_margins {|@page_margins| ... } ⇒ PageMargins
Page margins for printing the worksheet.
-
#page_setup {|@page_setup| ... } ⇒ PageSetup
Page setup settings for printing the worksheet.
-
#pivot_tables ⇒ Array
The pivot tables in this worksheet.
-
#pn ⇒ String
The part name of this worksheet.
-
#print_options {|@print_options| ... } ⇒ PrintOptions
Options for printing the worksheet.
-
#protect_range(cells) ⇒ ProtectedRange
Adds a new protected cell range to the worksheet.
-
#relationships ⇒ Relationships
The worksheet relationships.
-
#rels_pn ⇒ String
The relationship part name of this worksheet.
-
#rId ⇒ String
The relationship id of this worksheet.
-
#row_breaks ⇒ Object
A collection of row breaks added to this worksheet add_page_break.
-
#row_style(index, style, options = {}) ⇒ Object
Set the style for cells in a specific row.
-
#rows ⇒ SimpleTypedList
The rows in this worksheet.
-
#sheet_calc_pr ⇒ SheetCalcPr
The sheet calculation properties.
-
#sheet_format_pr {|@sheet_format_pr| ... } ⇒ SheetFormatPr
The sheet format pr for this worksheet.
-
#sheet_pr ⇒ SheetPr
The sheet properties for this workbook.
-
#sheet_protection {|@sheet_protection| ... } ⇒ SheetProtection
The sheet protection object for this workbook.
-
#sheet_view {|@sheet_view| ... } ⇒ SheetView
The sheet view object for this worksheet.
-
#state ⇒ Object
The visibility of this sheet.
-
#state=(sheet_state) ⇒ Object
Specifies the visible state of this sheet.
-
#styles ⇒ Object
Shortcut method to access workbook styles.
-
#tables ⇒ Array
The tables in this worksheet.
-
#to_sheet_node_xml_string(str = +'')) ⇒ Object
Returns a sheet node serialization for this sheet in the workbook.
-
#to_xml_string(str = +'')) ⇒ String
Serializes the worksheet object to an xml string This intentionally does not use nokogiri for performance reasons.
Methods included from SerializedAttributes
included, #serialized_attributes, #serialized_element_attributes, #serialized_tag
Methods included from OptionsParser
Constructor Details
#initialize(wb, options = {}) {|_self| ... } ⇒ Worksheet
the recommended way to manage worksheets is Workbook#add_worksheet
Creates a new worksheet.
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 19 def initialize(wb, = {}) self.workbook = wb @sheet_protection = nil () self.escape_formulas = wb.escape_formulas unless defined? @escape_formulas @workbook.worksheets << self @sheet_id = index + 1 yield self if block_given? end |
Instance Attribute Details
#escape_formulas ⇒ Boolean
Whether to treat values starting with an equals sign as formulas or as literal strings. Allowing user-generated data to be interpreted as formulas is a security risk. See https://www.owasp.org/index.php/CSV_Injection for details.
53 54 55 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 53 def escape_formulas @escape_formulas end |
#preserve_spaces ⇒ Object
Accessor for controlling whether leading and trailing spaces in cells are preserved or ignored. The default is to preserve spaces.
341 342 343 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 341 def preserve_spaces @preserve_spaces end |
#workbook ⇒ Workbook
The workbook that owns this worksheet
114 115 116 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 114 def workbook @workbook end |
Instance Method Details
#[](cell_def) ⇒ Cell, Array
Returns the cell or cells defined using Excel style A1:B3 references.
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 677 def [](cell_def) return rows[cell_def] if cell_def.is_a?(Integer) parts = cell_def.split(':').map { |part| name_to_cell part } if parts.size == 1 parts.first else if parts.size > 2 raise ArgumentError, format(ERR_CELL_REFERENCE_INVALID, cell_def) elsif parts.first.nil? raise ArgumentError, format(ERR_CELL_REFERENCE_MISSING_CELL, cell_def.split(":").first, cell_def) elsif parts.last.nil? raise ArgumentError, format(ERR_CELL_REFERENCE_MISSING_CELL, cell_def.split(":").last, cell_def) end range(*parts) end end |
#add_border(cell_refs, options = nil) ⇒ Object
Set the style for cells in a specific column
618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 618 def add_border(cell_refs, = nil) if .is_a?(Hash) border_edges = [:edges] border_style = [:style] border_color = [:color] else border_edges = end unless cell_refs.is_a?(Array) cell_refs = [cell_refs] end cell_refs.each do |cell_ref| item = self[cell_ref] cells = item.is_a?(Array) ? item : [item] Axlsx::BorderCreator.new(worksheet: self, cells: cells, edges: border_edges, style: border_style, color: border_color).draw end end |
#add_chart(chart_type, options = {}) {|chart| ... } ⇒ Object
each chart type also specifies additional options
Adds a chart to this worksheets drawing. This is the recommended way to create charts for your worksheet. This method wraps the complexity of dealing with ooxml drawing, anchors, markers graphic frames chart objects and all the other dirty details.
487 488 489 490 491 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 487 def add_chart(chart_type, = {}) chart = worksheet_drawing.add_chart(chart_type, ) yield chart if block_given? chart end |
#add_comment(options = {}) ⇒ Object
Shortcut to worsksheet_comments#add_comment
507 508 509 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 507 def add_comment( = {}) worksheet_comments.add_comment() end |
#add_conditional_formatting(cells, rules) ⇒ Object
Add conditional formatting to this worksheet.
448 449 450 451 452 453 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 448 def add_conditional_formatting(cells, rules) cf = ConditionalFormatting.new(sqref: cells) cf.add_rules rules conditional_formattings << cf conditional_formattings end |
#add_data_validation(cells, data_validation) ⇒ Object
Add data validation to this worksheet.
460 461 462 463 464 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 460 def add_data_validation(cells, data_validation) dv = DataValidation.new(data_validation) dv.sqref = cells data_validations << dv end |
#add_hyperlink(options = {}) ⇒ WorksheetHyperlink
Adds a new hyperlink to the worksheet
470 471 472 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 470 def add_hyperlink( = {}) hyperlinks.add() end |
#add_image(options = {}) {|image| ... } ⇒ Object
Adds a media item to the worksheets drawing
513 514 515 516 517 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 513 def add_image( = {}) image = worksheet_drawing.add_image() yield image if block_given? image end |
#add_page_break(cell) ⇒ Object
Adds a page break (row break) to the worksheet should be added to the sheet.
524 525 526 527 528 529 530 531 532 533 534 535 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 524 def add_page_break(cell) DataTypeValidator.validate :worksheet_page_break, [String, Cell], cell column_index, row_index = if cell.is_a?(String) Axlsx.name_to_indices(cell) else cell.pos end if column_index > 0 col_breaks.add_break(id: column_index) end row_breaks.add_break(id: row_index) end |
#add_pivot_table(ref, range, options = {}) {|pivot_tables.last| ... } ⇒ Object
500 501 502 503 504 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 500 def add_pivot_table(ref, range, = {}) pivot_tables << PivotTable.new(ref, range, self, ) yield pivot_tables.last if block_given? pivot_tables.last end |
#add_row(values = [], options = {}) {|row| ... } ⇒ Row Also known as: <<
Adds a row to the worksheet and updates auto fit data. (see https://www.owasp.org/index.php/CSV_Injection for details).
429 430 431 432 433 434 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 429 def add_row(values = [], = {}) row = Row.new(self, values, ) update_column_info row, .delete(:widths) yield row if block_given? row end |
#add_style(cell_refs, *styles) ⇒ Object
Set the style for cells in a specific column
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 597 def add_style(cell_refs, *styles) unless cell_refs.is_a?(Array) cell_refs = [cell_refs] end cell_refs.each do |cell_ref| item = self[cell_ref] cells = item.is_a?(Array) ? item : [item] cells.each do |cell| styles.each do |style| cell.add_style(style) end end end end |
#add_table(ref, options = {}) {|tables.last| ... } ⇒ Object
needs documentation
494 495 496 497 498 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 494 def add_table(ref, = {}) tables << Table.new(ref, self, ) yield tables.last if block_given? tables.last end |
#auto_filter ⇒ Object
A range that Excel will apply an auto-filter to "A1:B3" This will turn filtering on for the cells in the range. The first row is considered the header, while subsequent rows are considered to be data.
178 179 180 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 178 def auto_filter @auto_filter ||= AutoFilter.new self end |
#auto_filter=(v) ⇒ Object
The auto filter range for the worksheet
334 335 336 337 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 334 def auto_filter=(v) DataTypeValidator.validate :worksheet_auto_filter, String, v auto_filter.range = v end |
#cells ⇒ Array
convenience method to access all cells in this worksheet
283 284 285 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 283 def cells rows.flatten end |
#col_breaks ⇒ Object
Please do not use this directly. Instead use
A collection of column breaks added to this worksheet add_page_break
132 133 134 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 132 def col_breaks @col_breaks ||= ColBreaks.new end |
#col_style(index, style, options = {}) ⇒ Object
You can also specify the style for specific columns in the call to add_row by using an array for the :styles option
Set the style for cells in a specific column
574 575 576 577 578 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 574 def col_style(index, style, = {}) offset = .delete(:row_offset) || 0 cells = @rows[(offset..-1)].map { |row| row[index] }.flatten.compact cells.each { |cell| cell.style = style } end |
#cols(&block) ⇒ Object
returns the sheet data as columns If you pass a block, it will be evaluated whenever a row does not have a cell at a specific index. The block will be called with the row and column index in the missing cell was found.
170 171 172 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 170 def cols(&block) @rows.transpose(&block) end |
#column_info ⇒ SimpleTypedList
Column info for the sheet
195 196 197 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 195 def column_info @column_info ||= Cols.new self end |
#column_styles(*styles) ⇒ Object
This is a helper method that lets you specify a default style for multiple columns in a worksheet in one go. This style will be applied for all not-yet-defined cells in a column. Note that you must call column_styles BEFORE adding data, otherwise the styles will not be set successfully for new cells.
557 558 559 560 561 562 563 564 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 557 def column_styles(*styles) styles.each_with_index do |style, index| next if style.nil? Axlsx.validate_unsigned_int(style) find_or_create_column_info(index).style = style end end |
#column_widths(*widths) ⇒ Object
For updating only a single column it is probably easier to just set the width of the ws.column_info.width directly
This is a helper method that Lets you specify a fixed width for multiple columns in a worksheet in one go. Note that you must call column_widths AFTER adding data, otherwise the width will not be set successfully. 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.
544 545 546 547 548 549 550 551 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 544 def column_widths(*widths) widths.each_with_index do |value, index| next if value.nil? Axlsx.validate_unsigned_numeric(value) unless value.nil? find_or_create_column_info(index).width = value end end |
#comments ⇒ Array|SimpleTypedList
The a shortcut to the worksheet_comments list of comments
152 153 154 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 152 def comments worksheet_comments.comments if worksheet_comments.has_comments? end |
#dimension ⇒ Dimension
The dimensions of a worksheet. This is not actually a required element by the spec, but at least a few other document readers expect this for conversion
311 312 313 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 311 def dimension @dimension ||= Dimension.new self end |
#drawing ⇒ Drawing
the recommended way to work with drawings and charts is Worksheet#add_chart
The drawing associated with this worksheet.
372 373 374 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 372 def drawing worksheet_drawing.drawing end |
#fit_to_page? ⇒ Boolean
Indicates if the worksheet will be fit by width or height to a specific number of pages. To alter the width or height for page fitting, please use page_setup.fit_to_widht or page_setup.fit_to_height. If you want the worksheet to fit on more pages (e.g. 2x2), set PageSetup#fit_to_width and PageSetup#fit_to_height accordingly.
187 188 189 190 191 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 187 def fit_to_page? return false unless Axlsx.instance_values_for(self).key?('page_setup') page_setup.fit_to_page? end |
#header_footer {|@header_footer| ... } ⇒ HeaderFooter
Options for headers and footers.
275 276 277 278 279 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 275 def @header_footer ||= HeaderFooter.new yield @header_footer if block_given? @header_footer end |
#hyperlinks ⇒ WorksheetHyperlinks
A typed collection of hyperlinks associated with this worksheet
146 147 148 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 146 def hyperlinks @hyperlinks ||= WorksheetHyperlinks.new self end |
#index ⇒ Integer
The index of this worksheet in the owning Workbook's worksheets list.
364 365 366 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 364 def index @workbook.worksheets.index(self) end |
#initialize_page_options(options) ⇒ Object
Initializes page margin, setup and print options
34 35 36 37 38 39 40 41 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 34 def () @page_margins = PageMargins.new [:page_margins] if [:page_margins] @page_setup = PageSetup.new [:page_setup] if [:page_setup] @print_options = PrintOptions.new [:print_options] if [:print_options] @header_footer = HeaderFooter.new [:header_footer] if [:header_footer] @row_breaks = RowBreaks.new @col_breaks = ColBreaks.new end |
#merge_cells(cells) ⇒ Object
Creates merge information for this worksheet. Cells can be merged by calling the merge_cells method on a worksheet.
296 297 298 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 296 def merge_cells(cells) merged_cells.add cells end |
#name ⇒ String
The name of the worksheet
45 46 47 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 45 def name @name ||= "Sheet#{index + 1}" end |
#name=(name) ⇒ Object
The name of the worksheet The name of a worksheet must be unique in the workbook, and must not exceed the number of characters defined in Axlsx::WORKSHEET_MAX_NAME_LENGTH
326 327 328 329 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 326 def name=(name) validate_sheet_name name @name = Axlsx.coder.encode(name) end |
#name_to_cell(name) ⇒ Cell
returns the column and row index for a named based cell
700 701 702 703 704 705 706 707 708 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 700 def name_to_cell(name) col_index, row_index = *Axlsx.name_to_indices(name) r = rows[row_index] if r r[col_index] end end |
#outline_level_columns(start_index, end_index, level = 1, collapsed = true) ⇒ Object
shortcut level to specify the outline level for a series of columns Outlining is what lets you add collapse and expand to a data set.
743 744 745 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 743 def outline_level_columns(start_index, end_index, level = 1, collapsed = true) outline column_info, (start_index..end_index), level, collapsed end |
#outline_level_rows(start_index, end_index, level = 1, collapsed = true) ⇒ Object
shortcut level to specify the outline level for a series of rows Outlining is what lets you add collapse and expand to a data set.
733 734 735 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 733 def outline_level_rows(start_index, end_index, level = 1, collapsed = true) outline rows, (start_index..end_index), level, collapsed end |
#page_margins {|@page_margins| ... } ⇒ PageMargins
Page margins for printing the worksheet.
215 216 217 218 219 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 215 def page_margins @page_margins ||= PageMargins.new yield @page_margins if block_given? @page_margins end |
#page_setup {|@page_setup| ... } ⇒ PageSetup
Page setup settings for printing the worksheet.
238 239 240 241 242 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 238 def page_setup @page_setup ||= PageSetup.new yield @page_setup if block_given? @page_setup end |
#pivot_tables ⇒ Array
The pivot tables in this worksheet
124 125 126 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 124 def pivot_tables @pivot_tables ||= PivotTables.new self end |
#pn ⇒ String
The part name of this worksheet
345 346 347 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 345 def pn format(WORKSHEET_PN, index + 1) end |
#print_options {|@print_options| ... } ⇒ PrintOptions
Options for printing the worksheet.
260 261 262 263 264 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 260 def @print_options ||= PrintOptions.new yield @print_options if block_given? @print_options end |
#protect_range(cells) ⇒ ProtectedRange
When using an array of cells, a contiguous range is created from the minimum top left to the maximum top bottom of the cells provided.
Adds a new protected cell range to the worksheet. Note that protected ranges are only in effect when sheet protection is enabled.
304 305 306 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 304 def protect_range(cells) protected_ranges.add_range(cells) end |
#relationships ⇒ Relationships
The worksheet relationships. This is managed automatically by the worksheet
665 666 667 668 669 670 671 672 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 665 def relationships r = Relationships.new r.concat [tables.relationships, worksheet_comments.relationships, hyperlinks.relationships, worksheet_drawing.relationship, pivot_tables.relationships].flatten.compact end |
#rels_pn ⇒ String
The relationship part name of this worksheet
351 352 353 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 351 def rels_pn format(WORKSHEET_RELS_PN, index + 1) end |
#rId ⇒ String
The relationship id of this worksheet.
358 359 360 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 358 def rId @workbook.relationships.for(self).Id end |
#row_breaks ⇒ Object
Please do not use this directly. Instead use
A collection of row breaks added to this worksheet add_page_break
140 141 142 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 140 def row_breaks @row_breaks ||= RowBreaks.new end |
#row_style(index, style, options = {}) ⇒ Object
You can also specify the style in the add_row call
Set the style for cells in a specific row
588 589 590 591 592 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 588 def row_style(index, style, = {}) offset = .delete(:col_offset) || 0 cells = cols[(offset..-1)].map { |column| column[index] }.flatten.compact cells.each { |cell| cell.style = style } end |
#rows ⇒ SimpleTypedList
The recommended way to manage rows is Worksheet#add_row
The rows in this worksheet
160 161 162 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 160 def rows @rows ||= SimpleTypedList.new Row end |
#sheet_calc_pr ⇒ SheetCalcPr
The sheet calculation properties
81 82 83 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 81 def sheet_calc_pr @sheet_calc_pr ||= SheetCalcPr.new end |
#sheet_format_pr {|@sheet_format_pr| ... } ⇒ SheetFormatPr
The sheet format pr for this worksheet
106 107 108 109 110 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 106 def sheet_format_pr @sheet_format_pr ||= SheetFormatPr.new yield @sheet_format_pr if block_given? @sheet_format_pr end |
#sheet_pr ⇒ SheetPr
The sheet properties for this workbook. Currently only pageSetUpPr -> fitToPage is implemented
318 319 320 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 318 def sheet_pr @sheet_pr ||= SheetPr.new self end |
#sheet_protection {|@sheet_protection| ... } ⇒ SheetProtection
The sheet protection object for this workbook
88 89 90 91 92 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 88 def sheet_protection @sheet_protection ||= SheetProtection.new yield @sheet_protection if block_given? @sheet_protection end |
#sheet_view {|@sheet_view| ... } ⇒ SheetView
The sheet view object for this worksheet
97 98 99 100 101 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 97 def sheet_view @sheet_view ||= SheetView.new yield @sheet_view if block_given? @sheet_view end |
#state ⇒ Object
The visibility of this sheet
75 76 77 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 75 def state @state ||= :visible end |
#state=(sheet_state) ⇒ Object
Specifies the visible state of this sheet. Allowed states are :visible, :hidden or :very_hidden. The default value is :visible.
Worksheets in the :hidden state can be shown using the sheet formatting properties in Excel. :very_hidden sheets should be inaccessible to end users.
69 70 71 72 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 69 def state=(sheet_state) RestrictionValidator.validate :worksheet_state, [:visible, :hidden, :very_hidden], sheet_state @state = sheet_state end |
#styles ⇒ Object
The XLSX format does not support worksheet-specific styles. Even when using this method you're still working with the single global Styles object in the workbook.
Shortcut method to access workbook styles
This lets us do stuff like:
723 724 725 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 723 def styles @styles ||= workbook.styles end |
#tables ⇒ Array
The tables in this worksheet
118 119 120 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 118 def tables @tables ||= Tables.new self end |
#to_sheet_node_xml_string(str = +'')) ⇒ Object
Returns a sheet node serialization for this sheet in the workbook.
641 642 643 644 645 646 647 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 641 def to_sheet_node_xml_string(str = +'') add_autofilter_defined_name_to_workbook str << '<sheet ' serialized_attributes str str << 'name="' << name << '" ' str << 'r:id="' << rId << '"></sheet>' end |
#to_xml_string(str = +'')) ⇒ String
Serializes the worksheet object to an xml string This intentionally does not use nokogiri for performance reasons
652 653 654 655 656 657 658 659 660 661 |
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 652 def to_xml_string(str = +'') add_autofilter_defined_name_to_workbook auto_filter.apply if auto_filter.range str << '<?xml version="1.0" encoding="UTF-8"?>' str << worksheet_node serializable_parts.each do |item| item.to_xml_string(str) if item end str << '</worksheet>' end |