Browse files

fix failing 2003xml tests

  • Loading branch information...
1 parent 2267dc6 commit 4d64ee7fdbae16d86607cfb9c600b3bd226353bc @hmcgowan hmcgowan committed Dec 30, 2009
Showing with 32 additions and 46 deletions.
  1. +2 −2 lib/roo.rb
  2. +13 −5 lib/roo/excel2003xml.rb
  3. +2 −1 lib/roo/generic_spreadsheet.rb
  4. +15 −38 test/test_roo.rb
View
4 lib/roo.rb
@@ -10,7 +10,7 @@ def open(file)
when '.ods'
Openoffice.new(file)
when '.xml'
- Excel2003.new(file)
+ Excel2003XML.new(file)
when ''
Google.new(file)
else
@@ -28,5 +28,5 @@ def open(file)
require 'roo/excel'
require 'roo/excelx'
require 'roo/google'
-require 'roo/excel2003'
+require 'roo/excel2003xml'
require 'roo/roo_rails_helper'
View
18 lib/roo/excel2003xml.rb
@@ -5,7 +5,7 @@
require 'base64'
require 'cgi'
-class Excel2003 < GenericSpreadsheet
+class Excel2003XML < GenericSpreadsheet
@@nr = 0
@@ -244,7 +244,8 @@ def read_cells(sheet=nil)
ws.find('.//ss:Row').each do |r|
skip_to_row = r.attributes['Index'].to_i
row = skip_to_row if skip_to_row > 0
- r.each do |c|
+ r.each do |c|
+ next unless c.name == 'Cell'
skip_to_col = c.attributes['Index'].to_i
col = skip_to_col if skip_to_col > 0
c.each_element do |cell|
@@ -279,7 +280,14 @@ def read_cells(sheet=nil)
when :number
v = v.to_f
vt = :float
- when :string, :datetime,'', nil
+ when :datetime
+ if v =~ /^1899-12-31T(\d{2}:\d{2}:\d{2})/
+ v = $1
+ vt = :time
+ elsif v =~ /([^T]+)T00:00:00.000/
+ v = $1
+ vt = :date
+ end
when :boolean
v = cell.attributes['boolean-value']
else
@@ -291,10 +299,10 @@ def read_cells(sheet=nil)
# puts row
# puts col
# puts '---'
- set_cell_values(sheet,col,row,0,v,vt.to_sym,formula,cell,str_v,style_name)
end
+ set_cell_values(sheet,col,row,0,v,vt.to_sym,formula,cell,str_v,style_name)
end
- col += 1 if c.name == 'Cell'
+ col += 1
end
row += 1
col = 1
View
3 lib/roo/generic_spreadsheet.rb
@@ -604,7 +604,7 @@ def one_cell_output(onecelltype,onecell,empty)
else
raise "unhandled onecell-class "+onecell.class.to_s
end
- when :date, :date
+ when :date
str << onecell.to_s
when :time
str << GenericSpreadsheet.integer_to_timestring(onecell)
@@ -617,6 +617,7 @@ def one_cell_output(onecelltype,onecell,empty)
# converts an integer value to a time string like '02:05:06'
def self.integer_to_timestring(content)
+ return content if String === content
h = (content/3600.0).floor
content = content - h*3600
m = (content/60.0).floor
View
53 test/test_roo.rb
@@ -128,10 +128,10 @@ def minutes
class TestRoo < Test::Unit::TestCase
- OPENOFFICE = false # do Openoffice-Spreadsheet Tests?
- EXCEL = false # do Excel Tests?
+ OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
+ EXCEL = true # do Excel Tests?
GOOGLE = false # do Google-Spreadsheet Tests?
- EXCELX = false # do Excel-X Tests? (.xlsx-files)
+ EXCELX = true # do Excel-X Tests? (.xlsx-files)
EXCEL2003XML = true # do MS2003 XML tests
ONLINE = true
@@ -260,13 +260,8 @@ def test_cells
assert_equal 12, oo.cell(4,'C')
assert_equal 13, oo.cell(4,'D')
assert_equal 14, oo.cell(4,'E')
- if EXCEL2003XML
- assert_equal :datetime, oo.celltype(5,1)
- assert_equal "1961-11-21T00:00:00+00:00", oo.cell(5,1).to_s
- else
- assert_equal :date, oo.celltype(5,1)
- assert_equal "1961-11-21", oo.cell(5,1).to_s
- end
+ assert_equal :date, oo.celltype(5,1)
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
assert_equal Date.new(1961,11,21), oo.cell(5,1)
end
end
@@ -633,11 +628,7 @@ def yaml_entry(row,col,type,value)
def test_to_yaml
with_each_spreadsheet(:name=>'numbers1') do |oo|
- if EXCEL2003XML
- assert_equal "--- \n"+yaml_entry(5,1,"datetime","1961-11-21T00:00:00+00:00"), oo.to_yaml({}, 5,1,5,1)
- else
- assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
- end
+ assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
assert_equal \
@@ -814,19 +805,11 @@ def test_to_csv
def test_bug_mehrere_datum
with_each_spreadsheet(:name=>'numbers1') do |oo|
oo.default_sheet = 'Sheet5'
- if EXCEL2003XML
- assert_equal :datetime, oo.celltype('A',4)
- assert_equal :datetime, oo.celltype('B',4)
- assert_equal :datetime, oo.celltype('C',4)
- assert_equal :datetime, oo.celltype('D',4)
- assert_equal :datetime, oo.celltype('E',4)
- else
- assert_equal :date, oo.celltype('A',4)
- assert_equal :date, oo.celltype('B',4)
- assert_equal :date, oo.celltype('C',4)
- assert_equal :date, oo.celltype('D',4)
- assert_equal :date, oo.celltype('E',4)
- end
+ assert_equal :date, oo.celltype('A',4)
+ assert_equal :date, oo.celltype('B',4)
+ assert_equal :date, oo.celltype('C',4)
+ assert_equal :date, oo.celltype('D',4)
+ assert_equal :date, oo.celltype('E',4)
assert_equal Date.new(2007,11,21), oo.cell('A',4)
assert_equal Date.new(2007,11,21), oo.cell('B',4)
assert_equal Date.new(2007,11,21), oo.cell('C',4)
@@ -1134,6 +1117,8 @@ def get_extension(oo)
".xls"
when Excelx
".xlsx"
+ when Excel2003XML
+ ".xml"
when Google
""
end
@@ -1317,7 +1302,7 @@ def test_bug_time_nil
end
def test_date_time_to_csv
- with_each_spreadsheet(:name=>'time-test') do |oo|
+ with_each_spreadsheet(:name=>'time-test',:ignore=>:excel2003xml) do |oo|
begin
assert oo.to_csv("/tmp/time-test.csv")
assert File.exists?("/tmp/time-test.csv")
@@ -1827,16 +1812,8 @@ def test_bad_excel_date
end
end
- def test_foo
- with_each_spreadsheet(:name=>'excel2003xml', :format=>:excel2003xml) do |oo|
- oo.default_sheet = 'SiteData'
- puts oo.cell(1,1)
- puts oo.cell(1,2)
- end
- end
-
-
def test_public_google_doc
+ return unless GOOGLE
with_public_google_spreadsheet do
assert_raise(GoogleHTTPError) { Google.new("foo") }
assert_raise(GoogleReadError) { Google.new(key_of('numbers1'))}

0 comments on commit 4d64ee7

Please sign in to comment.