Module: FastExcel::WorkbookExt

Includes:
AttributeHelper
Defined in:
lib/fast_excel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from AttributeHelper

#fields_hash, #pretty_print, #set

Instance Attribute Details

#filenameObject

Returns the value of attribute filename


333
334
335
# File 'lib/fast_excel.rb', line 333

def filename
  @filename
end

#is_openObject

Returns the value of attribute is_open


333
334
335
# File 'lib/fast_excel.rb', line 333

def is_open
  @is_open
end

#tmp_fileObject

Returns the value of attribute tmp_file


333
334
335
# File 'lib/fast_excel.rb', line 333

def tmp_file
  @tmp_file
end

Instance Method Details

#add_format(options = nil) ⇒ Object


342
343
344
345
346
# File 'lib/fast_excel.rb', line 342

def add_format(options = nil)
  new_format = super()
  new_format.set(options) if options
  new_format
end

#add_worksheet(sheetname = nil) ⇒ Object


364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
# File 'lib/fast_excel.rb', line 364

def add_worksheet(sheetname = nil)
  if !sheetname.nil?
    if sheetname.length > Libxlsxwriter::SHEETNAME_MAX
      raise ArgumentError, "Worksheet name '#{sheetname}' exceeds Excel's limit of #{Libxlsxwriter::SHEETNAME_MAX} characters"
    elsif @sheet_names.include?(sheetname)
      raise ArgumentError, "Worksheet name '#{sheetname}' is already in use"
    end
  end

  sheet = super(sheetname)
  sheet.workbook = self
  @sheets << sheet
  @sheet_names << sheet[:name]
  sheet
end

#bold_cell_formatObject Also known as: bold_format


348
349
350
351
352
# File 'lib/fast_excel.rb', line 348

def bold_cell_format
  bold = add_format
  bold.set_bold
  bold
end

#closeObject


387
388
389
390
391
# File 'lib/fast_excel.rb', line 387

def close
  @is_open = false
  @sheets.each(&:close)
  super
end

#constant_memory?Boolean

Returns:

  • (Boolean)

404
405
406
407
# File 'lib/fast_excel.rb', line 404

def constant_memory?
  #FastExcel.print_ffi_obj(self[:options])
  @constant_memory ||= self[:options][:constant_memory] != 0
end

#get_worksheet_by_name(name) ⇒ Object


380
381
382
383
384
385
# File 'lib/fast_excel.rb', line 380

def get_worksheet_by_name(name)
  sheet = super(name)
  sheet.workbook = self

  sheet
end

#initialize(struct) ⇒ Object


335
336
337
338
339
340
# File 'lib/fast_excel.rb', line 335

def initialize(struct)
  @is_open = true
  @sheet_names = Set.new
  @sheets = []
  super(struct)
end

#number_format(pattern) ⇒ Object

“#,##0.00” “[$-409]m/d/yy h:mm AM/PM;@”


358
359
360
361
362
# File 'lib/fast_excel.rb', line 358

def number_format(pattern)
  format = add_format
  format.set_num_format(pattern)
  format
end

#read_stringObject


393
394
395
396
397
398
# File 'lib/fast_excel.rb', line 393

def read_string
  close if @is_open
  File.open(filename, 'rb', &:read)
ensure
  remove_tmp_folder
end

#remove_tmp_folderObject


400
401
402
# File 'lib/fast_excel.rb', line 400

def remove_tmp_folder
  FileUtils.remove_entry(File.dirname(filename)) if tmp_file
end