roo-immersion 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. data/History.txt +225 -0
  2. data/README.markdown +60 -0
  3. data/examples/roo_soap_client.rb +53 -0
  4. data/examples/roo_soap_server.rb +29 -0
  5. data/examples/write_me.rb +33 -0
  6. data/lib/roo.rb +32 -0
  7. data/lib/roo/excel.rb +468 -0
  8. data/lib/roo/excel2003xml.rb +394 -0
  9. data/lib/roo/excelx.rb +601 -0
  10. data/lib/roo/generic_spreadsheet.rb +628 -0
  11. data/lib/roo/google.rb +379 -0
  12. data/lib/roo/openoffice.rb +451 -0
  13. data/lib/roo/roo_rails_helper.rb +82 -0
  14. data/lib/roo/version.rb +9 -0
  15. data/test/1900_base.xls +0 -0
  16. data/test/1904_base.xls +0 -0
  17. data/test/Bibelbund.csv +3741 -0
  18. data/test/Bibelbund.ods +0 -0
  19. data/test/Bibelbund.xls +0 -0
  20. data/test/Bibelbund.xlsx +0 -0
  21. data/test/Bibelbund.xml +62518 -0
  22. data/test/Bibelbund1.ods +0 -0
  23. data/test/bad_excel_date.xls +0 -0
  24. data/test/bbu.ods +0 -0
  25. data/test/bbu.xls +0 -0
  26. data/test/bbu.xlsx +0 -0
  27. data/test/bbu.xml +152 -0
  28. data/test/bode-v1.ods.zip +0 -0
  29. data/test/bode-v1.xls.zip +0 -0
  30. data/test/boolean.ods +0 -0
  31. data/test/boolean.xls +0 -0
  32. data/test/boolean.xlsx +0 -0
  33. data/test/boolean.xml +112 -0
  34. data/test/borders.ods +0 -0
  35. data/test/borders.xls +0 -0
  36. data/test/borders.xlsx +0 -0
  37. data/test/borders.xml +144 -0
  38. data/test/bug-row-column-fixnum-float.xls +0 -0
  39. data/test/bug-row-column-fixnum-float.xml +127 -0
  40. data/test/datetime.ods +0 -0
  41. data/test/datetime.xls +0 -0
  42. data/test/datetime.xlsx +0 -0
  43. data/test/datetime.xml +142 -0
  44. data/test/datetime_floatconv.xls +0 -0
  45. data/test/datetime_floatconv.xml +148 -0
  46. data/test/emptysheets.ods +0 -0
  47. data/test/emptysheets.xls +0 -0
  48. data/test/emptysheets.xml +105 -0
  49. data/test/excel2003.xml +21140 -0
  50. data/test/false_encoding.xls +0 -0
  51. data/test/false_encoding.xml +132 -0
  52. data/test/formula.ods +0 -0
  53. data/test/formula.xls +0 -0
  54. data/test/formula.xlsx +0 -0
  55. data/test/formula.xml +134 -0
  56. data/test/formula_parse_error.xls +0 -0
  57. data/test/formula_parse_error.xml +1833 -0
  58. data/test/html-escape.ods +0 -0
  59. data/test/no_spreadsheet_file.txt +1 -0
  60. data/test/numbers1.csv +18 -0
  61. data/test/numbers1.ods +0 -0
  62. data/test/numbers1.xls +0 -0
  63. data/test/numbers1.xlsx +0 -0
  64. data/test/numbers1.xml +312 -0
  65. data/test/only_one_sheet.ods +0 -0
  66. data/test/only_one_sheet.xls +0 -0
  67. data/test/only_one_sheet.xlsx +0 -0
  68. data/test/only_one_sheet.xml +67 -0
  69. data/test/paragraph.ods +0 -0
  70. data/test/paragraph.xls +0 -0
  71. data/test/paragraph.xlsx +0 -0
  72. data/test/paragraph.xml +127 -0
  73. data/test/ric.ods +0 -0
  74. data/test/simple_spreadsheet.ods +0 -0
  75. data/test/simple_spreadsheet.xls +0 -0
  76. data/test/simple_spreadsheet.xlsx +0 -0
  77. data/test/simple_spreadsheet.xml +225 -0
  78. data/test/simple_spreadsheet_from_italo.ods +0 -0
  79. data/test/simple_spreadsheet_from_italo.xls +0 -0
  80. data/test/simple_spreadsheet_from_italo.xml +242 -0
  81. data/test/skipped_tests.rb +789 -0
  82. data/test/style.ods +0 -0
  83. data/test/style.xls +0 -0
  84. data/test/style.xlsx +0 -0
  85. data/test/style.xml +154 -0
  86. data/test/test_helper.rb +19 -0
  87. data/test/test_roo.rb +1834 -0
  88. data/test/time-test.csv +2 -0
  89. data/test/time-test.ods +0 -0
  90. data/test/time-test.xls +0 -0
  91. data/test/time-test.xlsx +0 -0
  92. data/test/time-test.xml +131 -0
  93. data/test/whitespace.ods +0 -0
  94. data/test/whitespace.xls +0 -0
  95. data/test/whitespace.xlsx +0 -0
  96. data/test/whitespace.xml +184 -0
  97. metadata +231 -0
