Class: Axlsx::Worksheet

Inherits:
Object
  • Object
show all
Includes:
OptionsParser, SerializedAttributes
Defined in:
lib/axlsx/workbook/worksheet/worksheet.rb

Overview

The Worksheet class represents a worksheet in the workbook.

Constant Summary

THIN_CHARS =

definition of characters which are less than the maximum width of 0-9 in the default font for use in String#count. This is used for autowidth calculations

'^.acfijklrstxzFIJL()-'.freeze

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Methods included from SerializedAttributes

#declared_attributes, included, #serialized_attributes, #serialized_element_attributes, #serialized_tag

Methods included from OptionsParser

#parse_options

Constructor Details

- (Worksheet) initialize(wb, options = {}) {|_self| ... }

Note:

the recommended way to manage worksheets is Workbook#add_worksheet

Creates a new worksheet.

Options Hash (options):

  • name (String)

    The name of this worksheet.

  • page_margins (Hash)

    A hash containing page margins for this worksheet. @see PageMargins

  • print_options (Hash)

    A hash containing print options for this worksheet. @see PrintOptions

  • header_footer (Hash)

    A hash containing header/footer options for this worksheet. @see HeaderFooter

  • show_gridlines (Boolean)

    indicates if gridlines should be shown for this sheet.

Yields:

  • (_self)

Yield Parameters:

See Also:



20
21
22
23
24
25
26
27
28
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 20

def initialize(wb, options={})
  self.workbook = wb
  @sheet_protection = nil
  initialize_page_options(options)
  parse_options options
  @workbook.worksheets << self
  @sheet_id = index + 1
  yield self if block_given?
end

Instance Attribute Details

- (Object) preserve_spaces

Accessor for controlling whether leading and trailing spaces in cells are preserved or ignored. The default is to preserve spaces.



370
371
372
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 370

def preserve_spaces
  @preserve_spaces
end

- (Workbook) workbook

The workbook that owns this worksheet



100
101
102
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 100

def workbook
  @workbook
end

Instance Method Details

- (Cell, Array) [](cell_def)

Returns the cell or cells defined using excel style A1:B3 references.



632
633
634
635
636
637
638
639
640
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 632

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
    range(*parts)
  end
end

- (Object) add_chart(chart_type, options = {}) {|chart| ... }

Note:

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.

Options Hash (options):

  • start_at (Array)
  • end_at (Array)
  • title (Cell, String)
  • show_legend (Boolean)
  • style (Integer)

Yields:

  • (chart)

See Also:



502
503
504
505
506
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 502

def add_chart(chart_type, options={})
  chart = worksheet_drawing.add_chart(chart_type, options)
  yield chart if block_given?
  chart
end

- (Object) add_comment(options = {})

Shortcut to worsksheet_comments#add_comment



522
523
524
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 522

def add_comment(options={})
  worksheet_comments.add_comment(options)
end

- (Object) add_conditional_formatting(cells, rules)

Add conditional formatting to this worksheet.

Examples:

This would format column A whenever it is FALSE.

