Class: Spreadsheet::Excel::Workbook

Inherits:
Workbook
  • Object
show all
Includes:
Spreadsheet::Encodings, Offset
Defined in:
lib/spreadsheet/excel/workbook.rb,
lib/spreadsheet/excel.rb

Overview

Excel-specific Workbook methods. These are mostly pertinent to the Excel reader. You should have no reason to use any of these.

Direct Known Subclasses

ExcelCompatibleWorkbook

Constant Summary collapse

BIFF_VERSIONS =
{
  0x000 => 2,
  0x007 => 2,
  0x200 => 2,
  0x300 => 3,
  0x400 => 4,
  0x500 => 5,
  0x600 => 8
}
VERSION_STRINGS =
{
  0x600 => "Microsoft Excel 97/2000/XP",
  0x500 => "Microsoft Excel 95"
}

Instance Attribute Summary collapse

Attributes included from Offset

#changes, #offsets

Attributes inherited from Workbook

#active_worksheet, #default_format, #encoding, #fonts, #formats, #io, #palette, #version, #worksheets

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Offset

append_features

Methods included from Compatibility

#ivar_name, #method_name

Methods inherited from Workbook

#add_font, #add_format, #create_worksheet, #delete_worksheet, #font, #format, #set_custom_color, #sheet_count, #worksheet, #write, #writer

Constructor Details

#initialize(*args) ⇒ Workbook

Returns a new instance of Workbook.



35
36
37
38
39
40
41
42
43
44
# File 'lib/spreadsheet/excel/workbook.rb', line 35

def initialize *args
  super
  enc = "UTF-16LE"
  if RUBY_VERSION >= "1.9"
    enc = Encoding.find enc
  end
  @encoding = enc
  @version = 0x600
  @sst = []
end

Instance Attribute Details

#bofObject

Returns the value of attribute bof.



29
30
31
# File 'lib/spreadsheet/excel/workbook.rb', line 29

def bof
  @bof
end

#date_baseObject



68
69
70
# File 'lib/spreadsheet/excel/workbook.rb', line 68

def date_base
  @date_base ||= DateTime.new 1899, 12, 31
end

#oleObject

Returns the value of attribute ole.



29
30
31
# File 'lib/spreadsheet/excel/workbook.rb', line 29

def ole
  @ole
end

Class Method Details

.open(io, opts = {}) ⇒ Object



31
32
33
# File 'lib/spreadsheet/excel/workbook.rb', line 31

def self.open io, opts = {}
  Reader.new(opts).read(io)
end

Instance Method Details

#add_shared_string(str) ⇒ Object



46
47
48
# File 'lib/spreadsheet/excel/workbook.rb', line 46

def add_shared_string str
  @sst.push str
end

#add_worksheet(worksheet) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/spreadsheet/excel.rb', line 24

def add_worksheet name
  if name.is_a? String
    create_worksheet name: name
  else
    super
  end
end

#biff_versionObject



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/spreadsheet/excel/workbook.rb', line 55

def biff_version
  case @bof
  when 0x009
    2
  when 0x209
    3
  when 0x409
    4
  else
    BIFF_VERSIONS.fetch(@version) { raise "Unkown BIFF_VERSION '#{@version}'" }
  end
end

#inspectObject



72
73
74
# File 'lib/spreadsheet/excel/workbook.rb', line 72

def inspect
  worksheets
end

#shared_string(idx) ⇒ Object



76
77
78
# File 'lib/spreadsheet/excel/workbook.rb', line 76

def shared_string idx
  @sst[idx.to_i].content
end

#sst_sizeObject



80
81
82
# File 'lib/spreadsheet/excel/workbook.rb', line 80

def sst_size
  @sst.size
end

#uninspect_variablesObject



84
85
86
# File 'lib/spreadsheet/excel/workbook.rb', line 84

def uninspect_variables
  super.push "@sst", "@offsets", "@changes"
end

#version_stringObject



88
89
90
# File 'lib/spreadsheet/excel/workbook.rb', line 88

def version_string
  client VERSION_STRINGS.fetch(@version, "Unknown"), "UTF-8"
end