Binary file
Binary file
Binary file
@@ -0,0 +1,154 @@
1
+ <?xml version="1.0"?>
2
+ <?mso-application progid="Excel.Sheet"?>
3
+ <Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet"
4
+ xmlns:o="urn:schemas-microsoft-com:office:office"
5
+ xmlns:x="urn:schemas-microsoft-com:office:excel"
6
+ xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet"
7
+ xmlns:html="http://www.w3.org/TR/REC-html40">
8
+ <DocumentProperties xmlns="urn:schemas-microsoft-com:office:office">
9
+ <LastAuthor>Licensed User</LastAuthor>
10
+ <Created>2009-12-22T17:40:52Z</Created>
11
+ <Version>12.00</Version>
12
+ </DocumentProperties>
13
+ <ExcelWorkbook xmlns="urn:schemas-microsoft-com:office:excel">
14
+ <WindowHeight>8190</WindowHeight>
15
+ <WindowWidth>16380</WindowWidth>
16
+ <WindowTopX>0</WindowTopX>
17
+ <WindowTopY>0</WindowTopY>
18
+ <ProtectStructure>False</ProtectStructure>
19
+ <ProtectWindows>False</ProtectWindows>
20
+ </ExcelWorkbook>
21
+ <Styles>
22
+ <Style ss:ID="Default" ss:Name="Normal">
23
+ <Alignment ss:Vertical="Bottom"/>
24
+ <Borders/>
25
+ <Font ss:FontName="Arial" x:Family="Swiss"/>
26
+ <Interior/>
27
+ <NumberFormat/>
28
+ <Protection/>
29
+ </Style>
30
+ <Style ss:ID="s21">
31
+ <Font ss:FontName="Arial" x:Family="Swiss" ss:Bold="1"/>
32
+ </Style>
33
+ <Style ss:ID="s22">
34
+ <Font ss:FontName="Arial" x:Family="Swiss" ss:Italic="1"/>
35
+ </Style>
36
+ <Style ss:ID="s23">
37
+ <Font ss:FontName="Arial" x:Family="Swiss" ss:Underline="Single"/>
38
+ </Style>
39
+ <Style ss:ID="s24">
40
+ <Font ss:FontName="Arial" x:Family="Swiss" ss:Bold="1" ss:Italic="1"/>
41
+ </Style>
42
+ <Style ss:ID="s25">
43
+ <Font ss:FontName="Arial" x:Family="Swiss" ss:Bold="1" ss:Underline="Single"/>
44
+ </Style>
45
+ <Style ss:ID="s26">
46
+ <Font ss:FontName="Arial" x:Family="Swiss" ss:Italic="1" ss:Underline="Single"/>
47
+ </Style>
48
+ </Styles>
49
+ <Worksheet ss:Name="Sheet1">
50
+ <Table ss:ExpandedColumnCount="4" ss:ExpandedRowCount="11" x:FullColumns="1"
51
+ x:FullRows="1">
52
+ <Column ss:AutoFitWidth="0" ss:Width="69"/>
53
+ <Column ss:StyleID="s21" ss:AutoFitWidth="0" ss:Width="79.5"/>
54
+ <Column ss:StyleID="s22" ss:AutoFitWidth="0" ss:Width="116.25"/>
55
+ <Row>
56
+ <Cell ss:StyleID="s21"><Data ss:Type="String">Bold</Data></Cell>
57
+ </Row>
58
+ <Row>
59
+ <Cell ss:StyleID="s22"><Data ss:Type="String">Italic</Data></Cell>
60
+ </Row>
61
+ <Row>
62
+ <Cell><Data ss:Type="String">Normal</Data></Cell>
63
+ </Row>
64
+ <Row>
65
+ <Cell ss:StyleID="s23"><Data ss:Type="String">Underline</Data></Cell>
66
+ </Row>
67
+ <Row>
68
+ <Cell ss:StyleID="s24"><Data ss:Type="String">Bold-Italic</Data></Cell>
69
+ </Row>
70
+ <Row>
71
+ <Cell ss:StyleID="s25"><Data ss:Type="String">Bold-Underline</Data></Cell>
72
+ </Row>
73
+ <Row>
74
+ <Cell ss:StyleID="s26"><Data ss:Type="String">Italic-Underline</Data></Cell>
75
+ </Row>
76
+ <Row ss:StyleID="s21">
77
+ <Cell><Data ss:Type="String">Bolded Row</Data></Cell>
78
+ <Cell ss:Index="3" ss:StyleID="s24"/>
79
+ </Row>
80
+ <Row>
81
+ <Cell ss:Index="2"><Data ss:Type="String">Bolded Column</Data></Cell>
82
+ </Row>
83
+ <Row ss:StyleID="s21">
84
+ <Cell ss:Index="3" ss:StyleID="s24"><Data ss:Type="String">Bolded Row Italic Column</Data></Cell>
85
+ </Row>
86
+ <Row>
87
+ <Cell ss:Index="4"><Data ss:Type="String">Normal</Data></Cell>
88
+ </Row>
89
+ </Table>
90
+ <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
91
+ <PageSetup>
92
+ <Header x:Margin="0.51180555555555551"/>
93
+ <Footer x:Margin="0.51180555555555551"/>
94
+ <PageMargins x:Bottom="0.98402777777777772" x:Left="0.74791666666666667"
95
+ x:Right="0.74791666666666667" x:Top="0.98402777777777772"/>
96
+ </PageSetup>
97
+ <Print>
98
+ <ValidPrinterInfo/>
99
+ <HorizontalResolution>300</HorizontalResolution>
100
+ <VerticalResolution>300</VerticalResolution>
101
+ </Print>
102
+ <Selected/>
103
+ <Panes>
104
+ <Pane>
105
+ <Number>3</Number>
106
+ <ActiveRow>3</ActiveRow>
107
+ <ActiveCol>2</ActiveCol>
108
+ </Pane>
109
+ </Panes>
110
+ <ProtectObjects>False</ProtectObjects>
111
+ <ProtectScenarios>False</ProtectScenarios>
112
+ </WorksheetOptions>
113
+ </Worksheet>
114
+ <Worksheet ss:Name="Sheet2">
115
+ <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
116
+ x:FullRows="1">
117
+ </Table>
118
+ <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
119
+ <PageSetup>
120
+ <Header x:Margin="0.51180555555555551"/>
121
+ <Footer x:Margin="0.51180555555555551"/>
122
+ <PageMargins x:Bottom="0.98402777777777772" x:Left="0.74791666666666667"
123
+ x:Right="0.74791666666666667" x:Top="0.98402777777777772"/>
124
+ </PageSetup>
125
+ <Print>
126
+ <ValidPrinterInfo/>
127
+ <HorizontalResolution>300</HorizontalResolution>
128
+ <VerticalResolution>300</VerticalResolution>
129
+ </Print>
130
+ <ProtectObjects>False</ProtectObjects>
131
+ <ProtectScenarios>False</ProtectScenarios>
132
+ </WorksheetOptions>
133
+ </Worksheet>
134
+ <Worksheet ss:Name="Sheet3">
135
+ <Table ss:ExpandedColumnCount="1" ss:ExpandedRowCount="1" x:FullColumns="1"
136
+ x:FullRows="1">
137
+ </Table>
138
+ <WorksheetOptions xmlns="urn:schemas-microsoft-com:office:excel">
139
+ <PageSetup>
140
+ <Header x:Margin="0.51180555555555551"/>
141
+ <Footer x:Margin="0.51180555555555551"/>
142
+ <PageMargins x:Bottom="0.98402777777777772" x:Left="0.74791666666666667"
143
+ x:Right="0.74791666666666667" x:Top="0.98402777777777772"/>
144
+ </PageSetup>
145
+ <Print>
146
+ <ValidPrinterInfo/>
147
+ <HorizontalResolution>300</HorizontalResolution>
148
+ <VerticalResolution>300</VerticalResolution>
149
+ </Print>
150
+ <ProtectObjects>False</ProtectObjects>
151
+ <ProtectScenarios>False</ProtectScenarios>
152
+ </WorksheetOptions>
153
+ </Worksheet>
154
+ </Workbook>
@@ -0,0 +1,19 @@
1
+ require 'test/unit'
2
+ require File.dirname(__FILE__) + '/../lib/roo'
3
+
4
+ # helper method
5
+ def after(d)
6
+ yield if DateTime.now > d
7
+ end
8
+
9
+ # helper method
10
+ def before(d)
11
+ yield if DateTime.now <= d
12
+ end
13
+
14
+ # helper method
15
+ def local_only
16
+ if ENV["roo_local"] == "thomas-p"
17
+ yield
18
+ end
19
+ end
@@ -0,0 +1,1834 @@
1
+ #damit keine falschen Vermutungen aufkommen: Ich habe religioes rein gar nichts
2
+ # mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
3
+ # Spreadsheet-Datei mit ca. 3500 Zeilen oeffentlich im Netz, die sich ganz gut
4
+ # zum Testen eignete.
5
+ #
6
+ #--
7
+ # these test cases were developed to run under Linux OS, some commands
8
+ # (like 'diff') must be changed (or commented out ;-)) if you want to run
9
+ # the tests under another OS
10
+ #
11
+
12
+
13
+ #TODO
14
+ # Look at formulas in excel - does not work with date/time
15
+
16
+
17
+ # Dump warnings that come from the test to open files
18
+ # with the wrong spreadsheet class
19
+ STDERR.reopen "/dev/null","w"
20
+
21
+ TESTDIR = File.dirname(__FILE__)
22
+ require TESTDIR + '/test_helper.rb'
23
+ #require 'soap/rpc/driver'
24
+ require 'fileutils'
25
+ require 'timeout'
26
+ require 'logger'
27
+ $log = Logger.new(File.join(ENV['HOME'],"roo.log"))
28
+ $log.level = Logger::WARN
29
+ #$log.level = Logger::DEBUG
30
+
31
+ DISPLAY_LOG = false
32
+ DB_LOG = false
33
+
34
+ if DB_LOG
35
+ require 'activerecord'
36
+ end
37
+
38
+ include FileUtils
39
+
40
+ if DB_LOG
41
+ def activerecord_connect
42
+ ActiveRecord::Base.establish_connection(:adapter => "mysql",
43
+ :database => "test_runs",
44
+ :host => "localhost",
45
+ :username => "root",
46
+ :socket => "/var/run/mysqld/mysqld.sock")
47
+ end
48
+
49
+ class Testrun < ActiveRecord::Base
50
+ end
51
+ end
52
+
53
+ class Test::Unit::TestCase
54
+ def key_of(spreadsheetname)
55
+ begin
56
+
57
+ return {
58
+ 'formula' => 'rt4Pw1WmjxFtyfrqqy94wPw',
59
+ "write.me" => 'r6m7HFlUOwst0RTUTuhQ0Ow',
60
+ 'numbers1' => "rYraCzjxTtkxw1NxHJgDU8Q",
61
+ 'borders' => "r_nLYMft6uWg_PT9Rc2urXw",
62
+ 'simple_spreadsheet' => "r3aMMCBCA153TmU_wyIaxfw",
63
+ 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
64
+ "only_one_sheet" => "rqRtkcPJ97nhQ0m9ksDw2rA",
65
+ 'time-test' => 'r2XfDBJMrLPjmuLrPQQrEYw',
66
+ 'datetime' => "r2kQpXWr6xOSUpw9MyXavYg",
67
+ 'whitespace' => "rZyQaoFebVGeHKzjG6e9gRQ"
68
+ }[spreadsheetname]
69
+ # 'numbers1' => "o10837434939102457526.4784396906364855777",
70
+ # 'borders' => "o10837434939102457526.664868920231926255",
71
+ # 'simple_spreadsheet' => "ptu6bbahNZpYe-L1vEBmgGA",
72
+ # 'testnichtvorhandenBibelbund.ods' => "invalidkeyforanyspreadsheet", # !!! intentionally false key
73
+ # "only_one_sheet" => "o10837434939102457526.762705759906130135",
74
+ # "write.me" => 'ptu6bbahNZpY0N0RrxQbWdw&hl',
75
+ # 'formula' => 'o10837434939102457526.3022866619437760118',
76
+ # 'time-test' => 'ptu6bbahNZpYBMhk01UfXSg',
77
+ # 'datetime' => "ptu6bbahNZpYQEtZwzL_dZQ",
78
+ rescue
79
+ raise "unknown spreadsheetname: #{spreadsheetname}"
80
+ end
81
+ end
82
+
83
+ if DB_LOG
84
+ if ! (defined?(@connected) and @connected)
85
+ activerecord_connect
86
+ else
87
+ @connected = true
88
+ end
89
+ end
90
+ alias unlogged_run run
91
+ def run(result, &block)
92
+ t1 = Time.now
93
+ #RAILS_DEFAULT_LOGGER.debug "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
94
+ if DISPLAY_LOG
95
+ print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
96
+ STDOUT.flush
97
+ end
98
+ unlogged_run result, &block
99
+ t2 = Time.now
100
+ if DISPLAY_LOG
101
+ puts "\t#{t2-t1} seconds"
102
+ end
103
+ if DB_LOG
104
+ domain = Testrun.create(
105
+ :class_name => self.class.to_s,
106
+ :test_name => @method_name,
107
+ :start => t1,
108
+ :duration => t2-t1
109
+ )
110
+ end
111
+ end
112
+ end
113
+
114
+ class File
115
+ def File.delete_if_exist(filename)
116
+ if File.exist?(filename)
117
+ File.delete(filename)
118
+ end
119
+ end
120
+ end
121
+
122
+ # :nodoc
123
+ class Fixnum
124
+ def minutes
125
+ self * 60
126
+ end
127
+ end
128
+
129
+ class TestRoo < Test::Unit::TestCase
130
+
131
+ OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
132
+ EXCEL = true # do Excel Tests?
133
+ GOOGLE = false # do Google-Spreadsheet Tests?
134
+ EXCELX = true # do Excel-X Tests? (.xlsx-files)
135
+ EXCEL2003XML = true # do MS2003 XML tests
136
+
137
+ ONLINE = true
138
+ LONG_RUN = false
139
+ GLOBAL_TIMEOUT = 48.minutes #*60 # 2*12*60 # seconds
140
+
141
+ def setup
142
+ #if DISPLAY_LOG
143
+ # puts " GLOBAL_TIMEOUT = #{GLOBAL_TIMEOUT}"
144
+ #end
145
+ end
146
+
147
+ def test_internal_minutes
148
+ assert_equal 42*60, 42.minutes
149
+ end
150
+
151
+ # call a block of code for each spreadsheet type
152
+ # and yield a reference to the roo object
153
+ def with_each_spreadsheet(options)
154
+ options[:format] ||= [:excel, :excelx, :excel2003xml, :openoffice, :google]
155
+ options[:format] = [options[:format]] if Symbol === options[:format]
156
+ if options[:ignore]
157
+ if Symbol === options[:ignore]
158
+ options[:format] = (options[:format] - [options[:ignore]])
159
+ else
160
+ options[:format] = (options[:format] - options[:ignore])
161
+ end
162
+ end
163
+ yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xls')) if EXCEL && options[:format].include?(:excel)
164
+ yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xlsx')) if EXCELX && options[:format].include?(:excelx)
165
+ yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.ods')) if OPENOFFICE && options[:format].include?(:openoffice)
166
+ yield Roo::Spreadsheet.open(File.join(TESTDIR, options[:name] + '.xml')) if EXCEL2003XML && options[:format].include?(:excel2003xml)
167
+ yield Roo::Spreadsheet.open(key_of(options[:name]) || options[:name]) if GOOGLE && options[:format].include?(:google)
168
+ end
169
+
170
+ def with_public_google_spreadsheet(&block)
171
+ user = ENV['GOOGLE_MAIL']
172
+ pass = ENV['GOOGLE_PASSWORD']
173
+ ENV['GOOGLE_MAIL'] = ''
174
+ ENV['GOOGLE_PASSWORD'] = ''
175
+ block.call
176
+ ENV['GOOGLE_MAIL'] = user
177
+ ENV['GOOGLE_PASSWORD'] = pass
178
+ end
179
+
180
+ # Using Date.strptime so check that it's using the method
181
+ # with the value set in date_format
182
+ def test_date
183
+ with_each_spreadsheet(:name=>'numbers1', :format=>:google) do |oo|
184
+ # should default to DDMMYYYY
185
+ assert oo.date?("21/11/1962") == true
186
+ assert oo.date?("11/21/1962") == false
187
+ oo.date_format = '%m/%d/%Y'
188
+ assert oo.date?("21/11/1962") == false
189
+ assert oo.date?("11/21/1962") == true
190
+ oo.date_format = '%Y-%m-%d'
191
+ assert oo.date?("1962-11-21") == true
192
+ assert oo.date?("1962-21-11") == false
193
+ end
194
+ end
195
+
196
+ def test_classes
197
+ if OPENOFFICE
198
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.ods"))
199
+ assert_kind_of Openoffice, oo
200
+ end
201
+ if EXCEL
202
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xls"))
203
+ assert_kind_of Excel, oo
204
+ end
205
+ if GOOGLE
206
+ oo = Google.new(key_of("numbers1"))
207
+ assert_kind_of Google, oo
208
+ end
209
+ if EXCELX
210
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xlsx"))
211
+ assert_kind_of Excelx, oo
212
+ end
213
+ end
214
+
215
+ def test_letters
216
+ assert_equal 1, GenericSpreadsheet.letter_to_number('A')
217
+ assert_equal 1, GenericSpreadsheet.letter_to_number('a')
218
+ assert_equal 2, GenericSpreadsheet.letter_to_number('B')
219
+ assert_equal 26, GenericSpreadsheet.letter_to_number('Z')
220
+ assert_equal 27, GenericSpreadsheet.letter_to_number('AA')
221
+ assert_equal 27, GenericSpreadsheet.letter_to_number('aA')
222
+ assert_equal 27, GenericSpreadsheet.letter_to_number('Aa')
223
+ assert_equal 27, GenericSpreadsheet.letter_to_number('aa')
224
+ end
225
+
226
+ def test_sheets
227
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
228
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
229
+ assert_raise(RangeError) { oo.default_sheet = "no_sheet" }
230
+ assert_raise(TypeError) { oo.default_sheet = [1,2,3] }
231
+ oo.sheets.each { |sh|
232
+ oo.default_sheet = sh
233
+ assert_equal sh, oo.default_sheet
234
+ }
235
+ end
236
+ end
237
+
238
+ def test_cells
239
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
240
+ assert_equal 1, oo.cell(1,1)
241
+ assert_equal 2, oo.cell(1,2)
242
+ assert_equal 3, oo.cell(1,3)
243
+ assert_equal 4, oo.cell(1,4)
244
+ assert_equal 5, oo.cell(2,1)
245
+ assert_equal 6, oo.cell(2,2)
246
+ assert_equal 7, oo.cell(2,3)
247
+ assert_equal 8, oo.cell(2,4)
248
+ assert_equal 9, oo.cell(2,5)
249
+ assert_equal "test", oo.cell(2,6)
250
+ assert_equal :string, oo.celltype(2,6)
251
+ assert_equal 11, oo.cell(2,7)
252
+ assert_equal :float, oo.celltype(2,7)
253
+ assert_equal 10, oo.cell(4,1)
254
+ assert_equal 11, oo.cell(4,2)
255
+ assert_equal 12, oo.cell(4,3)
256
+ assert_equal 13, oo.cell(4,4)
257
+ assert_equal 14, oo.cell(4,5)
258
+ assert_equal 10, oo.cell(4,'A')
259
+ assert_equal 11, oo.cell(4,'B')
260
+ assert_equal 12, oo.cell(4,'C')
261
+ assert_equal 13, oo.cell(4,'D')
262
+ assert_equal 14, oo.cell(4,'E')
263
+ assert_equal :date, oo.celltype(5,1)
264
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
265
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
266
+ end
267
+ end
268
+
269
+ def test_celltype
270
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
271
+ assert_equal :string, oo.celltype(2,6)
272
+ end
273
+ end
274
+
275
+ def test_cell_address
276
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
277
+ assert_equal "tata", oo.cell(6,1)
278
+ assert_equal "tata", oo.cell(6,'A')
279
+ assert_equal "tata", oo.cell('A',6)
280
+ assert_equal "tata", oo.cell(6,'a')
281
+ assert_equal "tata", oo.cell('a',6)
282
+ assert_raise(ArgumentError) { assert_equal "tata", oo.cell('a','f') }
283
+ assert_raise(ArgumentError) { assert_equal "tata", oo.cell('f','a') }
284
+ assert_equal "thisisc8", oo.cell(8,3)
285
+ assert_equal "thisisc8", oo.cell(8,'C')
286
+ assert_equal "thisisc8", oo.cell('C',8)
287
+ assert_equal "thisisc8", oo.cell(8,'c')
288
+ assert_equal "thisisc8", oo.cell('c',8)
289
+ assert_equal "thisisd9", oo.cell('d',9)
290
+ assert_equal "thisisa11", oo.cell('a',11)
291
+ end
292
+ end
293
+
294
+ def test_office_version
295
+ with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
296
+ assert_equal "1.0", oo.officeversion
297
+ end
298
+ end
299
+
300
+ #TODO: inkonsequente Lieferung Fixnum/Float
301
+ def test_rows
302
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
303
+ assert_equal 41, oo.cell('a',12)
304
+ assert_equal 42, oo.cell('b',12)
305
+ assert_equal 43, oo.cell('c',12)
306
+ assert_equal 44, oo.cell('d',12)
307
+ assert_equal 45, oo.cell('e',12)
308
+ assert_equal [41.0,42.0,43.0,44.0,45.0, nil, nil], oo.row(12)
309
+ assert_equal "einundvierzig", oo.cell('a',16)
310
+ assert_equal "zweiundvierzig", oo.cell('b',16)
311
+ assert_equal "dreiundvierzig", oo.cell('c',16)
312
+ assert_equal "vierundvierzig", oo.cell('d',16)
313
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
314
+ assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig", nil, nil], oo.row(16)
315
+ end
316
+ end
317
+
318
+ def test_last_row
319
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
320
+ assert_equal 18, oo.last_row
321
+ end
322
+ end
323
+
324
+ def test_last_column
325
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
326
+ assert_equal 7, oo.last_column
327
+ end
328
+ end
329
+
330
+ def test_last_column_as_letter
331
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
332
+ assert_equal 'G', oo.last_column_as_letter
333
+ end
334
+ end
335
+
336
+ def test_first_row
337
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
338
+ assert_equal 1, oo.first_row
339
+ end
340
+ end
341
+
342
+ def test_first_column
343
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
344
+ assert_equal 1, oo.first_column
345
+ end
346
+ end
347
+
348
+ def test_first_column_as_letter
349
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
350
+ assert_equal 'A', oo.first_column_as_letter
351
+ end
352
+ end
353
+
354
+ def test_sheetname
355
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
356
+ oo.default_sheet = "Name of Sheet 2"
357
+ assert_equal 'I am sheet 2', oo.cell('C',5)
358
+ assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
359
+ assert_raise(RangeError) { oo.default_sheet = "non existing sheet name" }
360
+ assert_raise(RangeError) { dummy = oo.cell('C',5,"non existing sheet name")}
361
+ assert_raise(RangeError) { dummy = oo.celltype('C',5,"non existing sheet name")}
362
+ assert_raise(RangeError) { dummy = oo.empty?('C',5,"non existing sheet name")}
363
+ if oo.class == Excel
364
+ assert_raise(RuntimeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
365
+ assert_raise(RuntimeError) { dummy = oo.formula('C',5,"non existing sheet name")}
366
+ else
367
+ assert_raise(RangeError) { dummy = oo.formula?('C',5,"non existing sheet name")}
368
+ assert_raise(RangeError) { dummy = oo.formula('C',5,"non existing sheet name")}
369
+ assert_raise(RangeError) { dummy = oo.set('C',5,42,"non existing sheet name")} unless oo.class == Google
370
+ assert_raise(RangeError) { dummy = oo.formulas("non existing sheet name")}
371
+ end
372
+ assert_raise(RangeError) { dummy = oo.to_yaml({},1,1,1,1,"non existing sheet name")}
373
+ end
374
+ end
375
+
376
+ def test_boundaries
377
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
378
+ oo.default_sheet = "Name of Sheet 2"
379
+ assert_equal 2, oo.first_column
380
+ assert_equal 'B', oo.first_column_as_letter
381
+ assert_equal 5, oo.first_row
382
+ assert_equal 'E', oo.last_column_as_letter
383
+ assert_equal 14, oo.last_row
384
+ end
385
+ end
386
+
387
+ def test_multiple_letters
388
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
389
+ oo.default_sheet = "Sheet3"
390
+ assert_equal "i am AA", oo.cell('AA',1)
391
+ assert_equal "i am AB", oo.cell('AB',1)
392
+ assert_equal "i am BA", oo.cell('BA',1)
393
+ assert_equal 'BA', oo.last_column_as_letter
394
+ assert_equal "i am BA", oo.cell(1,'BA')
395
+ end
396
+ end
397
+
398
+ def test_argument_error
399
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
400
+ assert_nothing_raised(ArgumentError) { oo.default_sheet = "Tabelle1" }
401
+ end
402
+ end
403
+
404
+ def test_empty_eh
405
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
406
+ assert oo.empty?('a',14)
407
+ assert !oo.empty?('a',15)
408
+ assert oo.empty?('a',20)
409
+ end
410
+ end
411
+
412
+ def test_reload
413
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
414
+ assert_equal 1, oo.cell(1,1)
415
+ oo.reload
416
+ assert_equal 1, oo.cell(1,1)
417
+ end
418
+ end
419
+
420
+ def test_bug_contiguous_cells
421
+ with_each_spreadsheet(:name=>'numbers1', :format=>:openoffice) do |oo|
422
+ oo.default_sheet = "Sheet4"
423
+ assert_equal Date.new(2007,06,16), oo.cell('a',1)
424
+ assert_equal 10, oo.cell('b',1)
425
+ assert_equal 10, oo.cell('c',1)
426
+ assert_equal 10, oo.cell('d',1)
427
+ assert_equal 10, oo.cell('e',1)
428
+ end
429
+ end
430
+
431
+ def test_bug_italo_ve
432
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
433
+ oo.default_sheet = "Sheet5"
434
+ assert_equal 1, oo.cell('A',1)
435
+ assert_equal 5, oo.cell('b',1)
436
+ assert_equal 5, oo.cell('c',1)
437
+ assert_equal 2, oo.cell('a',2)
438
+ assert_equal 3, oo.cell('a',3)
439
+ end
440
+ end
441
+
442
+ def test_italo_table
443
+ with_each_spreadsheet(:name=>'simple_spreadsheet_from_italo', :format=>[:openoffice, :excel]) do |oo|
444
+ assert_equal '1', oo.cell('A',1)
445
+ assert_equal '1', oo.cell('B',1)
446
+ assert_equal '1', oo.cell('C',1)
447
+ assert_equal 1, oo.cell('A',2).to_i
448
+ assert_equal 2, oo.cell('B',2).to_i
449
+ assert_equal 1, oo.cell('C',2).to_i
450
+ assert_equal 1, oo.cell('A',3)
451
+ assert_equal 3, oo.cell('B',3)
452
+ assert_equal 1, oo.cell('C',3)
453
+ assert_equal 'A', oo.cell('A',4)
454
+ assert_equal 'A', oo.cell('B',4)
455
+ assert_equal 'A', oo.cell('C',4)
456
+ assert_equal 0.01, oo.cell('A',5)
457
+ assert_equal 0.01, oo.cell('B',5)
458
+ assert_equal 0.01, oo.cell('C',5)
459
+ assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5)
460
+
461
+ # Cells values in row 1:
462
+ assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
463
+ assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
464
+ assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
465
+
466
+ # Cells values in row 2:
467
+ assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
468
+ assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
469
+ assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
470
+
471
+ # Cells values in row 3:
472
+ assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
473
+ assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
474
+ assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
475
+
476
+ # Cells values in row 4:
477
+ assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
478
+ assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
479
+ assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
480
+
481
+ # Cells values in row 5:
482
+ if oo.class == Openoffice
483
+ assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
484
+ assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
485
+ assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
486
+ else
487
+ assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
488
+ assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
489
+ assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
490
+ end
491
+ end
492
+ end
493
+
494
+ def test_formula_openoffice
495
+ with_each_spreadsheet(:name=>'formula', :format=>:openoffice) do |oo|
496
+ assert_equal 1, oo.cell('A',1)
497
+ assert_equal 2, oo.cell('A',2)
498
+ assert_equal 3, oo.cell('A',3)
499
+ assert_equal 4, oo.cell('A',4)
500
+ assert_equal 5, oo.cell('A',5)
501
+ assert_equal 6, oo.cell('A',6)
502
+ assert_equal 21, oo.cell('A',7)
503
+ assert_equal :formula, oo.celltype('A',7)
504
+ assert_equal "=[Sheet2.A1]", oo.formula('C',7)
505
+ assert_nil oo.formula('A',6)
506
+ assert_equal [[7, 1, "=SUM([.A1:.A6])"],
507
+ [7, 2, "=SUM([.$A$1:.B6])"],
508
+ [7, 3, "=[Sheet2.A1]"],
509
+ [8, 2, "=SUM([.$A$1:.B7])"],
510
+ ], oo.formulas(oo.sheets.first)
511
+
512
+ # setting a cell
513
+ oo.set('A',15, 41)
514
+ assert_equal 41, oo.cell('A',15)
515
+ oo.set('A',16, "41")
516
+ assert_equal "41", oo.cell('A',16)
517
+ oo.set('A',17, 42.5)
518
+ assert_equal 42.5, oo.cell('A',17)
519
+ end
520
+ end
521
+
522
+ def test_formula_google
523
+ with_each_spreadsheet(:name=>'formula', :format=>:google) do |oo|
524
+ assert_equal 1, oo.cell('A',1)
525
+ assert_equal 2, oo.cell('A',2)
526
+ assert_equal 3, oo.cell('A',3)
527
+ assert_equal 4, oo.cell('A',4)
528
+ assert_equal 5, oo.cell('A',5)
529
+ assert_equal 6, oo.cell('A',6)
530
+ # assert_equal 21, oo.cell('A',7)
531
+ assert_equal 21.0, oo.cell('A',7) #TODO: better solution Fixnum/Float
532
+ assert_equal :formula, oo.celltype('A',7)
533
+ # assert_equal "=[Sheet2.A1]", oo.formula('C',7)
534
+ # !!! different from formulas in Openoffice
535
+ #was: assert_equal "=sheet2!R[-6]C[-2]", oo.formula('C',7)
536
+ # has Google changed their format of formulas/references to other sheets?
537
+ assert_equal "=Sheet2!R[-6]C[-2]", oo.formula('C',7)
538
+ assert_nil oo.formula('A',6)
539
+ # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
540
+ # [7, 2, "=SUM([.$A$1:.B6])"],
541
+ # [7, 3, "=[Sheet2.A1]"],
542
+ # [8, 2, "=SUM([.$A$1:.B7])"],
543
+ # ], oo.formulas(oo.sheets.first)
544
+ # different format than in openoffice spreadsheets:
545
+ #was:
546
+ # assert_equal [[7, 1, "=SUM(R[-6]C[0]:R[-1]C[0])"],
547
+ # [7, 2, "=SUM(R1C1:R[-1]C[0])"],
548
+ # [7, 3, "=sheet2!R[-6]C[-2]"],
549
+ # [8, 2, "=SUM(R1C1:R[-1]C[0])"]],
550
+ # oo.formulas(oo.sheets.first)
551
+ assert_equal [[7, 1, "=SUM(R[-6]C:R[-1]C)"],
552
+ [7, 2, "=SUM(R1C1:R[-1]C)"],
553
+ [7, 3, "=Sheet2!R[-6]C[-2]"],
554
+ [8, 2, "=SUM(R1C1:R[-1]C)"]],
555
+ oo.formulas(oo.sheets.first)
556
+ end
557
+ end
558
+
559
+ def test_formula_excelx
560
+ with_each_spreadsheet(:name=>'formula', :format=>:excelx) do |oo|
561
+ assert_equal 1, oo.cell('A',1)
562
+ assert_equal 2, oo.cell('A',2)
563
+ assert_equal 3, oo.cell('A',3)
564
+ assert_equal 4, oo.cell('A',4)
565
+ assert_equal 5, oo.cell('A',5)
566
+ assert_equal 6, oo.cell('A',6)
567
+ assert_equal 21, oo.cell('A',7)
568
+ assert_equal :formula, oo.celltype('A',7)
569
+ #steht nicht in Datei, oder?
570
+ #nein, diesen Bezug habe ich nur in der Openoffice-Datei
571
+ #assert_equal "=[Sheet2.A1]", oo.formula('C',7)
572
+ assert_nil oo.formula('A',6)
573
+ # assert_equal [[7, 1, "=SUM([.A1:.A6])"],
574
+ # [7, 2, "=SUM([.$A$1:.B6])"],
575
+ #[7, 3, "=[Sheet2.A1]"],
576
+ #[8, 2, "=SUM([.$A$1:.B7])"],
577
+ #], oo.formulas(oo.sheets.first)
578
+ assert_equal [[7, 1, 'SUM(A1:A6)'],
579
+ [7, 2, 'SUM($A$1:B6)'],
580
+ # [7, 3, "=[Sheet2.A1]"],
581
+ # [8, 2, "=SUM([.$A$1:.B7])"],
582
+ ], oo.formulas(oo.sheets.first)
583
+
584
+ # setting a cell
585
+ oo.set('A',15, 41)
586
+ assert_equal 41, oo.cell('A',15)
587
+ oo.set('A',16, "41")
588
+ assert_equal "41", oo.cell('A',16)
589
+ oo.set('A',17, 42.5)
590
+ assert_equal 42.5, oo.cell('A',17)
591
+ end
592
+ end
593
+
594
+ # Excel can only read the cell's value
595
+ def test_formula_excel
596
+ with_each_spreadsheet(:name=>'formula', :format=>:excel) do |oo|
597
+ assert_equal 21, oo.cell('A',7)
598
+ assert_equal 21, oo.cell('B',7)
599
+ end
600
+ end
601
+
602
+
603
+ def test_borders_sheets
604
+ with_each_spreadsheet(:name=>'borders') do |oo|
605
+ oo.default_sheet = oo.sheets[1]
606
+ assert_equal 6, oo.first_row
607
+ assert_equal 11, oo.last_row
608
+ assert_equal 4, oo.first_column
609
+ assert_equal 8, oo.last_column
610
+
611
+ oo.default_sheet = oo.sheets.first
612
+ assert_equal 5, oo.first_row
613
+ assert_equal 10, oo.last_row
614
+ assert_equal 3, oo.first_column
615
+ assert_equal 7, oo.last_column
616
+
617
+ oo.default_sheet = oo.sheets[2]
618
+ assert_equal 7, oo.first_row
619
+ assert_equal 12, oo.last_row
620
+ assert_equal 5, oo.first_column
621
+ assert_equal 9, oo.last_column
622
+ end
623
+ end
624
+
625
+ def yaml_entry(row,col,type,value)
626
+ "cell_#{row}_#{col}: \n row: #{row} \n col: #{col} \n celltype: #{type} \n value: #{value} \n"
627
+ end
628
+
629
+ def test_to_yaml
630
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
631
+ assert_equal "--- \n"+yaml_entry(5,1,"date","1961-11-21"), oo.to_yaml({}, 5,1,5,1)
632
+ assert_equal "--- \n"+yaml_entry(8,3,"string","thisisc8"), oo.to_yaml({}, 8,3,8,3)
633
+ assert_equal "--- \n"+yaml_entry(12,3,"float",43.0), oo.to_yaml({}, 12,3,12,3)
634
+ assert_equal \
635
+ "--- \n"+yaml_entry(12,3,"float",43.0) +
636
+ yaml_entry(12,4,"float",44.0) +
637
+ yaml_entry(12,5,"float",45.0), oo.to_yaml({}, 12,3,12)
638
+ assert_equal \
639
+ "--- \n"+yaml_entry(12,3,"float",43.0)+
640
+ yaml_entry(12,4,"float",44.0)+
641
+ yaml_entry(12,5,"float",45.0)+
642
+ yaml_entry(15,3,"float",43.0)+
643
+ yaml_entry(15,4,"float",44.0)+
644
+ yaml_entry(15,5,"float",45.0)+
645
+ yaml_entry(16,3,"string","dreiundvierzig")+
646
+ yaml_entry(16,4,"string","vierundvierzig")+
647
+ yaml_entry(16,5,"string","fuenfundvierzig"), oo.to_yaml({}, 12,3)
648
+ end
649
+ end
650
+
651
+ def test_only_one_sheet
652
+ with_each_spreadsheet(:name=>'only_one_sheet') do |oo|
653
+ assert_equal 42, oo.cell('B',4)
654
+ assert_equal 43, oo.cell('C',4)
655
+ assert_equal 44, oo.cell('D',4)
656
+ oo.default_sheet = oo.sheets.first
657
+ assert_equal 42, oo.cell('B',4)
658
+ assert_equal 43, oo.cell('C',4)
659
+ assert_equal 44, oo.cell('D',4)
660
+ end
661
+ end
662
+
663
+ def test_excel_open_from_uri_and_zipped
664
+ if EXCEL
665
+ if ONLINE
666
+ begin
667
+ url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
668
+ excel = Excel.new(url, :zip)
669
+ excel.default_sheet = excel.sheets.first
670
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
671
+ ensure
672
+ excel.remove_tmp
673
+ end
674
+ end
675
+ end
676
+ end
677
+
678
+ def test_openoffice_open_from_uri_and_zipped
679
+ if OPENOFFICE
680
+ if ONLINE
681
+ begin
682
+ url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
683
+ sheet = Openoffice.new(url, :zip)
684
+ #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
685
+ assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
686
+ ensure
687
+ sheet.remove_tmp
688
+ end
689
+ end
690
+ end
691
+ end
692
+
693
+ def test_excel_zipped
694
+ if EXCEL
695
+ begin
696
+ oo = Excel.new(File.join(TESTDIR,"bode-v1.xls.zip"), :zip)
697
+ assert oo
698
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
699
+ ensure
700
+ oo.remove_tmp
701
+ end
702
+ end
703
+ end
704
+
705
+ def test_openoffice_zipped
706
+ if OPENOFFICE
707
+ begin
708
+ oo = Openoffice.new(File.join(TESTDIR,"bode-v1.ods.zip"), :zip)
709
+ assert oo
710
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
711
+ ensure
712
+ oo.remove_tmp
713
+ end
714
+ end
715
+ end
716
+
717
+ def test_bug_ric
718
+ with_each_spreadsheet(:name=>'ric', :format=>:openoffice) do |oo|
719
+ assert oo.empty?('A',1)
720
+ assert oo.empty?('B',1)
721
+ assert oo.empty?('C',1)
722
+ assert oo.empty?('D',1)
723
+ expected = 1
724
+ letter = 'e'
725
+ while letter <= 'u'
726
+ assert_equal expected, oo.cell(letter,1)
727
+ letter.succ!
728
+ expected += 1
729
+ end
730
+ assert_equal 'J', oo.cell('v',1)
731
+ assert_equal 'P', oo.cell('w',1)
732
+ assert_equal 'B', oo.cell('x',1)
733
+ assert_equal 'All', oo.cell('y',1)
734
+ assert_equal 0, oo.cell('a',2)
735
+ assert oo.empty?('b',2)
736
+ assert oo.empty?('c',2)
737
+ assert oo.empty?('d',2)
738
+ assert_equal 'B', oo.cell('e',2)
739
+ assert_equal 'B', oo.cell('f',2)
740
+ assert_equal 'B', oo.cell('g',2)
741
+ assert_equal 'B', oo.cell('h',2)
742
+ assert_equal 'B', oo.cell('i',2)
743
+ assert_equal 'B', oo.cell('j',2)
744
+ assert_equal 'B', oo.cell('k',2)
745
+ assert_equal 'B', oo.cell('l',2)
746
+ assert_equal 'B', oo.cell('m',2)
747
+ assert_equal 'B', oo.cell('n',2)
748
+ assert_equal 'B', oo.cell('o',2)
749
+ assert_equal 'B', oo.cell('p',2)
750
+ assert_equal 'B', oo.cell('q',2)
751
+ assert_equal 'B', oo.cell('r',2)
752
+ assert_equal 'B', oo.cell('s',2)
753
+ assert oo.empty?('t',2)
754
+ assert oo.empty?('u',2)
755
+ assert_equal 0 , oo.cell('v',2)
756
+ assert_equal 0 , oo.cell('w',2)
757
+ assert_equal 15 , oo.cell('x',2)
758
+ assert_equal 15 , oo.cell('y',2)
759
+ end
760
+ end
761
+
762
+ def test_mehrteilig
763
+ with_each_spreadsheet(:name=>'Bibelbund1', :format=>:openoffice) do |oo|
764
+ assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
765
+ end
766
+ #if EXCELX
767
+ # #Datei gibt es noch nicht
768
+ # oo = Excelx.new(File.join(TESTDIR,"Bibelbund1.xlsx"))
769
+ # oo.default_sheet = oo.sheets.first
770
+ # assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
771
+ #end
772
+ end
773
+
774
+ def test_huge_document_to_csv
775
+ if LONG_RUN
776
+ with_each_spreadsheet(:name=>'Bibelbund') do |oo|
777
+ assert_nothing_raised(Timeout::Error) {
778
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
779
+ File.delete_if_exist("/tmp/Bibelbund.csv")
780
+ assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
781
+ assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
782
+ assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
783
+ assert oo.to_csv("/tmp/Bibelbund.csv")
784
+ assert File.exists?("/tmp/Bibelbund.csv")
785
+ assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
786
+ end
787
+ }
788
+ end
789
+ end
790
+ end
791
+
792
+ def test_to_csv
793
+ with_each_spreadsheet(:name=>'numbers1', :ignore=>:excel2003xml) do |oo|
794
+ master = "#{TESTDIR}/numbers1.csv"
795
+ File.delete_if_exist("/tmp/numbers1.csv")
796
+ assert oo.to_csv("/tmp/numbers1.csv",oo.sheets.first)
797
+ assert File.exists?("/tmp/numbers1.csv")
798
+ assert_equal "", `diff #{master} /tmp/numbers1.csv`
799
+ assert oo.to_csv("/tmp/numbers1.csv")
800
+ assert File.exists?("/tmp/numbers1.csv")
801
+ assert_equal "", `diff #{master} /tmp/numbers1.csv`
802
+ end
803
+ end
804
+
805
+ def test_bug_mehrere_datum
806
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
807
+ oo.default_sheet = 'Sheet5'
808
+ assert_equal :date, oo.celltype('A',4)
809
+ assert_equal :date, oo.celltype('B',4)
810
+ assert_equal :date, oo.celltype('C',4)
811
+ assert_equal :date, oo.celltype('D',4)
812
+ assert_equal :date, oo.celltype('E',4)
813
+ assert_equal Date.new(2007,11,21), oo.cell('A',4)
814
+ assert_equal Date.new(2007,11,21), oo.cell('B',4)
815
+ assert_equal Date.new(2007,11,21), oo.cell('C',4)
816
+ assert_equal Date.new(2007,11,21), oo.cell('D',4)
817
+ assert_equal Date.new(2007,11,21), oo.cell('E',4)
818
+ assert_equal :float, oo.celltype('A',5)
819
+ assert_equal :float, oo.celltype('B',5)
820
+ assert_equal :float, oo.celltype('C',5)
821
+ assert_equal :float, oo.celltype('D',5)
822
+ assert_equal :float, oo.celltype('E',5)
823
+ assert_equal 42, oo.cell('A',5)
824
+ assert_equal 42, oo.cell('B',5)
825
+ assert_equal 42, oo.cell('C',5)
826
+ assert_equal 42, oo.cell('D',5)
827
+ assert_equal 42, oo.cell('E',5)
828
+ assert_equal :string, oo.celltype('A',6)
829
+ assert_equal :string, oo.celltype('B',6)
830
+ assert_equal :string, oo.celltype('C',6)
831
+ assert_equal :string, oo.celltype('D',6)
832
+ assert_equal :string, oo.celltype('E',6)
833
+ assert_equal "ABC", oo.cell('A',6)
834
+ assert_equal "ABC", oo.cell('B',6)
835
+ assert_equal "ABC", oo.cell('C',6)
836
+ assert_equal "ABC", oo.cell('D',6)
837
+ assert_equal "ABC", oo.cell('E',6)
838
+ end
839
+ end
840
+
841
+ def test_multiple_sheets
842
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
843
+ 2.times do
844
+ oo.default_sheet = "Tabelle1"
845
+ assert_equal 1, oo.cell(1,1)
846
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
847
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
848
+ sheetname = 'Sheet5'
849
+ assert_equal :date, oo.celltype('A',4,sheetname)
850
+ assert_equal :date, oo.celltype('B',4,sheetname)
851
+ assert_equal :date, oo.celltype('C',4,sheetname)
852
+ assert_equal :date, oo.celltype('D',4,sheetname)
853
+ assert_equal :date, oo.celltype('E',4,sheetname)
854
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
855
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
856
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
857
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
858
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
859
+ assert_equal :float, oo.celltype('A',5,sheetname)
860
+ assert_equal :float, oo.celltype('B',5,sheetname)
861
+ assert_equal :float, oo.celltype('C',5,sheetname)
862
+ assert_equal :float, oo.celltype('D',5,sheetname)
863
+ assert_equal :float, oo.celltype('E',5,sheetname)
864
+ assert_equal 42, oo.cell('A',5,sheetname)
865
+ assert_equal 42, oo.cell('B',5,sheetname)
866
+ assert_equal 42, oo.cell('C',5,sheetname)
867
+ assert_equal 42, oo.cell('D',5,sheetname)
868
+ assert_equal 42, oo.cell('E',5,sheetname)
869
+ assert_equal :string, oo.celltype('A',6,sheetname)
870
+ assert_equal :string, oo.celltype('B',6,sheetname)
871
+ assert_equal :string, oo.celltype('C',6,sheetname)
872
+ assert_equal :string, oo.celltype('D',6,sheetname)
873
+ assert_equal :string, oo.celltype('E',6,sheetname)
874
+ assert_equal "ABC", oo.cell('A',6,sheetname)
875
+ assert_equal "ABC", oo.cell('B',6,sheetname)
876
+ assert_equal "ABC", oo.cell('C',6,sheetname)
877
+ assert_equal "ABC", oo.cell('D',6,sheetname)
878
+ assert_equal "ABC", oo.cell('E',6,sheetname)
879
+ oo.reload
880
+ end
881
+ end
882
+ end
883
+
884
+
885
+ def test_bug_empty_sheet
886
+ with_each_spreadsheet(:name=>'formula', :format=>[:openoffice, :excelx]) do |oo|
887
+ oo.default_sheet = 'Sheet3' # is an empty sheet
888
+ assert_nothing_raised(NoMethodError) { oo.to_csv(File.join("/","tmp","emptysheet.csv")) }
889
+ assert_equal "", `cat /tmp/emptysheet.csv`
890
+ end
891
+ end
892
+
893
+ def test_find_by_row_huge_document
894
+ if LONG_RUN
895
+ with_each_spreadsheet(:name=>'Bibelbund') do |oo|
896
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
897
+ oo.default_sheet = oo.sheets.first
898
+ rec = oo.find 20
899
+ assert rec
900
+ # assert_equal "Brief aus dem Sekretariat", rec[0]
901
+ #p rec
902
+ assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
903
+ rec = oo.find 22
904
+ assert rec
905
+ # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
906
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
907
+ end
908
+ end
909
+ end
910
+ end
911
+
912
+ def test_find_by_row
913
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
914
+ oo.header_line = nil
915
+ rec = oo.find 16
916
+ assert rec
917
+ assert_nil oo.header_line
918
+ # keine Headerlines in diesem Beispiel definiert
919
+ assert_equal "einundvierzig", rec[0]
920
+ #assert_equal false, rec
921
+ rec = oo.find 15
922
+ assert rec
923
+ assert_equal 41,rec[0]
924
+ end
925
+ end
926
+
927
+ def test_find_by_conditions
928
+ if LONG_RUN
929
+ with_each_spreadsheet(:name=>'Bibelbund') do |oo|
930
+ assert_nothing_raised(Timeout::Error) {
931
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
932
+ #-----------------------------------------------------------------
933
+ zeilen = oo.find(:all, :conditions => {
934
+ 'TITEL' => 'Brief aus dem Sekretariat'
935
+ }
936
+ )
937
+ assert_equal 2, zeilen.size
938
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
939
+ "INTERNET"=>nil,
940
+ "SEITE"=>316.0,
941
+ "KENNUNG"=>"Aus dem Bibelbund",
942
+ "OBJEKT"=>"Bibel+Gem",
943
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
944
+ "NUMMER"=>"1982-3",
945
+ "TITEL"=>"Brief aus dem Sekretariat"},
946
+ {"VERFASSER"=>"Almassy, Annelene von",
947
+ "INTERNET"=>nil,
948
+ "SEITE"=>222.0,
949
+ "KENNUNG"=>"Aus dem Bibelbund",
950
+ "OBJEKT"=>"Bibel+Gem",
951
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
952
+ "NUMMER"=>"1983-2",
953
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
954
+
955
+ #----------------------------------------------------------
956
+ zeilen = oo.find(:all,
957
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
958
+ )
959
+ assert_equal 13, zeilen.size
960
+ #----------------------------------------------------------
961
+ zeilen = oo.find(:all, :conditions => {
962
+ 'TITEL' => 'Brief aus dem Sekretariat',
963
+ 'VERFASSER' => 'Almassy, Annelene von',
964
+ }
965
+ )
966
+ assert_equal 2, zeilen.size
967
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
968
+ "INTERNET"=>nil,
969
+ "SEITE"=>316.0,
970
+ "KENNUNG"=>"Aus dem Bibelbund",
971
+ "OBJEKT"=>"Bibel+Gem",
972
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
973
+ "NUMMER"=>"1982-3",
974
+ "TITEL"=>"Brief aus dem Sekretariat"},
975
+ {"VERFASSER"=>"Almassy, Annelene von",
976
+ "INTERNET"=>nil,
977
+ "SEITE"=>222.0,
978
+ "KENNUNG"=>"Aus dem Bibelbund",
979
+ "OBJEKT"=>"Bibel+Gem",
980
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
981
+ "NUMMER"=>"1983-2",
982
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
983
+
984
+ # Result as an array
985
+ zeilen = oo.find(:all,
986
+ :conditions => {
987
+ 'TITEL' => 'Brief aus dem Sekretariat',
988
+ 'VERFASSER' => 'Almassy, Annelene von',
989
+ }, :array => true)
990
+ assert_equal 2, zeilen.size
991
+ assert_equal [
992
+ [
993
+ "Brief aus dem Sekretariat",
994
+ "Almassy, Annelene von",
995
+ "Bibel+Gem",
996
+ "1982-3",
997
+ 316.0,
998
+ nil,
999
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1000
+ "Aus dem Bibelbund",
1001
+ ],
1002
+ [
1003
+ "Brief aus dem Sekretariat",
1004
+ "Almassy, Annelene von",
1005
+ "Bibel+Gem",
1006
+ "1983-2",
1007
+ 222.0,
1008
+ nil,
1009
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1010
+ "Aus dem Bibelbund",
1011
+ ]] , zeilen
1012
+ end # Timeout
1013
+ } # nothing_raised
1014
+ end
1015
+ end
1016
+ end
1017
+
1018
+
1019
+ #TODO: temporaerer Test
1020
+ def test_seiten_als_date
1021
+ with_each_spreadsheet(:name=>'Bibelbund', :format=>:excelx) do |oo|
1022
+ assert_equal 'Bericht aus dem Sekretariat', oo.cell(13,1)
1023
+ assert_equal '1981-4', oo.cell(13,'D')
1024
+ assert_equal [:numeric_or_formula,"General"], oo.excelx_type(13,'E')
1025
+ assert_equal '428', oo.excelx_value(13,'E')
1026
+ assert_equal 428.0, oo.cell(13,'E')
1027
+ end
1028
+ end
1029
+
1030
+ def test_column
1031
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
1032
+ expected = [1.0,5.0,nil,10.0,Date.new(1961,11,21),'tata',nil,nil,nil,nil,'thisisa11',41.0,nil,nil,41.0,'einundvierzig',nil,Date.new(2007,5,31)]
1033
+ assert_equal expected, oo.column(1)
1034
+ assert_equal expected, oo.column('a')
1035
+ end
1036
+ end
1037
+
1038
+ def test_column_huge_document
1039
+ if LONG_RUN
1040
+ with_each_spreadsheet(:name=>'Bibelbund') do |oo|
1041
+ assert_nothing_raised(Timeout::Error) {
1042
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1043
+ oo.default_sheet = oo.sheets.first
1044
+ assert_equal 3735, oo.column('a').size
1045
+ #assert_equal 499, oo.column('a').size
1046
+ end
1047
+ }
1048
+ end
1049
+ end
1050
+ end
1051
+
1052
+ def test_simple_spreadsheet_find_by_condition
1053
+ with_each_spreadsheet(:name=>'simple_spreadsheet') do |oo|
1054
+ oo.header_line = 3
1055
+ oo.date_format = '%m/%d/%Y' if oo.class == Google
1056
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
1057
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
1058
+ assert_equal 10.75 , erg[1]['Start time']
1059
+ assert_equal 12.50 , erg[1]['End time']
1060
+ assert_equal 0 , erg[1]['Pause']
1061
+ assert_equal 1.75 , erg[1]['Sum'] unless oo.class == Excel
1062
+ assert_equal "Task 1" , erg[1]['Comment']
1063
+ end
1064
+ end
1065
+
1066
+ # Ruby-spreadsheet now allows us to at least give the current value
1067
+ # from a cell with a formula (no possible with parseexcel)
1068
+ def test_bug_false_borders_with_formulas
1069
+ with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
1070
+ assert_equal 1, oo.first_row
1071
+ assert_equal 3, oo.last_row
1072
+ assert_equal 1, oo.first_column
1073
+ assert_equal 4, oo.last_column
1074
+ end
1075
+ end
1076
+
1077
+ # We'ce added minimal formula support so we can now read these
1078
+ # though not sure how the spreadsheet reports older values....
1079
+ def test_fe
1080
+ with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
1081
+ assert_equal Date.new(2007,11,1), oo.cell('a',1)
1082
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, oo.formula?('a',1)
1083
+ #DOES NOT WORK IN EXCEL FILES: assert_equal '=TODAY()', oo.formula('a',1)
1084
+
1085
+ assert_equal Date.new(2008,2,9), oo.cell('B',1)
1086
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, oo.formula?('B',1)
1087
+ #DOES NOT WORK IN EXCEL FILES: assert_equal "=A1+100", oo.formula('B',1)
1088
+
1089
+ assert_kind_of DateTime, oo.cell('C',1)
1090
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, oo.formula?('C',1)
1091
+ #DOES NOT WORK IN EXCEL FILES: assert_equal "=C1", oo.formula('C',1)
1092
+
1093
+ assert_equal 'H1', oo.cell('A',2)
1094
+ assert_equal 'H2', oo.cell('B',2)
1095
+ assert_equal 'H3', oo.cell('C',2)
1096
+ assert_equal 'H4', oo.cell('D',2)
1097
+ assert_equal 'R1', oo.cell('A',3)
1098
+ assert_equal 'R2', oo.cell('B',3)
1099
+ assert_equal 'R3', oo.cell('C',3)
1100
+ assert_equal 'R4', oo.cell('D',3)
1101
+ end
1102
+ end
1103
+
1104
+ def test_excel_does_not_support_formulas
1105
+ with_each_spreadsheet(:name=>'false_encoding', :format=>:excel) do |oo|
1106
+ assert_raise(RuntimeError) { void = oo.formula('a',1) }
1107
+ assert_raise(RuntimeError) { void = oo.formula?('a',1) }
1108
+ assert_raise(RuntimeError) { void = oo.formulas(oo.sheets.first) }
1109
+ end
1110
+ end
1111
+
1112
+ def get_extension(oo)
1113
+ case oo
1114
+ when Openoffice
1115
+ ".ods"
1116
+ when Excel
1117
+ ".xls"
1118
+ when Excelx
1119
+ ".xlsx"
1120
+ when Excel2003XML
1121
+ ".xml"
1122
+ when Google
1123
+ ""
1124
+ end
1125
+ end
1126
+
1127
+ def test_info
1128
+ expected_templ = "File: numbers1%s\n"+
1129
+ "Number of sheets: 5\n"+
1130
+ "Sheets: Tabelle1, Name of Sheet 2, Sheet3, Sheet4, Sheet5\n"+
1131
+ "Sheet 1:\n"+
1132
+ " First row: 1\n"+
1133
+ " Last row: 18\n"+
1134
+ " First column: A\n"+
1135
+ " Last column: G\n"+
1136
+ "Sheet 2:\n"+
1137
+ " First row: 5\n"+
1138
+ " Last row: 14\n"+
1139
+ " First column: B\n"+
1140
+ " Last column: E\n"+
1141
+ "Sheet 3:\n"+
1142
+ " First row: 1\n"+
1143
+ " Last row: 1\n"+
1144
+ " First column: A\n"+
1145
+ " Last column: BA\n"+
1146
+ "Sheet 4:\n"+
1147
+ " First row: 1\n"+
1148
+ " Last row: 1\n"+
1149
+ " First column: A\n"+
1150
+ " Last column: E\n"+
1151
+ "Sheet 5:\n"+
1152
+ " First row: 1\n"+
1153
+ " Last row: 6\n"+
1154
+ " First column: A\n"+
1155
+ " Last column: E"
1156
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
1157
+ ext = get_extension(oo)
1158
+ expected = sprintf(expected_templ,ext)
1159
+ if oo.class == Google
1160
+ assert_equal expected.gsub(/numbers1/,key_of("numbers1")), oo.info
1161
+ else
1162
+ assert_equal expected, oo.info
1163
+ end
1164
+ end
1165
+ end
1166
+
1167
+ def test_bug_excel_numbers1_sheet5_last_row
1168
+ with_each_spreadsheet(:name=>'numbers1', :format=>:excel) do |oo|
1169
+ oo.default_sheet = "Tabelle1"
1170
+ assert_equal 1, oo.first_row
1171
+ assert_equal 18, oo.last_row
1172
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
1173
+ assert_equal Openoffice.letter_to_number('G'), oo.last_column
1174
+ oo.default_sheet = "Name of Sheet 2"
1175
+ assert_equal 5, oo.first_row
1176
+ assert_equal 14, oo.last_row
1177
+ assert_equal Openoffice.letter_to_number('B'), oo.first_column
1178
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
1179
+ oo.default_sheet = "Sheet3"
1180
+ assert_equal 1, oo.first_row
1181
+ assert_equal 1, oo.last_row
1182
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
1183
+ assert_equal Openoffice.letter_to_number('BA'), oo.last_column
1184
+ oo.default_sheet = "Sheet4"
1185
+ assert_equal 1, oo.first_row
1186
+ assert_equal 1, oo.last_row
1187
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
1188
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
1189
+ oo.default_sheet = "Sheet5"
1190
+ assert_equal 1, oo.first_row
1191
+ assert_equal 6, oo.last_row
1192
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
1193
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
1194
+ end
1195
+ end
1196
+
1197
+ def test_should_raise_file_not_found_error
1198
+ if OPENOFFICE
1199
+ assert_raise(IOError) {
1200
+ oo = Openoffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
1201
+ }
1202
+ end
1203
+ if EXCEL
1204
+ assert_raise(IOError) {
1205
+ oo = Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
1206
+ }
1207
+ end
1208
+ if EXCELX
1209
+ assert_raise(IOError) {
1210
+ oo = Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
1211
+ }
1212
+ end
1213
+ if GOOGLE
1214
+ # assert_raise(Net::HTTPServerException) {
1215
+ # oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
1216
+ # oo = Google.new('testnichtvorhanden')
1217
+ # }
1218
+ end
1219
+ end
1220
+
1221
+ def test_write_google
1222
+ # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
1223
+
1224
+ with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1225
+ oo.set_value(1,1,"hello from the tests")
1226
+ assert_equal "hello from the tests", oo.cell(1,1)
1227
+ oo.set_value(1,1, 1.0)
1228
+ assert_equal 1.0, oo.cell(1,1)
1229
+ end
1230
+ end
1231
+
1232
+ def test_bug_set_value_with_more_than_one_sheet_google
1233
+ # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
1234
+ with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1235
+ content1 = 'AAA'
1236
+ content2 = 'BBB'
1237
+ oo.default_sheet = oo.sheets.first
1238
+ oo.set_value(1,1,content1)
1239
+ oo.default_sheet = oo.sheets[1]
1240
+ oo.set_value(1,1,content2) # in the second sheet
1241
+ oo.default_sheet = oo.sheets.first
1242
+ assert_equal content1, oo.cell(1,1)
1243
+ oo.default_sheet = oo.sheets[1]
1244
+ assert_equal content2, oo.cell(1,1)
1245
+ end
1246
+ end
1247
+
1248
+ def test_set_value_with_sheet_argument_google
1249
+ with_each_spreadsheet(:name=>'write.me', :format=>:google) do |oo|
1250
+ random_row = rand(10)+1
1251
+ random_column = rand(10)+1
1252
+ content1 = 'ABC'
1253
+ content2 = 'DEF'
1254
+ oo.set_value(random_row,random_column,content1,oo.sheets.first)
1255
+ oo.set_value(random_row,random_column,content2,oo.sheets[1])
1256
+ assert_equal content1, oo.cell(random_row,random_column,oo.sheets.first)
1257
+ assert_equal content2, oo.cell(random_row,random_column,oo.sheets[1])
1258
+ end
1259
+ end
1260
+
1261
+ def test_set_value_for_non_existing_sheet_google
1262
+ with_each_spreadsheet(:name=>'ptu6bbahNZpY0N0RrxQbWdw', :format=>:google) do |oo|
1263
+ assert_raise(RangeError) { oo.set_value(1,1,"dummy","no_sheet") }
1264
+ end
1265
+ end
1266
+
1267
+ def test_bug_bbu
1268
+ with_each_spreadsheet(:name=>'bbu', :format=>[:openoffice, :excelx, :excel]) do |oo|
1269
+ assert_nothing_raised() {
1270
+ assert_equal "File: bbu#{get_extension(oo)}
1271
+ Number of sheets: 3
1272
+ Sheets: 2007_12, Tabelle2, Tabelle3
1273
+ Sheet 1:
1274
+ First row: 1
1275
+ Last row: 4
1276
+ First column: A
1277
+ Last column: F
1278
+ Sheet 2:
1279
+ - empty -
1280
+ Sheet 3:
1281
+ - empty -", oo.info
1282
+ }
1283
+
1284
+ oo.default_sheet = oo.sheets[1] # empty sheet
1285
+ assert_nil oo.first_row
1286
+ assert_nil oo.last_row
1287
+ assert_nil oo.first_column
1288
+ assert_nil oo.last_column
1289
+ end
1290
+ end
1291
+
1292
+
1293
+ def test_bug_time_nil
1294
+ with_each_spreadsheet(:name=>'time-test', :ignore=>:excel2003xml) do |oo|
1295
+ assert_equal 12*3600+13*60+14, oo.cell('B',1) # 12:13:14 (secs since midnight)
1296
+ assert_equal :time, oo.celltype('B',1)
1297
+ assert_equal 15*3600+16*60, oo.cell('C',1) # 15:16 (secs since midnight)
1298
+ assert_equal :time, oo.celltype('C',1)
1299
+ assert_equal 23*3600, oo.cell('D',1) # 23:00 (secs since midnight)
1300
+ assert_equal :time, oo.celltype('D',1)
1301
+ end
1302
+ end
1303
+
1304
+ def test_date_time_to_csv
1305
+ with_each_spreadsheet(:name=>'time-test',:ignore=>:excel2003xml) do |oo|
1306
+ begin
1307
+ assert oo.to_csv("/tmp/time-test.csv")
1308
+ assert File.exists?("/tmp/time-test.csv")
1309
+ assert_equal "", `diff #{TESTDIR}/time-test.csv /tmp/time-test.csv`
1310
+ ensure
1311
+ File.delete_if_exist("/tmp/time-test.csv")
1312
+ end
1313
+ end
1314
+ end
1315
+
1316
+ def test_date_time_yaml
1317
+ with_each_spreadsheet(:name=>'time-test') do |oo|
1318
+ expected =
1319
+ "--- \ncell_1_1: \n row: 1 \n col: 1 \n celltype: string \n value: Mittags: \ncell_1_2: \n row: 1 \n col: 2 \n celltype: time \n value: 12:13:14 \ncell_1_3: \n row: 1 \n col: 3 \n celltype: time \n value: 15:16:00 \ncell_1_4: \n row: 1 \n col: 4 \n celltype: time \n value: 23:00:00 \ncell_2_1: \n row: 2 \n col: 1 \n celltype: date \n value: 2007-11-21 \n"
1320
+ assert_equal expected, oo.to_yaml
1321
+ end
1322
+ end
1323
+
1324
+ def test_no_remaining_tmp_files_openoffice
1325
+ if OPENOFFICE
1326
+ assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei
1327
+ # oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
1328
+ # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
1329
+ oo = Openoffice.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
1330
+ false,
1331
+ :ignore)
1332
+ }
1333
+ a=Dir.glob("oo_*")
1334
+ assert_equal [], a
1335
+ end
1336
+ end
1337
+
1338
+ def test_no_remaining_tmp_files_excel
1339
+ if EXCEL
1340
+ assert_raise(Ole::Storage::FormatError) {
1341
+ # oo = Excel.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
1342
+ # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
1343
+ oo = Excel.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
1344
+ false,
1345
+ :ignore)
1346
+ }
1347
+ a=Dir.glob("oo_*")
1348
+ assert_equal [], a
1349
+ end
1350
+ end
1351
+
1352
+ def test_no_remaining_tmp_files_excelx
1353
+ if EXCELX
1354
+ assert_raise(Zip::ZipError) { #TODO: besseres Fehlerkriterium bei
1355
+
1356
+ # oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"))
1357
+ # es soll absichtlich ein Abbruch provoziert werden, deshalb :ignore
1358
+ oo = Excelx.new(File.join(TESTDIR,"no_spreadsheet_file.txt"),
1359
+ false,
1360
+ :ignore)
1361
+
1362
+ }
1363
+ a=Dir.glob("oo_*")
1364
+ assert_equal [], a
1365
+ end
1366
+ end
1367
+
1368
+ def test_no_remaining_tmp_files_google
1369
+ if GOOGLE
1370
+ assert_raise(GoogleReadError) {
1371
+ oo = Google.new(key_of("no_spreadsheet_file.txt"))
1372
+ }
1373
+ a=Dir.glob("oo_*")
1374
+ assert_equal [], a
1375
+ end
1376
+ end
1377
+
1378
+ # Erstellt eine Liste aller Zellen im Spreadsheet. Dies ist nötig, weil ein einfacher
1379
+ # Textvergleich des XML-Outputs nicht funktioniert, da xml-builder die Attribute
1380
+ # nicht immer in der gleichen Reihenfolge erzeugt.
1381
+ def init_all_cells(oo,sheet)
1382
+ all = []
1383
+ oo.first_row(sheet).upto(oo.last_row(sheet)) do |row|
1384
+ oo.first_column(sheet).upto(oo.last_column(sheet)) do |col|
1385
+ unless oo.empty?(row,col,sheet)
1386
+ all << {:row => row.to_s,
1387
+ :column => col.to_s,
1388
+ :content => oo.cell(row,col,sheet).to_s,
1389
+ :type => oo.celltype(row,col,sheet).to_s,
1390
+ }
1391
+ end
1392
+ end
1393
+ end
1394
+ all
1395
+ end
1396
+
1397
+ def test_to_xml
1398
+ with_each_spreadsheet(:name=>'numbers1') do |oo|
1399
+ assert_nothing_raised {oo.to_xml}
1400
+ sheetname = oo.sheets.first
1401
+ doc = XML::Parser.string(oo.to_xml).parse
1402
+ doc.root.each_element {|xml_sheet|
1403
+ all_cells = init_all_cells(oo, sheetname)
1404
+ x = 0
1405
+ assert_equal sheetname, xml_sheet.attributes['name']
1406
+ xml_sheet.each_element {|cell|
1407
+ expected = [all_cells[x][:row],
1408
+ all_cells[x][:column],
1409
+ all_cells[x][:content],
1410
+ all_cells[x][:type],
1411
+ ]
1412
+ result = [
1413
+ cell.attributes['row'],
1414
+ cell.attributes['column'],
1415
+ cell.content,
1416
+ cell.attributes['type'],
1417
+ ]
1418
+ assert_equal expected, result
1419
+ x += 1
1420
+ } # end of sheet
1421
+ sheetname = oo.sheets[oo.sheets.index(sheetname)+1]
1422
+ }
1423
+ end
1424
+ end
1425
+
1426
+ def test_bug_row_column_fixnum_float
1427
+ with_each_spreadsheet(:name=>'bug-row-column-fixnum-float', :format=>:excel) do |oo|
1428
+ assert_equal 42.5, oo.cell('b',2)
1429
+ assert_equal 43 , oo.cell('c',2)
1430
+ assert_equal ['hij',42.5, 43], oo.row(2)
1431
+ assert_equal ['def',42.5, 'nop'], oo.column(2)
1432
+ end
1433
+ end
1434
+
1435
+ def test_file_warning_default
1436
+ if OPENOFFICE
1437
+ assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls")) }
1438
+ assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx")) }
1439
+ assert_equal [], Dir.glob("oo_*")
1440
+ end
1441
+ if EXCEL
1442
+ assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods")) }
1443
+ assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx")) }
1444
+ assert_equal [], Dir.glob("oo_*")
1445
+ end
1446
+ if EXCELX
1447
+ assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods")) }
1448
+ assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls")) }
1449
+ assert_equal [], Dir.glob("oo_*")
1450
+ end
1451
+ end
1452
+
1453
+ def test_file_warning_error
1454
+ if OPENOFFICE
1455
+ assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
1456
+ assert_raises(TypeError) { oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
1457
+ assert_equal [], Dir.glob("oo_*")
1458
+ end
1459
+ if EXCEL
1460
+ assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
1461
+ assert_raises(TypeError) { oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false,:error) }
1462
+ assert_equal [], Dir.glob("oo_*")
1463
+ end
1464
+ if EXCELX
1465
+ assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false,:error) }
1466
+ assert_raises(TypeError) { oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false,:error) }
1467
+ assert_equal [], Dir.glob("oo_*")
1468
+ end
1469
+ end
1470
+
1471
+ def test_file_warning_warning
1472
+ if OPENOFFICE
1473
+ assert_nothing_raised(TypeError) {
1474
+ assert_raises(Zip::ZipError) {
1475
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :warning)
1476
+ }
1477
+ }
1478
+ assert_nothing_raised(TypeError) {
1479
+ assert_raises(Errno::ENOENT) {
1480
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning)
1481
+ }
1482
+ }
1483
+ assert_equal [], Dir.glob("oo_*")
1484
+ end
1485
+ if EXCEL
1486
+ assert_nothing_raised(TypeError) {
1487
+ assert_raises(Ole::Storage::FormatError) {
1488
+ oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false, :warning) }
1489
+ }
1490
+ assert_nothing_raised(TypeError) {
1491
+ assert_raises(Ole::Storage::FormatError) {
1492
+ oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false, :warning) }
1493
+ }
1494
+ assert_equal [], Dir.glob("oo_*")
1495
+ end
1496
+ if EXCELX
1497
+ assert_nothing_raised(TypeError) {
1498
+ assert_raises(Errno::ENOENT) {
1499
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false, :warning) }
1500
+ }
1501
+ assert_nothing_raised(TypeError) {
1502
+ assert_raises(Zip::ZipError) {
1503
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false, :warning) }
1504
+ }
1505
+ assert_equal [], Dir.glob("oo_*")
1506
+ end
1507
+ end
1508
+
1509
+ def test_file_warning_ignore
1510
+ if OPENOFFICE
1511
+ assert_nothing_raised(TypeError) {
1512
+ assert_raises(Zip::ZipError) {
1513
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.xls"),false, :ignore) }
1514
+ }
1515
+ assert_nothing_raised(TypeError) {
1516
+ assert_raises(Errno::ENOENT) {
1517
+ oo = Openoffice.new(File.join(TESTDIR,"numbers1.xlsx"),false, :ignore) }
1518
+ }
1519
+ assert_equal [], Dir.glob("oo_*")
1520
+ end
1521
+ if EXCEL
1522
+ assert_nothing_raised(TypeError) {
1523
+ assert_raises(Ole::Storage::FormatError) {
1524
+ oo = Excel.new(File.join(TESTDIR,"numbers1.ods"),false, :ignore) }
1525
+ }
1526
+ assert_nothing_raised(TypeError) {
1527
+ assert_raises(Ole::Storage::FormatError) {oo = Excel.new(File.join(TESTDIR,"numbers1.xlsx"),false, :ignore) }}
1528
+ assert_equal [], Dir.glob("oo_*")
1529
+ end
1530
+ if EXCELX
1531
+ assert_nothing_raised(TypeError) {
1532
+ assert_raises(Errno::ENOENT) {
1533
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.ods"),false, :ignore)
1534
+ }
1535
+ }
1536
+ assert_nothing_raised(TypeError) {
1537
+ assert_raises(Zip::ZipError) {
1538
+ oo = Excelx.new(File.join(TESTDIR,"numbers1.xls"),false, :ignore)
1539
+ }
1540
+ }
1541
+ assert_equal [], Dir.glob("oo_*")
1542
+ end
1543
+ end
1544
+
1545
+ def test_bug_last_row_excel
1546
+ with_each_spreadsheet(:name=>'time-test', :format=>:excel) do |oo|
1547
+ assert_equal 2, oo.last_row
1548
+ end
1549
+ end
1550
+
1551
+ def test_bug_to_xml_with_empty_sheets
1552
+ with_each_spreadsheet(:name=>'emptysheets', :format=>[:openoffice, :excel]) do |oo|
1553
+ oo.sheets.each { |sheet|
1554
+ assert_equal nil, oo.first_row, "first_row not nil in sheet #{sheet}"
1555
+ assert_equal nil, oo.last_row, "last_row not nil in sheet #{sheet}"
1556
+ assert_equal nil, oo.first_column, "first_column not nil in sheet #{sheet}"
1557
+ assert_equal nil, oo.last_column, "last_column not nil in sheet #{sheet}"
1558
+ assert_equal nil, oo.first_row(sheet), "first_row not nil in sheet #{sheet}"
1559
+ assert_equal nil, oo.last_row(sheet), "last_row not nil in sheet #{sheet}"
1560
+ assert_equal nil, oo.first_column(sheet), "first_column not nil in sheet #{sheet}"
1561
+ assert_equal nil, oo.last_column(sheet), "last_column not nil in sheet #{sheet}"
1562
+ }
1563
+ assert_nothing_raised() { result = oo.to_xml }
1564
+ end
1565
+ end
1566
+
1567
+ def test_bug_simple_spreadsheet_time_bug
1568
+ # really a bug? are cells really of type time?
1569
+ # No! :float must be the correct type
1570
+ with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
1571
+ # puts oo.cell('B',5).to_s
1572
+ # assert_equal :time, oo.celltype('B',5)
1573
+ assert_equal :float, oo.celltype('B',5)
1574
+ assert_equal 10.75, oo.cell('B',5)
1575
+ assert_equal 12.50, oo.cell('C',5)
1576
+ assert_equal 0, oo.cell('D',5)
1577
+ assert_equal 1.75, oo.cell('E',5)
1578
+ assert_equal 'Task 1', oo.cell('F',5)
1579
+ assert_equal Date.new(2007,5,7), oo.cell('A',5)
1580
+ end
1581
+ end
1582
+
1583
+ def test_simple2_excelx
1584
+ with_each_spreadsheet(:name=>'simple_spreadsheet', :format=>:excelx) do |oo|
1585
+ assert_equal [:numeric_or_formula, "yyyy\\-mm\\-dd"], oo.excelx_type('A',4)
1586
+ assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('B',4)
1587
+ assert_equal [:numeric_or_formula, "#,##0.00"], oo.excelx_type('c',4)
1588
+ assert_equal [:numeric_or_formula, "General"], oo.excelx_type('d',4)
1589
+ assert_equal [:numeric_or_formula, "General"], oo.excelx_type('e',4)
1590
+ assert_equal :string, oo.excelx_type('f',4)
1591
+
1592
+ assert_equal "39209", oo.excelx_value('a',4)
1593
+ assert_equal "yyyy\\-mm\\-dd", oo.excelx_format('a',4)
1594
+ assert_equal "9.25", oo.excelx_value('b',4)
1595
+ assert_equal "10.25", oo.excelx_value('c',4)
1596
+ assert_equal "0", oo.excelx_value('d',4)
1597
+ #... Sum-Spalte
1598
+ # assert_equal "Task 1", oo.excelx_value('f',4)
1599
+ assert_equal "Task 1", oo.cell('f',4)
1600
+ assert_equal Date.new(2007,05,07), oo.cell('a',4)
1601
+ assert_equal "9.25", oo.excelx_value('b',4)
1602
+ assert_equal "#,##0.00", oo.excelx_format('b',4)
1603
+ assert_equal 9.25, oo.cell('b',4)
1604
+ assert_equal :float, oo.celltype('b',4)
1605
+ assert_equal :float, oo.celltype('d',4)
1606
+ assert_equal 0, oo.cell('d',4)
1607
+ assert_equal :formula, oo.celltype('e',4)
1608
+ assert_equal 1, oo.cell('e',4)
1609
+ assert_equal 'C4-B4-D4', oo.formula('e',4)
1610
+ assert_equal :string, oo.celltype('f',4)
1611
+ assert_equal "Task 1", oo.cell('f',4)
1612
+ end
1613
+ end
1614
+
1615
+ def test_datetime
1616
+ with_each_spreadsheet(:name=>'datetime') do |oo|
1617
+ val = oo.cell('c',3)
1618
+ assert_kind_of DateTime, val
1619
+ assert_equal :datetime, oo.celltype('c',3)
1620
+ assert_equal DateTime.new(1961,11,21,12,17,18), val
1621
+ val = oo.cell('a',1)
1622
+ assert_kind_of Date, val
1623
+ assert_equal :date, oo.celltype('a',1)
1624
+ assert_equal Date.new(1961,11,21), val
1625
+ assert_equal Date.new(1961,11,21), oo.cell('a',1)
1626
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',3)
1627
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',3)
1628
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',3)
1629
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',4)
1630
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',4)
1631
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',4)
1632
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('a',5)
1633
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('b',5)
1634
+ assert_equal DateTime.new(1961,11,21,12,17,18), oo.cell('c',5)
1635
+ assert_equal Date.new(1961,11,21), oo.cell('a',6)
1636
+ assert_equal Date.new(1961,11,21), oo.cell('b',6)
1637
+ assert_equal Date.new(1961,11,21), oo.cell('c',6)
1638
+ assert_equal Date.new(1961,11,21), oo.cell('a',7)
1639
+ assert_equal Date.new(1961,11,21), oo.cell('b',7)
1640
+ assert_equal Date.new(1961,11,21), oo.cell('c',7)
1641
+ end
1642
+ end
1643
+
1644
+ def test_cell_openoffice_html_escape
1645
+ with_each_spreadsheet(:name=>'html-escape', :format=>:openoffice) do |oo|
1646
+ assert_equal "'", oo.cell(1,1)
1647
+ assert_equal "&", oo.cell(2,1)
1648
+ assert_equal ">", oo.cell(3,1)
1649
+ assert_equal "<", oo.cell(4,1)
1650
+ assert_equal "`", oo.cell(5,1)
1651
+ # test_openoffice_zipped will catch issues with &quot;
1652
+ end
1653
+ end
1654
+
1655
+ def test_cell_boolean
1656
+ with_each_spreadsheet(:name=>'boolean', :format=>[:openoffice, :excel, :excelx]) do |oo|
1657
+ if oo.class == Excelx
1658
+ assert_equal "TRUE", oo.cell(1,1)
1659
+ assert_equal "FALSE", oo.cell(2,1)
1660
+ else
1661
+ assert_equal "true", oo.cell(1,1)
1662
+ assert_equal "false", oo.cell(2,1)
1663
+ end
1664
+ end
1665
+ end
1666
+
1667
+ def test_cell_multiline
1668
+ with_each_spreadsheet(:name=>'paragraph', :format=>[:openoffice, :excel, :excelx]) do |oo|
1669
+ assert_equal "This is a test\nof a multiline\nCell", oo.cell(1,1)
1670
+ assert_equal "This is a test\n¶\nof a multiline\n\nCell", oo.cell(1,2)
1671
+ assert_equal "first p\n\nsecond p\n\nlast p", oo.cell(2,1)
1672
+ end
1673
+ end
1674
+
1675
+ def test_cell_styles
1676
+ with_each_spreadsheet(:name=>'style', :format=>[:openoffice, :excel, :excelx, :excel2003xml]) do |oo|
1677
+ # bold
1678
+ assert_equal true, oo.font(1,1).bold?
1679
+ assert_equal false, oo.font(1,1).italic?
1680
+ assert_equal false, oo.font(1,1).underline?
1681
+
1682
+ # italic
1683
+ assert_equal false, oo.font(2,1).bold?
1684
+ assert_equal true, oo.font(2,1).italic?
1685
+ assert_equal false, oo.font(2,1).underline?
1686
+
1687
+ # normal
1688
+ assert_equal false, oo.font(3,1).bold?
1689
+ assert_equal false, oo.font(3,1).italic?
1690
+ assert_equal false, oo.font(3,1).underline?
1691
+
1692
+ # underline
1693
+ assert_equal false, oo.font(4,1).bold?
1694
+ assert_equal false, oo.font(4,1).italic?
1695
+ assert_equal true, oo.font(4,1).underline?
1696
+
1697
+ # bold italic
1698
+ assert_equal true, oo.font(5,1).bold?
1699
+ assert_equal true, oo.font(5,1).italic?
1700
+ assert_equal false, oo.font(5,1).underline?
1701
+
1702
+ # bold underline
1703
+ assert_equal true, oo.font(6,1).bold?
1704
+ assert_equal false, oo.font(6,1).italic?
1705
+ assert_equal true, oo.font(6,1).underline?
1706
+
1707
+ # italic underline
1708
+ assert_equal false, oo.font(7,1).bold?
1709
+ assert_equal true, oo.font(7,1).italic?
1710
+ assert_equal true, oo.font(7,1).underline?
1711
+
1712
+ # bolded row
1713
+ assert_equal true, oo.font(8,1).bold?
1714
+ assert_equal false, oo.font(8,1).italic?
1715
+ assert_equal false, oo.font(8,1).underline?
1716
+
1717
+ # bolded col
1718
+ assert_equal true, oo.font(9,2).bold?
1719
+ assert_equal false, oo.font(9,2).italic?
1720
+ assert_equal false, oo.font(9,2).underline?
1721
+
1722
+ # bolded row, italic col
1723
+ assert_equal true, oo.font(10,3).bold?
1724
+ assert_equal true, oo.font(10,3).italic?
1725
+ assert_equal false, oo.font(10,3).underline?
1726
+
1727
+ # normal
1728
+ assert_equal false, oo.font(11,4).bold?
1729
+ assert_equal false, oo.font(11,4).italic?
1730
+ assert_equal false, oo.font(11,4).underline?
1731
+ end
1732
+ end
1733
+
1734
+ # If a cell has a date-like string but is preceeded by a '
1735
+ # to force that date to be treated like a string, we were getting an exception.
1736
+ # This test just checks for that exception to make sure it's not raised in this case
1737
+ def test_date_to_float_conversion
1738
+ with_each_spreadsheet(:name=>'datetime_floatconv', :format=>:excel) do |oo|
1739
+ assert_nothing_raised(NoMethodError) do
1740
+ oo.cell('a',1)
1741
+ oo.cell('a',2)
1742
+ end
1743
+ end
1744
+ end
1745
+
1746
+ # Need to extend to other formats
1747
+ def test_row_whitespace
1748
+ with_each_spreadsheet(:name=>'whitespace') do |oo|
1749
+ oo.default_sheet = "Sheet1"
1750
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(1)
1751
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(2)
1752
+ assert_equal ["Date", "Start time", "End time", "Pause", "Sum", "Comment"], oo.row(3)
1753
+ assert_equal [Date.new(2007,5,7), 9.25, 10.25, 0.0, 1.0, "Task 1"], oo.row(4)
1754
+ assert_equal [nil, nil, nil, nil, nil, nil], oo.row(5)
1755
+ assert_equal [Date.new(2007,5,7), 10.75, 10.75, 0.0, 0.0, "Task 1"], oo.row(6)
1756
+ oo.default_sheet = "Sheet2"
1757
+ assert_equal ["Date", nil, "Start time"], oo.row(1)
1758
+ assert_equal [Date.new(2007,5,7), nil, 9.25], oo.row(2)
1759
+ assert_equal [Date.new(2007,5,7), nil, 10.75], oo.row(3)
1760
+ end
1761
+ end
1762
+
1763
+ def test_col_whitespace
1764
+ with_each_spreadsheet(:name=>'whitespace') do |oo|
1765
+ oo.default_sheet = "Sheet1"
1766
+ assert_equal ["Date", Date.new(2007,5,7), nil, Date.new(2007,5,7)], oo.column(1)
1767
+ assert_equal ["Start time", 9.25, nil, 10.75], oo.column(2)
1768
+ assert_equal ["End time", 10.25, nil, 10.75], oo.column(3)
1769
+ assert_equal ["Pause", 0.0, nil, 0.0], oo.column(4)
1770
+ assert_equal ["Sum", 1.0, nil, 0.0], oo.column(5)
1771
+ assert_equal ["Comment","Task 1", nil, "Task 1"], oo.column(6)
1772
+ oo.default_sheet = "Sheet2"
1773
+ assert_equal [nil, nil, nil], oo.column(1)
1774
+ assert_equal [nil, nil, nil], oo.column(2)
1775
+ assert_equal ["Date", Date.new(2007,5,7), Date.new(2007,5,7)], oo.column(3)
1776
+ assert_equal [nil, nil, nil], oo.column(4)
1777
+ assert_equal [ "Start time", 9.25, 10.75], oo.column(5)
1778
+ end
1779
+ end
1780
+
1781
+
1782
+ def test_ruby_spreadsheet_formula_bug
1783
+ with_each_spreadsheet(:name=>'formula_parse_error', :format=>:excel) do |oo|
1784
+ assert_equal '5026', oo.cell(2,3)
1785
+ assert_equal '5026', oo.cell(3,3)
1786
+ end
1787
+ end
1788
+
1789
+
1790
+ # Excel has two base date formats one from 1900 and the other from 1904.
1791
+ # There's a MS bug that 1900 base dates include an extra day due to erroneously
1792
+ # including 1900 as a leap yar.
1793
+ def test_base_dates_in_excel
1794
+ with_each_spreadsheet(:name=>'1900_base', :format=>:excel) do |oo|
1795
+ assert_equal Date.new(2009,06,15), oo.cell(1,1)
1796
+ assert_equal Date.new(2009,06,28), oo.cell(2,1) #formula for TODAY(), last calculated on 06.28
1797
+ assert_equal :date, oo.celltype(1,1)
1798
+ end
1799
+ with_each_spreadsheet(:name=>'1904_base', :format=>:excel) do |oo|
1800
+ assert_equal Date.new(2009,06,15), oo.cell(1,1)
1801
+ assert_equal Date.new(2009,06,28), oo.cell(2,1) #formula for TODAY(), last calculated on 06.28
1802
+ assert_equal :date, oo.celltype(1,1)
1803
+ end
1804
+ end
1805
+
1806
+
1807
+ def test_bad_excel_date
1808
+ with_each_spreadsheet(:name=>'bad_exceL_date', :format=>:excel) do |oo|
1809
+ assert_nothing_raised(ArgumentError) {
1810
+ assert_equal DateTime.new(2006,2,2,10,0,0), oo.cell('a',1)
1811
+ }
1812
+ end
1813
+ end
1814
+
1815
+ def test_public_google_doc
1816
+ return unless GOOGLE
1817
+ with_public_google_spreadsheet do
1818
+ assert_raise(GoogleHTTPError) { Google.new("foo") }
1819
+ assert_raise(GoogleReadError) { Google.new(key_of('numbers1'))}
1820
+ assert_nothing_raised { Google.new("0AncOJVyN5MMMcjZtN0hGbFVPd3N0MFJUVVR1aFEwT3c") } # use spreadsheet key (private)
1821
+ assert_nothing_raised { Google.new(key_of('write.me')) } # use spreadsheet key (public)
1822
+ end
1823
+ end
1824
+
1825
+ def test_public_google_doc_write
1826
+ with_public_google_spreadsheet do
1827
+ assert_raise(GoogleWriteError) {
1828
+ oo = Google.new(key_of('write.me'))
1829
+ oo.set_value(1,1,'test')
1830
+ }
1831
+ end
1832
+ end
1833
+
1834
+ end # class