# for a longer example, see examples/example_conditional_formatting.rb (link below)
worksheet.add_conditional_formatting( "A1:A1048576", { :type => :cellIs, :operator => :equal, :formula => "FALSE", :dxfId => 1, :priority => 1 }

See Also:



463
464
465
466
467
468
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 463

def add_conditional_formatting(cells, rules)
  cf = ConditionalFormatting.new( :sqref => cells )
  cf.add_rules rules
  conditional_formattings << cf
  conditional_formattings
end

- (Object) add_data_validation(cells, data_validation)

Add data validation to this worksheet.

See Also:

  • for an example


475
476
477
478
479
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 475

def add_data_validation(cells, data_validation)
  dv = DataValidation.new(data_validation)
  dv.sqref = cells
  data_validations << dv
end

Adds a new hyperlink to the worksheet



485
486
487
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 485

def add_hyperlink(options={})
  hyperlinks.add(options)
end

- (Object) add_image(options = {}) {|image| ... }

Adds a media item to the worksheets drawing

Yields:

  • (image)


528
529
530
531
532
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 528

def add_image(options={})
  image = worksheet_drawing.add_image(options)
  yield image if block_given?
  image
end

- (Object) add_page_break(cell)

Adds a page break (row break) to the worksheet should be added to the sheet.

Examples:

ws.add_page_break("A4")


539
540
541
542
543
544
545
546
547
548
549
550
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 539

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

- (Object) add_pivot_table(ref, range, options = {}) {|pivot_tables.last| ... }

Yields:

  • (pivot_tables.last)


515
516
517
518
519
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 515

def add_pivot_table(ref, range, options={})
  pivot_tables << PivotTable.new(ref, range, self, options)
  yield pivot_tables.last if block_given?
  pivot_tables.last
end

- (Row) add_row(values = [], options = {}) {|row| ... } Also known as: <<

Adds a row to the worksheet and updates auto fit data.

Examples:

  • put a vanilla row in your spreadsheet

ws.add_row [1, 'fish on my pl', '8']

  • specify a fixed width for a column in your spreadsheet

# The first column will ignore the content of this cell when calculating column autowidth.
# The second column will include this text in calculating the columns autowidth
# The third cell will set a fixed with of 80 for the column.
# If you need to un-fix a column width, use :auto. That will recalculate the column width based on all content in the column

ws.add_row ['I wish', 'for a fish', 'on my fish wish dish'], :widths=>[:ignore, :auto, 80]

  • specify a fixed height for a row

ws.add_row ['I wish', 'for a fish', 'on my fish wish dish'], :height => 40

  • create and use a style for all cells in the row

blue = ws.styles.add_style :color => "#00FF00"
ws.add_row [1, 2, 3], :style=>blue

  • only style some cells

blue = ws.styles.add_style :color => "#00FF00"
red = ws.styles.add_style :color => "#FF0000"
big = ws.styles.add_style :sz => 40
ws.add_row ["red fish", "blue fish", "one fish", "two fish"], :style=>[red, blue, nil, big] # the last nil is optional

  • force the second cell to be a float value

ws.add_row [3, 4, 5], :types => [nil, :float]

  • use << alias

ws << [3, 4, 5], :types => [nil, :float]

Options Hash (options):

  • values (Array)
  • types (Array, Symbol)
  • style (Array, Integer)
  • widths (Array)

    each member of the widths array will affect how auto_fit behavies.

  • height (Float)

    the row's height (in points)

Yields:

  • (row)

See Also:



444
445
446
447
448
449
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 444

def add_row(values=[], options={})
  row = Row.new(self, values, options)
  update_column_info row, options.delete(:widths)
  yield row if block_given?
  row
end

- (Object) add_table(ref, options = {}) {|tables.last| ... }

needs documentation

Yields:

  • (tables.last)


509
510
511
512
513
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 509

def add_table(ref, options={})
  tables << Table.new(ref, self, options)
  yield tables.last if block_given?
  tables.last
end

- (Object) auto_filter

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.



164
165
166
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 164

def auto_filter
  @auto_filter ||= AutoFilter.new self
end

- (Object) auto_filter=(v)

The auto filter range for the worksheet

See Also:

  • auto_filter


363
364
365
366
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 363

def auto_filter=(v)
  DataTypeValidator.validate :worksheet_auto_filter, String, v
  auto_filter.range = v
end

- (Array) cells

convinience method to access all cells in this worksheet



269
270
271
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 269

def cells
  rows.flatten
end

- (Object) col_breaks

Note:

Please do not use this directly. Instead use

A collection of column breaks added to this worksheet add_page_break

See Also:



118
119
120
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 118

def col_breaks
  @col_breaks ||= ColBreaks.new
end

- (Object) col_style(index, style, options = {})

Note:

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

See Also:



575
576
577
578
579
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 575

def col_style(index, style, options={})
  offset = options.delete(:row_offset) || 0
  cells = @rows[(offset..-1)].map { |row| row[index] }.flatten.compact
  cells.each { |cell| cell.style = style }
end

- (Object) cols(&block)

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.

Examples:

cols { |row_index, column_index| p "warn - row #{row_index} is does not have a cell at #{column_index}


156
157
158
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 156

def cols(&block)
  @rows.transpose(&block)
end

- (SimpleTypedList) column_info

Column info for the sheet



181
182
183
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 181

def column_info
  @column_info ||= Cols.new self
end

- (Object) column_widths(*widths)

Note:

For updating only a single column it is probably easier to just set the width of the ws.column_info[col_index].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.

Examples:

This would set the first and third column widhts but leave the second column in autofit state.

ws.column_widths 7.2, nil, 3


559
560
561
562
563
564
565
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 559

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

- (Array|SimpleTypedList) comments

The a shortcut to the worksheet_comments list of comments



138
139
140
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 138

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



297
298
299
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 297

def dimension
  @dimension ||= Dimension.new self
end

- (Drawing) drawing

Note:

the recommended way to work with drawings and charts is Worksheet#add_chart

The drawing associated with this worksheet.

See Also:



401
402
403
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 401

def drawing
  worksheet_drawing.drawing
end

- (Boolean) fit_to_page=(v)



347
348
349
350
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 347

def fit_to_page=(v)
  warn('axlsx::DEPRECIATED: Worksheet#fit_to_page has been depreciated. This value will automatically be set for you when you use PageSetup#fit_to.')
  fit_to_page?
end

- (Boolean) fit_to_page?

Indicates if the worksheet will be fit by witdh 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.

See Also:



173
174
175
176
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 173

def fit_to_page?
  return false unless self.instance_values.keys.include?('page_setup')
  page_setup.fit_to_page?
end

Options for headers and footers.

Examples:

wb = Axlsx::Package.new.workbook
# would generate something like: "file.xlsx : sheet_name 2 of 7 date with timestamp"
header = {:different_odd_ => false, :odd_header => "&L&F : &A&C&Pof%N%R%D %T"}
ws = wb.add_worksheet :header_footer => header

Yields:

  • (@header_footer)

See Also:



261
262
263
264
265
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 261

def header_footer
  @header_footer ||= HeaderFooter.new
  yield @header_footer if block_given?
  @header_footer
end

A typed collection of hyperlinks associated with this worksheet



132
133
134
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 132

def hyperlinks
  @hyperlinks ||= WorksheetHyperlinks.new self
end

- (Integer) index

The index of this worksheet in the owning Workbook's worksheets list.



393
394
395
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 393

def index
  @workbook.worksheets.index(self)
end

- (Object) initialize_page_options(options)

Initalizes page margin, setup and print options



34
35
36
37
38
39
40
41
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 34

def initialize_page_options(options)
  @page_margins = PageMargins.new options[:page_margins] if options[:page_margins]
  @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

- (Object) merge_cells(cells)

Creates merge information for this worksheet. Cells can be merged by calling the merge_cells method on a worksheet.

Examples:

This would merge the three cells C1..E1 #

worksheet.merge_cells "C1:E1"
# you can also provide an array of cells to be merged
worksheet.merge_cells worksheet.rows.first.cells[(2..4)]
#alternatively you can do it from a single cell
worksheet["C1"].merge worksheet["E1"]


282
283
284
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 282

def merge_cells(cells)
  merged_cells.add cells
end

- (String) name

The name of the worksheet



45
46
47
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 45

def name
  @name ||= "Sheet" + (index+1).to_s
end

- (Object) name=(name)

The name of the worksheet The name of a worksheet must be unique in the workbook, and must not exceed 31 characters



355
356
357
358
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 355

def name=(name)
  validate_sheet_name name
  @name=Axlsx::coder.encode(name)
end

- (Cell) name_to_cell(name)

returns the column and row index for a named based cell



645
646
647
648
649
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 645

def name_to_cell(name)
  col_index, row_index = *Axlsx::name_to_indices(name)
  r = rows[row_index]
  r[col_index] if r
end

- (Object) outline_level_columns(start_index, end_index, level = 1, collapsed = true)

shortcut level to specify the outline level for a series of columns Oulining is what lets you add collapse and expand to a data set.



680
681
682
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 680

def outline_level_columns(start_index, end_index, level = 1, collapsed = true)
  outline column_info, (start_index..end_index), level, collapsed
end

- (Object) outline_level_rows(start_index, end_index, level = 1, collapsed = true)

shortcut level to specify the outline level for a series of rows Oulining is what lets you add collapse and expand to a data set.



670
671
672
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 670

def outline_level_rows(start_index, end_index, level = 1, collapsed = true)
  outline rows, (start_index..end_index), level, collapsed
end

- (PageMargins) page_margins {|@page_margins| ... }

Page margins for printing the worksheet.

Examples:

wb = Axlsx::Package.new.workbook
# using options when creating the worksheet.
ws = wb.add_worksheet :page_margins => {:left => 1.9, :header => 0.1}

# use the set method of the page_margins object
ws.page_margins.set(:bottom => 3, :footer => 0.7)

# set page margins in a block
ws.page_margins do |margins|
  margins.right = 6
  margins.top = 0.2
end

Yields:

  • (@page_margins)

See Also:



201
202
203
204
205
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 201

def page_margins
  @page_margins ||= PageMargins.new
  yield @page_margins if block_given?
  @page_margins
end

- (PageSetup) page_setup {|@page_setup| ... }

Page setup settings for printing the worksheet.

Examples:

wb = Axlsx::Package.new.workbook

# using options when creating the worksheet.
ws = wb.add_worksheet :page_setup => {:fit_to_width => 2, :orientation => :landscape}

# use the set method of the page_setup object
ws.page_setup.set(:paper_width => "297mm", :paper_height => "210mm")

# setup page in a block
ws.page_setup do |page|
  page.scale = 80
  page.orientation = :portrait
end

Yields:

  • (@page_setup)

See Also:



224
225
226
227
228
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 224

def page_setup
  @page_setup ||= PageSetup.new
  yield @page_setup if block_given?
  @page_setup
end

- (Array) pivot_tables

The pivot tables in this worksheet



110
111
112
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 110

def pivot_tables
  @pivot_tables ||=  PivotTables.new self
end

- (String) pn

The part name of this worksheet



374
375
376
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 374

def pn
  "#{WORKSHEET_PN % (index+1)}"
end

Options for printing the worksheet.

Examples:

wb = Axlsx::Package.new.workbook
# using options when creating the worksheet.
ws = wb.add_worksheet :print_options => {:grid_lines => true, :horizontal_centered => true}

# use the set method of the page_margins object
ws.print_options.set(:headings => true)

# set page margins in a block
ws.print_options do |options|
  options.horizontal_centered = true
  options.vertical_centered = true
end

Yields:

  • (@print_options)

See Also:



246
247
248
249
250
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 246

def print_options
  @print_options ||= PrintOptions.new
  yield @print_options if block_given?
  @print_options
end

- (ProtectedRange) protect_range(cells)

Note:

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.



290
291
292
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 290

def protect_range(cells)
  protected_ranges.add_range(cells)
end

- (Relationships) relationships

The worksheet relationships. This is managed automatically by the worksheet



619
620
621
622
623
624
625
626
627
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 619

def relationships
  r = Relationships.new
  r + [tables.relationships,
       worksheet_comments.relationships,
       hyperlinks.relationships,
       worksheet_drawing.relationship,
       pivot_tables.relationships].flatten.compact || []
  r
end

- (String) rels_pn

The relationship part name of this worksheet



380
381
382
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 380

def rels_pn
  "#{WORKSHEET_RELS_PN % (index+1)}"
end

- (String) rId

The relationship id of this worksheet.

See Also:



387
388
389
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 387

def rId
  @workbook.relationships.for(self).Id
end

- (Object) row_breaks

Note:

Please do not use this directly. Instead use

A collection of row breaks added to this worksheet add_page_break

See Also:



126
127
128
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 126

def row_breaks
  @row_breaks ||= RowBreaks.new
end

- (Object) row_style(index, style, options = {})

Note:

You can also specify the style in the add_row call

Set the style for cells in a specific row

See Also:



589
590
591
592
593
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 589

def row_style(index, style, options={})
  offset = options.delete(:col_offset) || 0
  cells = cols[(offset..-1)].map { |column| column[index] }.flatten.compact
  cells.each { |cell| cell.style = style }
end

- (SimpleTypedList) rows

Note:

The recommended way to manage rows is Worksheet#add_row

The rows in this worksheet

See Also:



146
147
148
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 146

def rows
  @rows ||= SimpleTypedList.new Row
end

- (Object) selected

Deprecated.

Use SheetView#tab_selected instead.

Indicates if the worksheet is selected in the workbook It is possible to have more than one worksheet selected, however it might cause issues in some older versions of excel when using copy and paste.



340
341
342
343
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 340

def selected
  warn('axlsx::DEPRECIATED: Worksheet#selected has been depreciated. This value can get over SheetView#tab_selected.')
  sheet_view.tab_selected
end

- (Boolean) selected=(v)

Deprecated.

Use SheetView#tab_selected= instead.

See Also:

  • selected


321
322
323
324
325
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 321

def selected=(v)
  warn('axlsx::DEPRECIATED: Worksheet#selected= has been depreciated. This value can be set over SheetView#tab_selected=.')
  Axlsx::validate_boolean v
  sheet_view.tab_selected = v
end

- (SheetCalcPr) sheet_calc_pr

The sheet calculation properties



67
68
69
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 67

def sheet_calc_pr
  @sheet_calc_pr ||= SheetCalcPr.new
end

- (SheetFormatPr) sheet_format_pr

The sheet format pr for this worksheet

See Also:

  • [SheetFormatPr]


92
93
94
95
96
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 92

def sheet_format_pr
  @sheet_format_pr ||= SheetFormatPr.new
  yeild @sheet_format_pr if block_given?
  @sheet_format_pr
end

- (SheetPr) sheet_pr

The sheet properties for this workbook. Currently only pageSetUpPr -> fitToPage is implemented



304
305
306
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 304

def sheet_pr
  @sheet_pr ||= SheetPr.new self
end

- (SheetProtection) sheet_protection {|@sheet_protection| ... }

The sheet protection object for this workbook

Yields:

  • (@sheet_protection)

See Also:



74
75
76
77
78
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 74

def sheet_protection
  @sheet_protection ||= SheetProtection.new
  yield @sheet_protection if block_given?
  @sheet_protection
end

- (SheetView) sheet_view {|@sheet_view| ... }

The sheet view object for this worksheet

Yields:

  • (@sheet_view)

See Also:

  • [SheetView]


83
84
85
86
87
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 83

def sheet_view
  @sheet_view ||= SheetView.new
  yield @sheet_view if block_given?
  @sheet_view
end

- (Object) show_gridlines

Deprecated.

Use SheetView#show_grid_lines instead.

Indicates if the worksheet should show gridlines or not



330
331
332
333
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 330

def show_gridlines
  warn('axlsx::DEPRECIATED: Worksheet#show_gridlines has been depreciated. This value can get over SheetView#show_grid_lines.')
  sheet_view.show_grid_lines
end

- (Boolean) show_gridlines=(v)

Deprecated.

Use SheetView#show_grid_lines= instead.

Indicates if gridlines should be shown in the sheet. This is true by default.



312
313
314
315
316
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 312

def show_gridlines=(v)
  warn('axlsx::DEPRECIATED: Worksheet#show_gridlines= has been depreciated. This value can be set over SheetView#show_grid_lines=.')
  Axlsx::validate_boolean v
  sheet_view.show_grid_lines = v
end

- (Object) state

The visibility of this sheet



61
62
63
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 61

def state
  @state ||= :visible
end

- (Object) state=(sheet_state)

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.



55
56
57
58
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 55

def state=(sheet_state)
  RestrictionValidator.validate :worksheet_state, [:visible, :hidden, :very_hidden], sheet_state
  @state = sheet_state
end

- (Object) styles

shortcut method to access styles direclty from the worksheet This lets us do stuff like:

Examples:

p = Axlsx::Package.new
p.workbook.add_worksheet(:name => 'foo') do |sheet|
  my_style = sheet.styles.add_style { :bg_color => "FF0000" }
  sheet.add_row ['Oh No!'], :styles => my_style
end
p.serialize 'foo.xlsx'


660
661
662
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 660

def styles
  @styles ||= self.workbook.styles
end

- (Array) tables

The tables in this worksheet



104
105
106
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 104

def tables
  @tables ||=  Tables.new self
end

- (Object) to_sheet_node_xml_string(str = '')

Returns a sheet node serialization for this sheet in the workbook.



596
597
598
599
600
601
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 596

def to_sheet_node_xml_string(str='')
  add_autofilter_defined_name_to_workbook
  str << '<sheet '
  serialized_attributes str
  str << ('r:id="' << rId << '"></sheet>')
end

- (String) to_xml_string(str = '')

Serializes the worksheet object to an xml string This intentionally does not use nokogiri for performance reasons



606
607
608
609
610
611
612
613
614
615
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 606

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