Class: Excelgrip::Workbook

Inherits:
GripWrapper show all
Defined in:
lib/excelgrip.rb

Overview

Workbook Class =================

Instance Method Summary collapse

Methods inherited from GripWrapper

#initialize, #inspect, #raw

Constructor Details

This class inherits a constructor from Excelgrip::GripWrapper

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Excelgrip::GripWrapper

Instance Method Details

#[](sheet_name) ⇒ Object Also known as: open_sheet



104
105
106
107
108
# File 'lib/excelgrip.rb', line 104

def [](sheet_name)
  raw_worksheet = @raw_object.Worksheets(sheet_name)
  raw_worksheet.Activate
  Worksheet.new(raw_worksheet)
end

#add_sheet(source_sheet) ⇒ Object



122
123
124
125
126
127
# File 'lib/excelgrip.rb', line 122

def add_sheet(source_sheet)
  last_sheet_no = @raw_object.worksheets.count
  source_sheet.copy({'after' => @raw_object.worksheets(last_sheet_no)})
  raw_worksheet = @raw_object.sheets(last_sheet_no + 1)
  Worksheet.new(raw_worksheet)
end

#closeObject



145
146
147
148
# File 'lib/excelgrip.rb', line 145

def close
  @raw_object.Close
  @raw_object = nil
end

#each_sheetObject



134
135
136
137
138
139
# File 'lib/excelgrip.rb', line 134

def each_sheet
  @raw_object.worksheets.each {|raw_worksheet|
    raw_worksheet.Activate
    yield Worksheet.new(raw_worksheet)
  }
end

#parentObject



141
142
143
# File 'lib/excelgrip.rb', line 141

def parent
  @raw_object.parent
end

#save(filename) ⇒ Object



129
130
131
132
# File 'lib/excelgrip.rb', line 129

def save(filename)
  fullpath = FileSystemObject.instance.fullpath(filename)
  @raw_object.saveAs({'filename'=>fullpath})
end

#worksheets(index = nil) ⇒ Object Also known as: sheets



112
113
114
115
116
117
118
# File 'lib/excelgrip.rb', line 112

def worksheets(index=nil)
  if index
    self[index]
  else
    Worksheets.new(@raw_object.worksheets)
  end
end