Class: Writexlsx::Workbook

Inherits:
Object
  • Object
show all
Includes:
Utility
Defined in:
lib/write_xlsx/workbook.rb

Direct Known Subclasses

WriteXLSX

Constant Summary collapse

EMPTY_HASH =

Add a string to the shared string table, if it isn’t already there, and return the string index.

{}.freeze

Constants included from Utility

Utility::CHAR_WIDTHS, Utility::COL_MAX, Utility::DEFAULT_COL_PIXELS, Utility::MAX_DIGIT_WIDTH, Utility::PADDING, Utility::PERL_TRUE_VALUES, Utility::ROW_MAX, Utility::SHEETNAME_MAX, Utility::STR_MAX

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utility

#absolute_char, #check_dimensions, #check_dimensions_and_update_max_min_values, #check_parameter, #color, #convert_date_time, #convert_font_args, #dash_types, delete_files, #escape_url, #fill_properties, #float_to_str, #get_font_latin_attributes, #get_font_style_attributes, #layout_properties, #legend_properties, #line_fill_properties, #line_properties, #palette_color_from_index, #params_to_font, #pattern_properties, #pixels_to_points, #ptrue?, #put_deprecate_message, #quote_sheetname, #r_id_attributes, #row_col_notation, #shape_style_base, #store_col_max_min_values, #store_row_max_min_values, #substitute_cellref, #underline_attributes, #v_shape_attributes_base, #v_shape_style_base, #value_or_raise, #write_a_body_pr, #write_a_def_rpr, #write_a_end_para_rpr, #write_a_lst_style, #write_a_p_formula, #write_a_p_pr_formula, #write_a_solid_fill, #write_a_srgb_clr, #write_anchor, #write_auto_fill, #write_color, #write_comment_path, #write_def_rpr_r_pr_common, #write_div, #write_fill, #write_font, #write_stroke, #write_tx_pr, #write_xml_declaration, #xl_cell_to_rowcol, #xl_col_to_name, #xl_range, #xl_range_formula, #xl_rowcol_to_cell, #xl_string_pixel_width

Constructor Details

#initialize(file, *option_params) ⇒ Workbook

Returns a new instance of Workbook.



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/write_xlsx/workbook.rb', line 47

def initialize(file, *option_params)
  options, default_formats = process_workbook_options(*option_params)
  @options = options.dup                    # for test
  @default_formats = default_formats.dup    # for test
  @writer = Package::XMLWriterSimple.new

  @file = file
  @tempdir = options[:tempdir] ||
             File.join(
               Dir.tmpdir,
               Digest::MD5.hexdigest("#{Time.now.to_f}-#{Process.pid}")
             )
  @date_1904           = options[:date_1904] || false
  @activesheet         = 0
  @firstsheet          = 0
  @selected            = 0
  @fileclosed          = false
  @worksheets          = Sheets.new
  @charts              = []
  @drawings            = []
  @formats             = Formats.new
  @xf_formats          = []
  @dxf_formats         = []
  @num_formats         = []
  @defined_names       = []
  @named_ranges        = []
  @custom_colors       = []
  @doc_properties      = {}
  @custom_properties   = []
  @optimization        = options[:optimization] || 0
  @x_window            = 240
  @y_window            = 15
  @window_width        = 16_095
  @window_height       = 9_660
  @tab_ratio           = 600
  @excel2003_style     = options[:excel2003_style] || false
  @image_types         = {}
  @images              = []
  @strings_to_urls     = options[:strings_to_urls].nil? || options[:strings_to_urls] ? true : false

  @max_url_length      = MAX_URL_LENGTH
  @has_comments        = false
  @read_only           = 0
  @has_metadata        = false
  @has_embedded_images = false
  @has_embedded_descriptions = false

  if options[:max_url_length]
    @max_url_length = options[:max_url_length].to_i

    @max_url_length = MAX_URL_LENGTH if @max_url_length < 255
  end

  # Structures for the shared strings data.
  @shared_strings = Package::SharedStrings.new

  # Structures for embedded images.
  @embedded_image_indexes = {}
  @embedded_images        = []

  # Formula calculation default settings.
  @calc_id             = 124519
  @calc_mode           = 'auto'
  @calc_on_load        = true

  if @excel2003_style
    add_format(default_formats.merge(
                 xf_index:    0,
                 font_family: 0,
                 font:        'Arial',
                 size:        10,
                 theme:       -1
               ))
  else
    add_format(default_formats.merge(xf_index: 0))
  end

  # Add a default URL format.
  @default_url_format = add_format(hyperlink: 1)

  set_color_palette
