Class: Axlsx::Worksheet

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

Overview

The Worksheet class represents a worksheet in the workbook.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from OptionsParser

#parse_options

Constructor Details

#initialize(wb, options = {}) ⇒ Worksheet

Note:

the recommended way to manage worksheets is Workbook#add_worksheet

Creates a new worksheet.

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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.

See Also:



24
25
26
27
28
29
30
31
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 24

def initialize(wb, options={})
  self.workbook = wb
  @sheet_protection = nil

  initialize_page_options(options)
  parse_options options
  @workbook.worksheets << self
end

Instance Attribute Details

#workbookWorkbook

The workbook that owns this worksheet

Returns:



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

def workbook
  @workbook
end

Class Method Details

.thin_charsString

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

Returns:

  • (String)


11
12
13
14
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 11

def self.thin_chars
  # removed 'e' and 'y' from this list - as a GUESS
  @thin_chars ||= "^.acfijklrstxzFIJL()-"
end

Instance Method Details

#[](cell_def) ⇒ Cell, Array

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

Parameters:

  • cell_def (String|Integer)

    the string defining the cell or range of cells, or the rownumber

Returns:



579
580
581
582
583
584
585
586
587
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 579

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

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

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.

Parameters:

  • chart_type (Class)
  • options (Hash) (defaults to: {})

    a customizable set of options

Options Hash (options):

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

Yields:

  • (chart)

See Also:



459
460
461
462
463
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 459

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

#add_comment(options = {}) ⇒ Object

Shortcut to worsksheet_comments#add_comment



479
480
481
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 479

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

#add_conditional_formatting(cells, rules) ⇒ Object

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 }

Parameters:

  • cells (String)

    The range to apply the formatting to

  • rules (Array|Hash)

    An array of hashes (or just one) to create Conditional formatting rules from.

See Also:



420
421
422
423
424
425
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 420

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.

Parameters:

  • cells (String)

    The cells the validation will apply to.

  • data_validation (hash)

    options defining the validation to apply.

See Also:

  • for an example


432
433
434
435
436
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 432

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

Parameters:

  • options (Hash) (defaults to: {})

    for the hyperlink

Returns:

See Also:



442
443
444
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 442

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

#add_image(options = {}) {|image| ... } ⇒ Object

Adds a media item to the worksheets drawing

Parameters:

  • [Hash] (Hash)

    a customizable set of options

Yields:

  • (image)


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

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

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

Yields:



472
473
474
475
476
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 472

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

#add_row(values = [], options = {}) {|@rows.last| ... } ⇒ 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]

Parameters:

  • options (Hash) (defaults to: {})

    a customizable set of options

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:

Returns:

See Also:



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

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

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

needs documentation

Yields:



466
467
468
469
470
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 466

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

#auto_filterObject

An range that excel will apply an autfilter 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 considerd to be data.

Returns:

  • String



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

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

#auto_filter=(v) ⇒ Object

The auto filter range for the worksheet

Parameters:

  • v (String)

See Also:



325
326
327
328
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 325

def auto_filter=(v)
  DataTypeValidator.validate "Worksheet.auto_filter", String, v
  auto_filter.range = v
end

#cellsArray

convinience method to access all cells in this worksheet

Returns:

  • (Array)

    cells



231
232
233
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 231

def cells
  rows.flatten
end

#col_style(index, style, options = {}) ⇒ Object

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

Parameters:

  • index (Integer)

    the index of the column

  • style (Integer)

    the cellXfs index

  • options (Hash) (defaults to: {})
  • [Integer] (Hash)

    a customizable set of options

See Also:



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

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

#colsObject

returns the sheet data as columnw



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

def cols
  @rows.transpose
end

#column_infoSimpleTypedList

Column info for the sheet

Returns:

  • (SimpleTypedList)


143
144
145
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 143

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

#column_widths(*widths) ⇒ Object

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. 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.

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

Parameters:

  • widths (Integer|Float|Fixnum|nil)


498
499
500
501
502
503
504
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 498

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

#commentsArray|SimpleTypedList

The a shortcut to the worksheet_comments list of comments

Returns:

  • (Array|SimpleTypedList)


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

def comments
  worksheet_comments.comments if worksheet_comments.has_comments?
end

#dimensionDimension

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

Returns:



259
260
261
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 259

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

#drawingDrawing

Note:

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

The drawing associated with this worksheet.

Returns:

See Also:



358
359
360
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 358

def drawing
  worksheet_drawing.drawing
end

#fit_to_page=(v) ⇒ Boolean

Returns:

  • (Boolean)


309
310
311
312
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 309

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

#fit_to_page?Boolean

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.

Returns:

  • (Boolean)

    Boolean

See Also:



135
136
137
138
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 135

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:

Returns:

See Also:



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

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

Returns:



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

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

#indexInteger

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

Returns:

  • (Integer)


350
351
352
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 350

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

#initialize_page_options(options) ⇒ Object

Initalizes page margin, setup and print options

Parameters:

  • options (Hash)

    Options passed in from the initializer



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

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]
end

#merge_cells(cells) ⇒ Object

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"]

Parameters:

  • cells (Array, string)


244
245
246
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 244

def merge_cells(cells)
  merged_cells.add cells
end

#nameString

The name of the worksheet

