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.



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

def filename
  @filename
end

#is_openObject

Returns the value of attribute is_open.



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

def is_open
  @is_open
end

#tmp_fileObject

Returns the value of attribute tmp_file.



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

def tmp_file
  @tmp_file
end

Instance Method Details

#add_format(options = nil) ⇒ Object



353
354
355
356
357
# File 'lib/fast_excel.rb', line 353

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

#add_worksheet(sheetname = nil) ⇒ Object



375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
# File 'lib/fast_excel.rb', line 375

def add_worksheet(sheetname = nil)
  if !sheetname.nil?
    error = validate_worksheet_name(sheetname)
    if error != :no_error
      error_code = ERROR_ENUM.find(error)
      error_str = error_code ? Libxlsxwriter.strerror(error_code) : ''
      raise ArgumentError, "Invalid worksheet name '#{sheetname}': (#{error_code} - #{error}) #{error_str}"
    end
  end

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

#bold_cell_formatObject Also known as: bold_format



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

def bold_cell_format
  bold = add_format
  bold.set_bold
  bold
end

#closeObject



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

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

#constant_memory?Boolean

Returns:

  • (Boolean)


416
417
418
419
# File 'lib/fast_excel.rb', line 416

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

#get_worksheet_by_name(name) ⇒ Object



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

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

  sheet
end

#initialize(struct) ⇒ Object



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

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;@”



369
370
371
372
373
# File 'lib/fast_excel.rb', line 369

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

#read_stringObject



405
406
407
408
409
410
# File 'lib/fast_excel.rb', line 405

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

#remove_tmp_folderObject



412
413
414
# File 'lib/fast_excel.rb', line 412

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