Class: Rspreadsheet::WorkbookFlat
Instance Attribute Summary
Attributes inherited from Workbook
#filename, #xmlnode
Loading and saving related methods
collapse
Methods inherited from Workbook
#[], #create_worksheet, #create_worksheet_from_node, #mime, #mime_preferred_extension, #to_io, #worksheet_names, #worksheets, #worksheets_count, #write_ods_to_io, #xmldoc
Constructor Details
#initialize(afilename = nil) ⇒ WorkbookFlat
Returns a new instance of WorkbookFlat.
193
194
195
196
197
198
199
200
201
|
# File 'lib/rspreadsheet/workbook.rb', line 193
def initialize(afilename=nil)
@worksheets=[]
@filename = afilename
@xml_doc = LibXML::XML::Document.file(@filename || FLAT_TEMPLATE_FILE_NAME)
@xmlnode = @xml_doc.find_first('//office:spreadsheet')
@xmlnode.find('./table:table').each do |node|
create_worksheet_from_node(node)
end
end
|
Instance Method Details
221
|
# File 'lib/rspreadsheet/workbook.rb', line 221
def flat_format?; true end
|
222
|
# File 'lib/rspreadsheet/workbook.rb', line 222
def normal_format?; false end
|
#save(io = nil) ⇒ Object
Also known as:
save_to_io, save_as
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
# File 'lib/rspreadsheet/workbook.rb', line 203
def save(io=nil)
case
when @filename.nil? && io.nil?
raise 'New file should be named on first save, please provide filename (or IO).'
when @filename.kind_of?(String) && io.nil?
@xml_doc.save(@filename)
when (@filename.kind_of?(String) && (io.kind_of?(String) || io.kind_of?(File)))
@filename = (io.kind_of?(File)) ? io.path : io
@xml_doc.save(@filename)
when io.kind_of?(IO) || io.kind_of?(String) || io.kind_of?(StringIO)
IO.write(io,@xml_doc.to_s)
io.rewind if io.kind_of?(StringIO)
else raise 'Invalid combinations of parameter types in save'
end
end
|