Returns:

  • (String)


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

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

#name=(name) ⇒ Object

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

Parameters:

  • name (String)


317
318
319
320
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 317

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

Parameters:

  • name (String)

    The cell or cell range to return. "A1" will return the first cell of the first row.

Returns:



592
593
594
595
596
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 592

def name_to_cell(name)
  col_index, row_index = *Axlsx::name_to_indices(name)
  r = rows[row_index]
  r.cells[col_index] if r
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 Oulining is what lets you add collapse and expand to a data set.

Parameters:

  • start_index (Integer)

    The zero based index of the first column of outlining.

  • end_index (Integer)

    The zero based index of the last column to be outlined

  • level (integer) (defaults to: 1)

    The level of outline to apply

  • collapsed (Integer) (defaults to: true)

    The initial collapsed state of the outline group



627
628
629
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 627

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 Oulining is what lets you add collapse and expand to a data set.

Parameters:

  • start_index (Integer)

    The zero based index of the first row of outlining.

  • end_index (Integer)

    The zero based index of the last row to be outlined

  • level (integer) (defaults to: 1)

    The level of outline to apply

  • collapsed (Integer) (defaults to: true)

    The initial collapsed state of the outline group



617
618
619
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 617

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.

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:

Returns:

See Also:



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

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.

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:

Returns:

See Also:



186
187
188
189
190
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 186

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

#pivot_tablesArray

The pivot tables in this worksheet

Returns:

  • (Array)

    of Table



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

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

#pnString

The part name of this worksheet

Returns:

  • (String)


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

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:

Returns:

See Also:



208
209
210
211
212
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 208

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

#protect_range(cells) ⇒ ProtectedRange

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.

Parameters:

  • cells (String|Array)

    The string reference for the cells to protect or an array of cells.

Returns:



252
253
254
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 252

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

#relationshipsRelationships

The worksheet relationships. This is managed automatically by the worksheet

Returns:



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

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

#relationships_index_of(object) ⇒ Integer

identifies the index of an object withing the collections used in generating relationships for the worksheet

Parameters:

  • object (Any)

    the object to search for

Returns:

  • (Integer)

    The index of the object



571
572
573
574
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 571

def relationships_index_of(object)
  objects = [tables.to_a, worksheet_comments.comments.to_a, hyperlinks.to_a, worksheet_drawing.drawing].flatten.compact || []
  objects.index(object)
end

#rels_pnString

The relationship part name of this worksheet

Returns:

  • (String)


338
339
340
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 338

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

#rIdString

The relationship Id of thiw worksheet

Returns:

  • (String)


344
345
346
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 344

def rId
  "rId#{index+1}"
end

#row_style(index, style, options = {}) ⇒ Object

Note:

You can also specify the style in the add_row call

Set the style for cells in a specific row

Parameters:

  • index (Integer)

    or range of indexes in the table

  • style (Integer)

    the cellXfs index

  • options (Hash) (defaults to: {})

    the options used when applying the style

  • [Integer] (Hash)

    a customizable set of options

See Also:



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

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

#rowsSimpleTypedList

Note:

The recommended way to manage rows is Worksheet#add_row

The rows in this worksheet

Returns:

  • (SimpleTypedList)

See Also:



113
114
115
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 113

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

#sanitize(str) ⇒ String

returns the provided string with all invalid control charaters removed.

Parameters:

  • str (String)

    The sting to process

Returns:

  • (String)


552
553
554
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 552

def sanitize(str)
  str.gsub(CONTROL_CHAR_REGEX, '')
end

#selectedObject

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.

Returns:

  • Boolean



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

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

#selected=(v) ⇒ Boolean

Deprecated.

Use SheetView#tab_selected= instead.

Returns:

  • (Boolean)

See Also:



283
284
285
286
287
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 283

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

#sheet_calc_prSheetCalcPr

The sheet calculation properties

Returns:



50
51
52
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 50

def sheet_calc_pr
  @sheet_calc_pr ||= SheetCalcPr.new
end

#sheet_format_prSheetFormatPr

The sheet format pr for this worksheet

Returns:

See Also:

  • [SheetFormatPr]


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

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

#sheet_prSheetPr

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

Returns:



266
267
268
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 266

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

#sheet_protection {|@sheet_protection| ... } ⇒ SheetProtection

The sheet protection object for this workbook

Yields:

Returns:

See Also:



57
58
59
60
61
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 57

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

Yields:

Returns:

See Also:

  • [SheetView]


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

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

#show_gridlinesObject

Deprecated.

Use SheetView#show_grid_lines instead.

Indicates if the worksheet should show gridlines or not

Returns:

  • Boolean



292
293
294
295
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 292

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

#show_gridlines=(v) ⇒ Boolean

Deprecated.

Use SheetView#show_grid_lines= instead.

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

Returns:

  • (Boolean)


274
275
276
277
278
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 274

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

#stylesObject

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'


607
608
609
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 607

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

#tablesArray

The tables in this worksheet

Returns:

  • (Array)

    of Table



87
88
89
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 87

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

#to_xml_stringString

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

Returns:

  • (String)


537
538
539
540
541
542
543
544
545
546
# File 'lib/axlsx/workbook/worksheet/worksheet.rb', line 537

def to_xml_string
  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>'
  sanitize(str)
end