class ReadXls::Spreadsheet
Constants
- ParsingFailedError
Attributes
biff[RW]
position[RW]
workbook[RW]
Public Class Methods
new(ole)
click to toggle source
# File lib/read_xls/spreadsheet.rb, line 13 def initialize(ole) self.position = 0 self.biff = ole.file.read("Workbook") self.workbook = parse_workbook ensure ole.close end
parse(xls_file_path)
click to toggle source
# File lib/read_xls/spreadsheet.rb, line 7 def self.parse(xls_file_path) new( Ole::Storage.open(xls_file_path, "rb") ) end
Public Instance Methods
parse_workbook()
click to toggle source
# File lib/read_xls/spreadsheet.rb, line 25 def parse_workbook workbook_builder = WorkbookBuilder.new(biff) loop do record_number = read_word break if record_number == ::ReadXls::RecordHandler::EOF record_length = read_word record_data = read_data(record_length) ::ReadXls::RecordHandler.call( record_number, workbook_builder, biff, record_data ) end workbook_builder.build end
read_data(bytes)
click to toggle source
# File lib/read_xls/spreadsheet.rb, line 46 def read_data(bytes) val = biff.byteslice(position, bytes) self.position += bytes val end
read_word()
click to toggle source
# File lib/read_xls/spreadsheet.rb, line 52 def read_word val = biff.byteslice(position, 2).unpack("v") self.position += 2 val.first || raise(ParsingFailedError, "expected to get value, got nil") end
sheets()
click to toggle source
# File lib/read_xls/spreadsheet.rb, line 21 def sheets workbook.worksheets end