end

Instance Attribute Details

#activesheetObject

:nodoc:



612
613
614
# File 'lib/write_xlsx/workbook.rb', line 612

def activesheet # :nodoc:
  @activesheet ||= 0
end

#chartsObject

:nodoc:



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

def charts
  @charts
end

#custom_propertiesObject (readonly)

:nodoc:



33
34
35
# File 'lib/write_xlsx/workbook.rb', line 33

def custom_properties
  @custom_properties
end

#default_url_formatObject (readonly) Also known as: get_default_url_format

Get the default url format used when a user defined format isn’t specified with write_url(). The format is the hyperlink style defined by Excel for the default theme.



505
506
507
# File 'lib/write_xlsx/workbook.rb', line 505

def default_url_format
  @default_url_format
end

#doc_propertiesObject (readonly)

:nodoc:



32
33
34
# File 'lib/write_xlsx/workbook.rb', line 32

def doc_properties
  @doc_properties
end

#drawingsObject

:nodoc:



30
31
32
# File 'lib/write_xlsx/workbook.rb', line 30

def drawings
  @drawings
end

#embedded_descriptionsObject (readonly)

:nodoc:



43
44
45
# File 'lib/write_xlsx/workbook.rb', line 43

def embedded_descriptions
  @embedded_descriptions
end

#embedded_image_indexesObject (readonly)

:nodec:



41
42
43
# File 'lib/write_xlsx/workbook.rb', line 41

def embedded_image_indexes
  @embedded_image_indexes
end

#embedded_imagesObject (readonly)

:nodoc:



42
43
44
# File 'lib/write_xlsx/workbook.rb', line 42

def embedded_images
  @embedded_images
end

#excel2003_styleObject (readonly)

:nodoc:



37
38
39
# File 'lib/write_xlsx/workbook.rb', line 37

def excel2003_style
  @excel2003_style
end

#firstsheetObject

:nodoc:



608
609
610
# File 'lib/write_xlsx/workbook.rb', line 608

def firstsheet # :nodoc:
  @firstsheet ||= 0
end

#has_embedded_descriptions=(value) ⇒ Object (writeonly)

:nodoc:



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

def has_embedded_descriptions=(value)
  @has_embedded_descriptions = value
end

#image_typesObject (readonly)

:nodoc:



34
35
36
# File 'lib/write_xlsx/workbook.rb', line 34

def image_types
  @image_types
end

#imagesObject (readonly)

:nodoc:



34
35
36
# File 'lib/write_xlsx/workbook.rb', line 34

def images
  @images
end

#max_url_lengthObject (readonly)

:nodoc:



38
39
40
# File 'lib/write_xlsx/workbook.rb', line 38

def max_url_length
  @max_url_length
end

#named_rangesObject (readonly)

:nodoc:



31
32
33
# File 'lib/write_xlsx/workbook.rb', line 31

def named_ranges
  @named_ranges
end

#paletteObject (readonly)

:nodoc:



28
29
30
# File 'lib/write_xlsx/workbook.rb', line 28

def palette
  @palette
end

#read_onlyObject (readonly)

:nodoc:



40
41
42
# File 'lib/write_xlsx/workbook.rb', line 40

def read_only
  @read_only
end

#shared_stringsObject (readonly)

:nodoc:



35
36
37
# File 'lib/write_xlsx/workbook.rb', line 35

def shared_strings
  @shared_strings
end

#strings_to_urlsObject (readonly)

:nodoc:



39
40
41
# File 'lib/write_xlsx/workbook.rb', line 39

def strings_to_urls
  @strings_to_urls
end

#vba_projectObject (readonly)

:nodoc:



36
37
38
# File 'lib/write_xlsx/workbook.rb', line 36

def vba_project
  @vba_project
end

#worksheetsObject (readonly)

:nodoc:



29
30
31
# File 'lib/write_xlsx/workbook.rb', line 29

def worksheets
  @worksheets
end

#writerObject (readonly)

Returns the value of attribute writer.



542
543
544
# File 'lib/write_xlsx/workbook.rb', line 542

