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.



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

def filename
  @filename
end

#is_openObject

Returns the value of attribute is_open.



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

def is_open
  @is_open
end

#tmp_fileObject

Returns the value of attribute tmp_file.



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

def tmp_file
  @tmp_file
end

Instance Method Details

#add_format(options = nil) ⇒ Object



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

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

#add_worksheet(sheetname = nil) ⇒ Object



368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
# File 'lib/fast_excel.rb', line 368

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



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

def bold_cell_format
  bold = add_format
  bold.set_bold
  bold
end

#closeObject



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

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

#constant_memory?Boolean

Returns:

  • (Boolean)


409
410
411
412
# File 'lib/fast_excel.rb', line 409

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

#get_worksheet_by_name(name) ⇒ Object



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

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

  sheet
end

#initialize(struct) ⇒ Object



339
340
341
342
343
344
# File 'lib/fast_excel.rb', line 339

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



362
363
364
365
366
# File 'lib/fast_excel.rb', line 362

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

#read_stringObject



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

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

#remove_tmp_folderObject



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

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