lib/roo/generic_spreadsheet.rb in roo-1.3.11 vs lib/roo/generic_spreadsheet.rb in roo-1.9.0
- old
+ new
@@ -1,5 +1,6 @@
+# encoding: utf-8
require 'rubygems'
require 'builder'
# Base class for all other types of spreadsheets
class GenericSpreadsheet
@@ -311,11 +312,11 @@
# Returns information of the spreadsheet document and all sheets within
# this document.
def info
result = "File: #{File.basename(@filename)}\n"+
"Number of sheets: #{sheets.size}\n"+
- "Sheets: #{sheets.map{|sheet| sheet+", "}.to_s[0..-3]}\n"
+ "Sheets: #{sheets.join(', ')}\n"
n = 1
sheets.each {|sheet|
self.default_sheet = sheet
result << "Sheet " + n.to_s + ":\n"
unless first_row
@@ -357,9 +358,36 @@
end
}
xml_document
end
+ # when a method like spreadsheet.a42 is called
+ # convert it to a call of spreadsheet.cell('a',42)
+ def method_missing(m, *args)
+ # #aa42 => #cell('aa',42)
+ # #aa42('Sheet1') => #cell('aa',42,'Sheet1')
+ if m =~ /^([a-z]+)(\d)$/
+ col = GenericSpreadsheet.letter_to_number($1)
+ row = $2.to_i
+ if args.size > 0
+ return cell(row,col,args[0])
+ else
+ return cell(row,col)
+ end
+# else
+# geht noch nicht, weil label unterhalb (in Openoffice) dieser Klasse
+# es definiert ist
+# p "Label #{m} angesprochen?"
+# row,col,sheet = label('anton')
+# # row,col,sheet = label(m)
+# p "row: #{row}"
+# p "col: #{col}"
+# p "sheet: #{sheet}"
+# return cell(row,col)
+ end
+ raise ArgumentError, "Method #{m} missing. Args: #{args}"
+ end
+
protected
def file_type_check(filename, ext, name)
new_expression = {
'.ods' => 'Openoffice.new',