Class: SheetData
Constant Summary collapse
- @@file =
nil- @@workbook =
nil
Constants included from BasicLogging
BasicLogging::DEBUG, BasicLogging::ERROR, BasicLogging::FATAL, BasicLogging::INFO, BasicLogging::Levels, BasicLogging::UNKNOWN, BasicLogging::WARN
Instance Attribute Summary
Attributes included from BasicLogging
Class Method Summary collapse
Methods included from BasicLogging
is_muted?, log, mute, set_level, set_level, set_target, set_target
Class Method Details
.workbook(file) ⇒ Object
46 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 |
# File 'lib/sheetdata.rb', line 46 def self::workbook(file) @@file = file if !@@workbook begin fm = FileMagic.mime mtype = fm.fd(File.new(file) ).split(';')[0] fm = FileMagic.fm magic = fm.fd(File.new(file) ).split(';')[0] @@workbook = case mtype when ODS_MIME debug('ODS') Roo::Spreadsheet::open(@@file, extension: :ods ) when (XLS_MIME) debug('XLS') Roo::Spreadsheet::open(@@file, extension: :xls ) when XLSX_MIME, PMDX_MIME debug('XLSX') Roo::Spreadsheet::open(@@file, extension: :xlsx ) when CSV_MIME raise IOError.new('CSV is not yet supported, sorry') else raise IOError.new('Mime-Type is ' << mtype << ' and Magic sais: ' << magic << ". Is this supposed to be a spreadsheet?") end rescue Exception => ex msg = 'ERROR! File %s is not supported: %s' %[@@file, ex.] puts msg error yellow(msg) exit false end return @@workbook end end |