def writer
  @writer
end

Instance Method Details

#add_chart(params = {}) ⇒ Object

This method is use to create a new chart either as a standalone worksheet (the default) or as an embeddable object that can be inserted into a worksheet via the insert_chart method.



252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'lib/write_xlsx/workbook.rb', line 252

def add_chart(params = {})
  # Type must be specified so we can create the required chart instance.
  type     = params[:type]
  embedded = params[:embedded]
  name     = params[:name]
  raise "Must define chart type in add_chart()" unless type

  chart = Chart.factory(type, params[:subtype])
  chart.palette = @palette

  # If the chart isn't embedded let the workbook control it.
  if ptrue?(embedded)
    chart.name = name if name

    # Set index to 0 so that the activate() and set_first_sheet() methods
    # point back to the first worksheet if used for embedded charts.
    chart.index = 0
    chart.set_embedded_config_data
  else
    # Check the worksheet name for non-embedded charts.
    sheetname  = check_chart_sheetname(name)
    chartsheet = Chartsheet.new(self, @worksheets.size, sheetname)
    chartsheet.chart = chart
    @worksheets << chartsheet
  end
  @charts << chart
  ptrue?(embedded) ? chart : chartsheet
end

#add_format(property_hash = {}) ⇒ Object

The add_format method can be used to create new Format objects which are used to apply formatting to a cell. You can either define the properties at creation time via a hash of property values or later via method calls.

format1 = workbook.add_format(property_hash) # Set properties at creation
format2 = workbook.add_format                # Set properties later


290
291
292
293
294
295
296
297
298
299
300
# File 'lib/write_xlsx/workbook.rb', line 290

def add_format(property_hash = {})
  properties = {}
  properties.update(font: 'Arial', size: 10, theme: -1) if @excel2003_style
  properties.update(property_hash)

  format = Format.new(@formats, properties)

  @formats.formats.push(format)    # Store format reference

  format
end

#add_shape(properties = {}) ⇒ Object

The add_shape method can be used to create new shapes that may be inserted into a worksheet.



306
307
308
309
310
311
312
313
# File 'lib/write_xlsx/workbook.rb', line 306

def add_shape(properties = {})
  shape = Shape.new(properties)
  shape.palette = @palette

  @shapes ||= []
  @shapes << shape  # Store shape reference.
  shape
end

#add_vba_project(vba_project) ⇒ Object

The add_vba_project method can be used to add macros or functions to an WriteXLSX file using a binary VBA project file that has been extracted from an existing Excel xlsm file.



465
466
467
# File 'lib/write_xlsx/workbook.rb', line 465

def add_vba_project(vba_project)
  @vba_project = vba_project
end

#add_worksheet(name = '') ⇒ Object

At least one worksheet should be added to a new workbook. A worksheet is used to write data into cells:



240
241
242
243
244
245
# File 'lib/write_xlsx/workbook.rb', line 240

def add_worksheet(name = '')
  name = check_sheetname(name)
  worksheet = Worksheet.new(self, @worksheets.size, name)
  @worksheets << worksheet
  worksheet
end

#assemble_xml_fileObject

user must not use. it is internal method.



201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
# File 'lib/write_xlsx/workbook.rb', line 201

def assemble_xml_file  # :nodoc:
  return unless @writer

  # Prepare format object for passing to Style.rb.
  prepare_format_properties

  write_xml_declaration do
    # Write the root workbook element.
    write_workbook do
      # Write the XLSX file version.
      write_file_version

      # Write the fileSharing element.
      write_file_sharing

      # Write the workbook properties.
      write_workbook_pr

      # Write the workbook view properties.
      write_book_views

      # Write the worksheet names and ids.
      @worksheets.write_sheets(@writer)

      # Write the workbook defined names.
      write_defined_names

      # Write the workbook calculation properties.
      write_calc_pr

      # Write the workbook extension storage.
      # write_ext_lst
    end
  end
end

#chartsheet_countObject



570
571
572
# File 'lib/write_xlsx/workbook.rb', line 570

def chartsheet_count
  @worksheets.chartsheet_count
end

#chartsheetsObject



600
601
602
# File 'lib/write_xlsx/workbook.rb', line 600

def chartsheets
  @worksheets.chartsheets
end

#closeObject

The close method is used to close an Excel file.



