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

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.



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

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.



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

def bof
  @bof
end

#date_baseObject



62
63
64
# File 'lib/spreadsheet/excel/workbook.rb', line 62

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

#oleObject

Returns the value of attribute ole.



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

def ole
  @ole
end

Class Method Details

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



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

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

Instance Method Details

#add_shared_string(str) ⇒ Object



43
44
45
# File 'lib/spreadsheet/excel/workbook.rb', line 43

def add_shared_string str
  @sst.push str
end

#add_worksheet(worksheet) ⇒ Object



21
22
23
24
25
26
27
# File 'lib/spreadsheet/excel.rb', line 21

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

#biff_versionObject



50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/spreadsheet/excel/workbook.rb', line 50

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



65
66
67
# File 'lib/spreadsheet/excel/workbook.rb', line 65

def inspect
  self.worksheets
end

#shared_string(idx) ⇒ Object



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

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

#sst_sizeObject



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

def sst_size
  @sst.size
end

#uninspect_variablesObject



74
75
76
# File 'lib/spreadsheet/excel/workbook.rb', line 74

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

#version_stringObject



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

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