Class: DYI::Chart::ExcelReader
- Inherits:
-
ArrayReader
- Object
- ArrayReader
- DYI::Chart::ExcelReader
- Defined in:
- lib/dyi/chart/excel_reader.rb,
lib/ironruby.rb
Overview
ExcelReader
class provides a interface to Microsoft Excel file and data for a chart object. Creating the instance, you should not call new
method but ExcelReader.read method.
This class requires that win32ole has been installed your system.
Constant Summary collapse
- OFFSET =
DateTime.now.offset
Class Method Summary collapse
-
.read(path, options = {}) ⇒ ExcelReader
Parses Excel file and creates instance of ExcelReader.
Instance Method Summary collapse
-
#read(path, options = {}) ⇒ Object
Parses Excel file and sets data.
Methods inherited from ArrayReader
#[], #clear_data, #each, #has_field?, #initialize, #members, #records, #records_size, #series, #values_each, #values_size
Constructor Details
This class inherits a constructor from DYI::Chart::ArrayReader
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class DYI::Chart::ArrayReader
Class Method Details
.read(path, options = {}) ⇒ ExcelReader
Parses Excel file and creates instance of ExcelReader.
117 118 119 |
# File 'lib/dyi/chart/excel_reader.rb', line 117 def read(path, ={}) new.read(path, ) end |
Instance Method Details
#read(path, options = {}) ⇒ Object
Parses Excel file and sets data.
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 |
# File 'lib/dyi/chart/excel_reader.rb', line 53 def read(path, ={}) if defined? WIN32OLE # for Windows path = WIN32OLE.new('Scripting.FileSystemObject').getAbsolutePathName(path) excel = WIN32OLE.new('Excel.Application') book = excel.workbooks.open(path) sheet = book.worksheets.item([:sheet] || 1) range = sheet.usedRange sheet_values = sheet.range(sheet.cells(1,1), sheet.cells(range.end(4).row, range.end(2).column)).value jagged_array = [] sheet_values.get_length(0).times do |i| jagged_array << [] sheet_values.get_length(1).times do |j| jagged_array[i] << sheet_values.get_value(i+1, j+1) end end sheet_values = jagged_array end begin super(sheet_values, ) ensure if defined? WIN32OLE book.close(false) excel.quit excel = sheet = nil end book = sheet_values = nil GC.start end self end |