133
134
135
136
137
138
139
# File 'lib/write_xlsx/workbook.rb', line 133

def close
  # In case close() is called twice.
  return if @fileclosed

  @fileclosed = true
  store_workbook
end

#date_1904?Boolean

:nodoc:

Returns:

  • (Boolean)


544
545
546
547
# File 'lib/write_xlsx/workbook.rb', line 544

def date_1904? # :nodoc:
  @date_1904 ||= false
  !!@date_1904
end

#define_name(name, formula) ⇒ Object

Create a defined name in Excel. We handle global/workbook level names and local/worksheet names.



319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# File 'lib/write_xlsx/workbook.rb', line 319

def define_name(name, formula)
  sheet_index = nil
  sheetname   = ''

  # Local defined names are formatted like "Sheet1!name".
  if name =~ /^(.*)!(.*)$/
    sheetname   = ::Regexp.last_match(1)
    name        = ::Regexp.last_match(2)
    sheet_index = @worksheets.index_by_name(sheetname)
  else
    sheet_index = -1   # Use -1 to indicate global names.
  end

  # Raise if the sheet index wasn't found.
  raise "Unknown sheet name #{sheetname} in defined_name()" unless sheet_index

  # Raise if the name contains invalid chars as defined by Excel help.
  # Refer to the following to see Excel's syntax rules for defined names:
  # http://office.microsoft.com/en-001/excel-help/define-and-use-names-in-formulas-HA010147120.aspx#BMsyntax_rules_for_names
  #
  raise "Invalid characters in name '#{name}' used in defined_name()" if name =~ /\A[-0-9 !"#$%&'()*+,.:;<=>?@\[\]\^`{}~]/ || name =~ /.+[- !"#$%&'()*+,\\:;<=>?@\[\]\^`{}~]/

  # Raise if the name looks like a cell name.
  raise "Invalid name '#{name}' looks like a cell name in defined_name()" if name =~ /^[a-zA-Z][a-zA-Z]?[a-dA-D]?[0-9]+$/

  # Raise if the name looks like a R1C1
  raise "Invalid name '#{name}' like a RC cell ref in defined_name()" if name =~ /\A[rcRC]\Z/ || name =~ /\A[rcRC]\d+[rcRC]\d+\Z/

  @defined_names.push([name, sheet_index, formula.sub(/^=/, '')])
end

#get_1904Object

return date system. false = 1900, true = 1904



176
177
178
# File 'lib/write_xlsx/workbook.rb', line 176

def get_1904
  @date_1904
end

#has_dynamic_functions?Boolean

Returns:

  • (Boolean)


549
550
551
# File 'lib/write_xlsx/workbook.rb', line 549

def has_dynamic_functions?
  @has_dynamic_functions
end

#has_embedded_descriptions?Boolean

Returns:

  • (Boolean)


624
625
626
# File 'lib/write_xlsx/workbook.rb', line 624

def has_embedded_descriptions?
  @has_embedded_descriptions
end

#has_embedded_images?Boolean

Returns:

  • (Boolean)


620
621
622
# File 'lib/write_xlsx/workbook.rb', line 620

def has_embedded_images?
  @has_embedded_images
end

#has_metadata?Boolean

Returns:

  • (Boolean)


616
617
618
# File 'lib/write_xlsx/workbook.rb', line 616

def has_metadata?
  @has_metadata
end

#non_chartsheet_countObject



574
575
576
# File 'lib/write_xlsx/workbook.rb', line 574

def non_chartsheet_count
  @worksheets.worksheets.count
end

#non_chartsheetsObject



604
605
606
# File 'lib/write_xlsx/workbook.rb', line 604

def non_chartsheets
  @worksheets.worksheets
end

#num_comment_filesObject



596
597
598
# File 'lib/write_xlsx/workbook.rb', line 596

def num_comment_files
  @worksheets.select { |sheet| sheet.has_comments? }.count
end

#num_vml_filesObject



592
593
594
# File 'lib/write_xlsx/workbook.rb', line 592

def num_vml_files
  @worksheets.select { |sheet| sheet.has_vml? || sheet.has_header_vml? }.count
end

Set the Excel “Read-only recommended” save option.



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

def read_only_recommended
  @read_only = 2
end

#set_1904(mode = true) ⇒ Object

Set the date system: false = 1900 (the default), true = 1904



167
168
169
170
171
# File 'lib/write_xlsx/workbook.rb', line 167

def set_1904(mode = true)
  raise "set_1904() must be called before add_worksheet()" unless sheets.empty?

  @date_1904 = ptrue?(mode)
end

#set_calc_mode(mode, calc_id = nil) ⇒ Object

set_calc_mode()

Set the Excel caclcuation mode for the workbook.



488
489
490
491
492
493
494
495
496
497
498
# File 'lib/write_xlsx/workbook.rb', line 488

def set_calc_mode(mode, calc_id = nil)
  @calc_mode = mode || 'auto'

  if mode == 'manual'
    @calc_on_load = false
  elsif mode == 'auto_except_tables'
    @calc_mode = 'autoNoTable'
  end

  @calc_id = calc_id if calc_id
end

#set_custom_color(index, red = 0, green = 0, blue = 0) ⇒ Object

Change the RGB components of the elements in the colour palette.



511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
# File 'lib/write_xlsx/workbook.rb', line 511

def set_custom_color(index, red = 0, green = 0, blue = 0)
  # Match a HTML #xxyyzz style parameter
  if red.to_s =~ /^#(\w\w)(\w\w)(\w\w)/
    red   = ::Regexp.last_match(1).hex
    green = ::Regexp.last_match(2).hex
    blue  = ::Regexp.last_match(3).hex
  end

  # Check that the colour index is the right range
  raise "Color index #{index} outside range: 8 <= index <= 64" if index < 8 || index > 64

  # Check that the colour components are in the right range
  if (red   < 0 || red   > 255) ||
     (green < 0 || green > 255) ||
     (blue  < 0 || blue  > 255)
    raise "Color component outside range: 0 <= color <= 255"
  end

  index -= 8       # Adjust colour index (wingless dragonfly)

  # Set the RGB value
  @palette[index] = [red, green, blue]

  # Store the custome colors for the style.xml file.
  @custom_colors << sprintf("FF%02X%02X%02X", red, green, blue)

  index + 8
end

#set_custom_property(name, value, type = nil) ⇒ Object

Set a user defined custom document property.



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
# File 'lib/write_xlsx/workbook.rb', line 423

def set_custom_property(name, value, type = nil)
  # Valid types.
  valid_type = {
    'text'       => 1,
    'date'       => 1,
    'number'     => 1,
    'number_int' => 1,
    'bool'       => 1
  }

  raise "The name and value parameters must be defined in set_custom_property()" if !name || (type != 'bool' && !value)

  # Determine the type for strings and numbers if it hasn't been specified.
  unless ptrue?(type)
    type = if value =~ /^\d+$/
             'number_int'
           elsif value =~
                 /^([+-]?)(?=[0-9]|\.[0-9])[0-9]*(\.[0-9]*)?([Ee]([+-]?[0-9]+))?$/
             'number'
           else
             'text'
           end
  end

  # Check for valid validation types.
  raise "Unknown custom type '$type' in set_custom_property()" unless valid_type[type]

  #  Check for strings longer than Excel's limit of 255 chars.
  raise "Length of text custom value '$value' exceeds Excel's limit of 255 in set_custom_property()" if type == 'text' && value.length > 255

  if type == 'bool'
    value = value ? 1 : 0
  end

  @custom_properties << [name, value, type]
end

#set_properties(params) ⇒ Object

The set_properties method can be used to set the document properties of the Excel file created by WriteXLSX. These properties are visible when you use the Office Button -> Prepare -> Properties option in Excel and are also available to external applications that read or index windows files.



389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
# File 'lib/write_xlsx/workbook.rb', line 389

def set_properties(params)
  # Ignore if no args were passed.
  return -1 if params.empty?

  # List of valid input parameters.
  valid = {
    title:          1,
    subject:        1,
    author:         1,
    keywords:       1,
    comments:       1,
    last_author:    1,
    created:        1,
    category:       1,
    manager:        1,
    company:        1,
    status:         1,
    hyperlink_base: 1
  }

  # Check for valid input parameters.
  params.each_key do |key|
    return -1 unless valid.has_key?(key)
  end

  # Set the creation time unless specified by the user.
  params[:created] = @createtime unless params.has_key?(:created)

  @doc_properties = params.dup
end

#set_size(width = nil, height = nil) ⇒ Object

Set the workbook size.



353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
# File 'lib/write_xlsx/workbook.rb', line 353

def set_size(width = nil, height = nil)
  @window_width = if ptrue?(width)
                    # Convert to twips at 96 dpi.
                    width.to_i * 1440 / 96
                  else
                    16095
                  end

  @window_height = if ptrue?(height)
                     # Convert to twips at 96 dpi.
                     height.to_i * 1440 / 96
                   else
                     9660
                   end
end

#set_tab_ratio(tab_ratio = nil) ⇒ Object

Set the ratio of space for worksheet tabs.



372
373
374
375
376
377
378
379
380
# File 'lib/write_xlsx/workbook.rb', line 372

def set_tab_ratio(tab_ratio = nil)
  return unless tab_ratio

  if tab_ratio < 0 || tab_ratio > 100
    raise "Tab ratio outside range: 0 <= zoom <= 100"
  else
    @tab_ratio = (tab_ratio * 10).to_i
  end
end

#set_tempdir(dir) ⇒ Object



180
181
182
# File 'lib/write_xlsx/workbook.rb', line 180

def set_tempdir(dir)
  @tempdir = dir.dup
end

#set_vba_name(vba_codename = nil) ⇒ Object

Set the VBA name for the workbook.



472
473
474
# File 'lib/write_xlsx/workbook.rb', line 472

def set_vba_name(vba_codename = nil)
  @vba_codename = vba_codename || 'ThisWorkbook'
end

#set_xml_writer(filename) ⇒ Object

user must not use. it is internal method.



187
188
189
# File 'lib/write_xlsx/workbook.rb', line 187

def set_xml_writer(filename)  # :nodoc:
  @writer.set_xml_writer(filename)
end

#shared_string_index(str) ⇒ Object

:nodoc:



558
559
560
# File 'lib/write_xlsx/workbook.rb', line 558

def shared_string_index(str) # :nodoc:
  @shared_strings.index(str, EMPTY_HASH)
end

#shared_strings_empty?Boolean

:nodoc:

Returns:

  • (Boolean)


566
567
568
# File 'lib/write_xlsx/workbook.rb', line 566

def shared_strings_empty?  # :nodoc:
  @shared_strings.empty?
end

#sheets(*args) ⇒ Object

get array of Worksheet objects

:call-seq:

sheets              -> array of all Wordsheet object
sheets(1, 3, 4)     -> array of spcified Worksheet object.


148
149
150
151
152
153
154
# File 'lib/write_xlsx/workbook.rb', line 148

def sheets(*args)
  if args.empty?
    @worksheets
  else
    args.collect { |i| @worksheets[i] }
  end
end

#store_image_types(type) ⇒ Object

Store the image types (PNG/JPEG/etc) used in the workbook to use in these Content_Types file.



632
633
634
635
636
637
638
639
640
641
642
643
# File 'lib/write_xlsx/workbook.rb', line 632

def store_image_types(type)
  case type
  when 'png'
    @image_types[:png] = 1
  when 'jpeg'
    @image_types[:jpeg] = 1
  when 'gif'
    @image_types[:gif] = 1
  when 'bmp'
    @image_types[:bmp] = 1
  end
end

#str_uniqueObject

:nodoc:



562
563
564
# File 'lib/write_xlsx/workbook.rb', line 562

def str_unique   # :nodoc:
  @shared_strings.unique_count
end

#style_propertiesObject



578
579
580
581
582
583
584
585
586
587
588
589
590
# File 'lib/write_xlsx/workbook.rb', line 578

def style_properties
  [
    @xf_formats,
    @palette,
    @font_count,
    @num_formats,
    @border_count,
    @fill_count,
    @custom_colors,
    @dxf_formats,
    @has_comments
  ]
end

#worksheet_by_name(sheetname = nil) ⇒ Object Also known as: get_worksheet_by_name

Return a worksheet object in the workbook using the sheetname.



159
160
161
# File 'lib/write_xlsx/workbook.rb', line 159

def worksheet_by_name(sheetname = nil)
  sheets.select { |s| s.name == sheetname }.first
end

#xml_strObject

user must not use. it is internal method.



194
195
196
# File 'lib/write_xlsx/workbook.rb', line 194

def xml_str  # :nodoc:
  @writer.string
end