Method: Spreadsheet::Excel::Reader#setup

Defined in:
lib/spreadsheet/excel/reader.rb

#setup(io) ⇒ Object



1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
# File 'lib/spreadsheet/excel/reader.rb', line 1315

def setup io
  ## Reading from StringIO fails without forced encoding
  if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new("2.3.0")
    io.set_encoding("ASCII-8BIT")
  elsif io.respond_to?(:string) && (str = io.string) && str.respond_to?(:force_encoding)
    str.force_encoding("ASCII-8BIT")
  end
  io.rewind
  @ole = Ole::Storage.open io
  @workbook = Workbook.new io, {}
  %w[Book Workbook BOOK WORKBOOK book workbook].any? do |name|
    @book = begin
      @ole.file.open(name)
    rescue
      false
    end
  end
  raise "could not locate a workbook, possibly an empty file passed" unless @book
  @data = @book.read
  read_bof
  @workbook.ole = @book
  @workbook.bof = @bof
  @workbook.version = @version
  biff = @workbook.biff_version
  extend_reader biff
  extend_internals biff
end