roo 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,8 @@
1
+ == 0.9.1 2008-03-23
2
+ * 1 enhancement
3
+ * additional 'sheet' parameter in Google#set_value
4
+ * 1 bugfix
5
+ * fixed a bug within Google#set_value. thanks to davecahill <dpcahill@gmail.com> for the patch.
1
6
  == 0.9.0 2008-01-24
2
7
  * 1 enhancement:
3
8
  * better support of roo spreadsheets in rails views
@@ -304,7 +304,11 @@ class GenericSpreadsheet
304
304
  #-- id
305
305
  if args[0].class == Fixnum
306
306
  rownum = args[0]
307
- tmp = {}
307
+ if @header_line
308
+ tmp = {}
309
+ else
310
+ tmp = []
311
+ end
308
312
  1.upto(self.row(rownum).size) {|j|
309
313
  x = ''
310
314
  column_with.each { |key,val|
@@ -312,9 +316,18 @@ class GenericSpreadsheet
312
316
  x = key
313
317
  end
314
318
  }
315
- tmp[x] = cell(rownum,j)
319
+ if @header_line
320
+ tmp[x] = cell(rownum,j)
321
+ else
322
+ tmp[j-1] = cell(rownum,j)
323
+ end
324
+
316
325
  }
317
- result = [ tmp ] # row(rownum)
326
+ if @header_line
327
+ result = [ tmp ]
328
+ else
329
+ result = tmp
330
+ end
318
331
  #-- :all
319
332
  elsif args[0] == :all
320
333
  if args[1].class == Hash
data/lib/roo/google.rb CHANGED
@@ -27,8 +27,9 @@ module GData
27
27
  end
28
28
 
29
29
  #-- new
30
- def save_entry_roo(entry)
31
- path = "/feeds/cells/#{@spreadsheet_id}/1/#{@headers ? 'private' : 'public'}/full"
30
+ #@@ added sheet_no to definition
31
+ def save_entry_roo(entry, sheet_no)
32
+ path = "/feeds/cells/#{@spreadsheet_id}/#{sheet_no}/#{@headers ? 'private' : 'public'}/full"
32
33
  post(path, entry)
33
34
  end
34
35
 
@@ -42,8 +43,9 @@ XML
42
43
  end
43
44
 
44
45
  #-- new
45
- def add_to_cell_roo(row,col,value)
46
- save_entry_roo(entry_roo(value,row,col))
46
+ #@@ added sheet_no to definition
47
+ def add_to_cell_roo(row,col,value, sheet_no=1)
48
+ save_entry_roo(entry_roo(value,row,col), sheet_no)
47
49
  end
48
50
 
49
51
  #-- new
@@ -261,8 +263,16 @@ class Google < GenericSpreadsheet
261
263
 
262
264
  # sets the cell to the content of 'value'
263
265
  # a formula can be set in the form of '=SUM(...)'
264
- def set_value(row,col,value)
265
- @gs.add_to_cell_roo(row,col,value)
266
+ def set_value(row,col,value,sheet=nil)
267
+ sheet = @default_sheet unless sheet
268
+ raise RangeError, "sheet not set" unless sheet
269
+ #@@ Set and pass sheet_no
270
+ begin
271
+ sheet_no = sheets.index(sheet)+1
272
+ rescue
273
+ raise RangeError, "invalid sheet '"+sheet.to_s+"'"
274
+ end
275
+ @gs.add_to_cell_roo(row,col,value,sheet_no)
266
276
  end
267
277
 
268
278
  # returns the first non-empty row in a sheet
@@ -271,7 +281,7 @@ class Google < GenericSpreadsheet
271
281
  unless @first_row[sheet]
272
282
  sheet_no = sheets.index(sheet) + 1
273
283
  @first_row[sheet], @last_row[sheet], @first_column[sheet], @last_column[sheet] = @gs.oben_unten_links_rechts(sheet_no)
274
- end
284
+ end
275
285
  return @first_row[sheet]
276
286
  end
277
287
 
@@ -314,81 +324,81 @@ class Google < GenericSpreadsheet
314
324
  # also in Openofiffe
315
325
  # -----------------------------------------------------
316
326
  #++
317
- def find(*args)
318
- result_array = false
319
- args.each {|arg,val|
320
- if arg.class == Hash
321
- arg.each { |hkey,hval|
322
- if hkey == :array and hval == true
323
- result_array = true
324
- end
325
- }
326
- end
327
- }
328
- column_with = {}
329
- 1.upto(last_column) do |col|
330
- column_with[cell(@header_line,col)] = col
331
- end
332
- result = Array.new
333
- #-- id
334
- if args[0].class == Fixnum
335
- rownum = args[0]
336
- tmp = {}
337
- 1.upto(self.row(rownum).size) {|j|
338
- x = ''
339
- column_with.each { |key,val|
340
- if val == j
341
- x = key
342
- end
343
- }
344
- tmp[x] = cell(rownum,j)
345
- }
346
- result = [ tmp ] # row(rownum)
347
- #-- :all
348
- elsif args[0] == :all
349
- if args[1].class == Hash
350
- args[1].each {|key,val|
351
- if key == :conditions
352
- column_with = {}
353
- 1.upto(last_column) do |col|
354
- column_with[cell(@header_line,col)] = col
355
- end
356
- conditions = val
357
- first_row.upto(last_row) do |i|
358
- # are all conditions met?
359
- found = 1
360
- conditions.each { |key,val|
361
- if cell(i,column_with[key]) == val
362
- found *= 1
363
- else
364
- found *= 0
365
- end
366
- }
367
- # p self.row(i) if found > 0
368
- if found > 0
369
- tmp = {}
370
- 1.upto(self.row(i).size) {|j|
371
- x = ''
372
- column_with.each { |key,val|
373
- if val == j
374
- x = key
375
- end
376
- }
377
- tmp[x] = cell(i,j)
378
- }
379
- if result_array
380
- result << self.row(i)
381
- else
382
- result << tmp
383
- end
384
- end
385
- end
386
- end # :conditions
387
- }
388
- end
389
- end
390
- result
391
- end
327
+ #def find(*args)
328
+ # result_array = false
329
+ # args.each {|arg,val|
330
+ # if arg.class == Hash
331
+ # arg.each { |hkey,hval|
332
+ # if hkey == :array and hval == true
333
+ # result_array = true
334
+ # end
335
+ # }
336
+ # end
337
+ # }
338
+ # column_with = {}
339
+ # 1.upto(last_column) do |col|
340
+ # column_with[cell(@header_line,col)] = col
341
+ # end
342
+ # result = Array.new
343
+ # #-- id
344
+ # if args[0].class == Fixnum
345
+ # rownum = args[0]
346
+ # tmp = {}
347
+ # 1.upto(self.row(rownum).size) {|j|
348
+ # x = ''
349
+ # column_with.each { |key,val|
350
+ # if val == j
351
+ # x = key
352
+ # end
353
+ # }
354
+ # tmp[x] = cell(rownum,j)
355
+ # }
356
+ # result = [ tmp ] # row(rownum)
357
+ # #-- :all
358
+ # elsif args[0] == :all
359
+ # if args[1].class == Hash
360
+ # args[1].each {|key,val|
361
+ # if key == :conditions
362
+ # column_with = {}
363
+ # 1.upto(last_column) do |col|
364
+ # column_with[cell(@header_line,col)] = col
365
+ # end
366
+ # conditions = val
367
+ # first_row.upto(last_row) do |i|
368
+ # # are all conditions met?
369
+ # found = 1
370
+ # conditions.each { |key,val|
371
+ # if cell(i,column_with[key]) == val
372
+ # found *= 1
373
+ # else
374
+ # found *= 0
375
+ # end
376
+ # }
377
+ # # p self.row(i) if found > 0
378
+ # if found > 0
379
+ # tmp = {}
380
+ # 1.upto(self.row(i).size) {|j|
381
+ # x = ''
382
+ # column_with.each { |key,val|
383
+ # if val == j
384
+ # x = key
385
+ # end
386
+ # }
387
+ # tmp[x] = cell(i,j)
388
+ # }
389
+ # if result_array
390
+ # result << self.row(i)
391
+ # else
392
+ # result << tmp
393
+ # end
394
+ # end
395
+ # end
396
+ # end # :conditions
397
+ # }
398
+ # end
399
+ # end
400
+ # result
401
+ #end
392
402
  private
393
403
 
394
404
  # read all cells in a sheet
@@ -252,21 +252,6 @@ class Openoffice < GenericSpreadsheet
252
252
  theformulas
253
253
  end
254
254
 
255
- # # write the current spreadsheet to stdout or into a file
256
- # #TODO: refactoring --> GenericSpreadsheet
257
- #
258
- # def to_csv(filename=nil,sheet=nil)
259
- # sheet = @default_sheet unless sheet
260
- # if filename
261
- # file = File.open(filename,"w") # do |file|
262
- # write_csv_content(file,sheet)
263
- # file.close
264
- # else
265
- # write_csv_content(STDOUT,sheet)
266
- # end
267
- # true
268
- # end
269
-
270
255
  private
271
256
 
272
257
  # read the version of the OO-Version
data/lib/roo/version.rb CHANGED
@@ -2,7 +2,7 @@ module Roo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 9
5
- TINY = 0
5
+ TINY = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/test_roo.rb CHANGED
@@ -20,7 +20,7 @@ def local_only
20
20
  end
21
21
 
22
22
  DISPLAY_LOG = false
23
- DB_LOG = false
23
+ DB_LOG = true
24
24
 
25
25
  if DB_LOG
26
26
  # gem 'activerecord', '< 2.0.0'
@@ -117,25 +117,22 @@ class TestRoo < Test::Unit::TestCase
117
117
  OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
118
118
  EXCEL = true # do Excel Tests?
119
119
  GOOGLE = true # do Google-Spreadsheet Tests?
120
-
120
+ GNUMERIC_ODS = false # do gnumeric with ods files Tests?
121
+
121
122
  OPENOFFICEWRITE = false # experimental: write access with OO-Documents
122
- ONLINE = false
123
+ ONLINE = true
123
124
  LONG_RUN = false
124
125
  GLOBAL_TIMEOUT = 2*12*60 # seconds
125
126
 
126
127
 
127
128
  # helper method
128
129
  def after(d)
129
- if DateTime.now > d
130
- yield
131
- end
130
+ yield if DateTime.now > d
132
131
  end
133
132
 
134
133
  # helper method
135
134
  def before(d)
136
- if DateTime.now <= d
137
- yield
138
- end
135
+ yield if DateTime.now <= d
139
136
  end
140
137
 
141
138
  def setup
@@ -209,6 +206,24 @@ class TestRoo < Test::Unit::TestCase
209
206
  end
210
207
  end
211
208
 
209
+ def test_sheets_gnumeric_ods
210
+ if GNUMERIC_ODS
211
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
212
+ assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
213
+ assert_raise(RangeError) {
214
+ oo.default_sheet = "no_sheet"
215
+ }
216
+ assert_raise(TypeError) {
217
+ oo.default_sheet = [1,2,3]
218
+ }
219
+
220
+ oo.sheets.each { |sh|
221
+ oo.default_sheet = sh
222
+ assert_equal sh, oo.default_sheet
223
+ }
224
+ end
225
+ end
226
+
212
227
  def test_sheets_excel
213
228
  if EXCEL
214
229
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -230,14 +245,12 @@ class TestRoo < Test::Unit::TestCase
230
245
  if GOOGLE
231
246
  oo = Google.new(key_of("numbers1"))
232
247
  assert_equal ["Tabelle1","Name of Sheet 2","Sheet3","Sheet4","Sheet5"], oo.sheets
233
- after Date.new(2007,12,15) do
234
- assert_raise(RangeError) {
235
- oo.default_sheet = "no_sheet"
236
- }
237
- assert_raise(TypeError) {
238
- oo.default_sheet = [1,2,3]
239
- }
240
- end
248
+ assert_raise(RangeError) {
249
+ oo.default_sheet = "no_sheet"
250
+ }
251
+ assert_raise(TypeError) {
252
+ oo.default_sheet = [1,2,3]
253
+ }
241
254
  oo.sheets.each { |sh|
242
255
  oo.default_sheet = sh
243
256
  assert_equal sh, oo.default_sheet
@@ -284,6 +297,45 @@ class TestRoo < Test::Unit::TestCase
284
297
  end
285
298
  end
286
299
 
300
+ def test_cell_gnumeric_ods
301
+ if GNUMERIC_ODS
302
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
303
+ oo.default_sheet = oo.sheets.first
304
+ assert_equal 1, oo.cell(1,1)
305
+ assert_equal 2, oo.cell(1,2)
306
+ assert_equal 3, oo.cell(1,3)
307
+ assert_equal 4, oo.cell(1,4)
308
+ assert_equal 5, oo.cell(2,1)
309
+ assert_equal 6, oo.cell(2,2)
310
+ assert_equal 7, oo.cell(2,3)
311
+ assert_equal 8, oo.cell(2,4)
312
+ assert_equal 9, oo.cell(2,5)
313
+ assert_equal "test", oo.cell(2,6)
314
+ # assert_equal "string", oo.celltype(2,6)
315
+ assert_equal :string, oo.celltype(2,6)
316
+ assert_equal 11, oo.cell(2,7)
317
+ # assert_equal "float", oo.celltype(2,7)
318
+ assert_equal :float, oo.celltype(2,7)
319
+
320
+ assert_equal 10, oo.cell(4,1)
321
+ assert_equal 11, oo.cell(4,2)
322
+ assert_equal 12, oo.cell(4,3)
323
+ assert_equal 13, oo.cell(4,4)
324
+ assert_equal 14, oo.cell(4,5)
325
+
326
+ assert_equal 10, oo.cell(4,'A')
327
+ assert_equal 11, oo.cell(4,'B')
328
+ assert_equal 12, oo.cell(4,'C')
329
+ assert_equal 13, oo.cell(4,'D')
330
+ assert_equal 14, oo.cell(4,'E')
331
+
332
+ # assert_equal "date", oo.celltype(5,1)
333
+ assert_equal :date, oo.celltype(5,1)
334
+ assert_equal Date.new(1961,11,21), oo.cell(5,1)
335
+ assert_equal "1961-11-21", oo.cell(5,1).to_s
336
+ end
337
+ end
338
+
287
339
  def test_cell_excel
288
340
  if EXCEL
289
341
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -369,6 +421,11 @@ class TestRoo < Test::Unit::TestCase
369
421
  oo.default_sheet = oo.sheets.first
370
422
  assert_equal :string, oo.celltype(2,6)
371
423
  end
424
+ if GNUMERIC_ODS
425
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
426
+ oo.default_sheet = oo.sheets.first
427
+ assert_equal :string, oo.celltype(2,6)
428
+ end
372
429
  if EXCEL
373
430
  oo = Excel.new(File.join("test","numbers1.xls"))
374
431
  oo.default_sheet = oo.sheets.first
@@ -406,6 +463,31 @@ class TestRoo < Test::Unit::TestCase
406
463
  assert_equal "thisisd9", oo.cell('d',9)
407
464
  assert_equal "thisisa11", oo.cell('a',11)
408
465
  end
466
+
467
+ if GNUMERIC_ODS
468
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
469
+ oo.default_sheet = oo.sheets.first
470
+ assert_equal "tata", oo.cell(6,1)
471
+ assert_equal "tata", oo.cell(6,'A')
472
+ assert_equal "tata", oo.cell('A',6)
473
+ assert_equal "tata", oo.cell(6,'a')
474
+ assert_equal "tata", oo.cell('a',6)
475
+
476
+ assert_raise(ArgumentError) {
477
+ assert_equal "tata", oo.cell('a','f')
478
+ }
479
+ assert_raise(ArgumentError) {
480
+ assert_equal "tata", oo.cell('f','a')
481
+ }
482
+ assert_equal "thisisc8", oo.cell(8,3)
483
+ assert_equal "thisisc8", oo.cell(8,'C')
484
+ assert_equal "thisisc8", oo.cell('C',8)
485
+ assert_equal "thisisc8", oo.cell(8,'c')
486
+ assert_equal "thisisc8", oo.cell('c',8)
487
+
488
+ assert_equal "thisisd9", oo.cell('d',9)
489
+ assert_equal "thisisa11", oo.cell('a',11)
490
+ end
409
491
 
410
492
  if EXCEL
411
493
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -463,9 +545,14 @@ class TestRoo < Test::Unit::TestCase
463
545
  # Version of the (XML) office document
464
546
  # please note that "1.0" is returned even if it was created with OpenOffice V. 2.0
465
547
  def test_officeversion
466
- #-- OpenOffice
467
- oo = Openoffice.new(File.join("test","numbers1.ods"))
468
- assert_equal "1.0", oo.officeversion
548
+ if OPENOFFICE
549
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
550
+ assert_equal "1.0", oo.officeversion
551
+ end
552
+ if GNUMERIC_ODS
553
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
554
+ assert_equal "1.0", oo.officeversion
555
+ end
469
556
  if EXCEL
470
557
  # excel does not have a officeversion
471
558
  end
@@ -492,6 +579,22 @@ class TestRoo < Test::Unit::TestCase
492
579
  assert_equal "fuenfundvierzig", oo.cell('e',16)
493
580
  assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig"], oo.row(16)
494
581
  end
582
+ if GNUMERIC_ODS
583
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
584
+ oo.default_sheet = oo.sheets.first
585
+ assert_equal 41, oo.cell('a',12)
586
+ assert_equal 42, oo.cell('b',12)
587
+ assert_equal 43, oo.cell('c',12)
588
+ assert_equal 44, oo.cell('d',12)
589
+ assert_equal 45, oo.cell('e',12)
590
+ assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
591
+ assert_equal "einundvierzig", oo.cell('a',16)
592
+ assert_equal "zweiundvierzig", oo.cell('b',16)
593
+ assert_equal "dreiundvierzig", oo.cell('c',16)
594
+ assert_equal "vierundvierzig", oo.cell('d',16)
595
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
596
+ assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig"], oo.row(16)
597
+ end
495
598
  if EXCEL
496
599
  #-- Excel
497
600
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -541,6 +644,11 @@ class TestRoo < Test::Unit::TestCase
541
644
  oo.default_sheet = oo.sheets.first
542
645
  assert_equal 18, oo.last_row
543
646
  end
647
+ if GNUMERIC_ODS
648
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
649
+ oo.default_sheet = oo.sheets.first
650
+ assert_equal 18, oo.last_row
651
+ end
544
652
  if EXCEL
545
653
  oo = Excel.new(File.join("test","numbers1.xls"))
546
654
  oo.default_sheet = oo.sheets.first
@@ -559,8 +667,12 @@ class TestRoo < Test::Unit::TestCase
559
667
  oo.default_sheet = oo.sheets.first
560
668
  assert_equal 7, oo.last_column
561
669
  end
670
+ if GNUMERIC_ODS
671
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
672
+ oo.default_sheet = oo.sheets.first
673
+ assert_equal 7, oo.last_column
674
+ end
562
675
  if EXCEL
563
- #-- Excel
564
676
  oo = Excel.new(File.join("test","numbers1.xls"))
565
677
  oo.default_sheet = oo.sheets.first
566
678
  assert_equal 7, oo.last_column
@@ -578,8 +690,12 @@ class TestRoo < Test::Unit::TestCase
578
690
  oo.default_sheet = oo.sheets.first
579
691
  assert_equal 'G', oo.last_column_as_letter
580
692
  end
693
+ if GNUMERIC_ODS
694
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
695
+ oo.default_sheet = oo.sheets.first
696
+ assert_equal 'G', oo.last_column_as_letter
697
+ end
581
698
  if EXCEL
582
- #-- Excel
583
699
  oo = Excel.new(File.join("test","numbers1.xls"))
584
700
  oo.default_sheet = 1 # oo.sheets.first
585
701
  assert_equal 'G', oo.last_column_as_letter
@@ -597,8 +713,12 @@ class TestRoo < Test::Unit::TestCase
597
713
  oo.default_sheet = oo.sheets.first
598
714
  assert_equal 1, oo.first_row
599
715
  end
716
+ if GNUMERIC_ODS
717
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
718
+ oo.default_sheet = oo.sheets.first
719
+ assert_equal 1, oo.first_row
720
+ end
600
721
  if EXCEL
601
- #-- Excel
602
722
  oo = Excel.new(File.join("test","numbers1.xls"))
603
723
  oo.default_sheet = 1 # oo.sheets.first
604
724
  assert_equal 1, oo.first_row
@@ -616,6 +736,11 @@ class TestRoo < Test::Unit::TestCase
616
736
  oo.default_sheet = oo.sheets.first
617
737
  assert_equal 1, oo.first_column
618
738
  end
739
+ if GNUMERIC_ODS
740
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
741
+ oo.default_sheet = oo.sheets.first
742
+ assert_equal 1, oo.first_column
743
+ end
619
744
  if EXCEL
620
745
  #-- Excel
621
746
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -641,9 +766,16 @@ class TestRoo < Test::Unit::TestCase
641
766
  end
642
767
  end
643
768
 
769
+ def test_first_column_as_letter_gnumeric_ods
770
+ if GNUMERIC_ODS
771
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
772
+ oo.default_sheet = oo.sheets.first
773
+ assert_equal 'A', oo.first_column_as_letter
774
+ end
775
+ end
776
+
644
777
  def test_first_column_as_letter_excel
645
778
  if EXCEL
646
- #-- Excel
647
779
  oo = Excel.new(File.join("test","numbers1.xls"))
648
780
  oo.default_sheet = 1 # oo.sheets.first
649
781
  assert_equal 'A', oo.first_column_as_letter
@@ -664,6 +796,11 @@ class TestRoo < Test::Unit::TestCase
664
796
  oo.default_sheet = "Name of Sheet 2"
665
797
  assert_equal 'I am sheet 2', oo.cell('C',5)
666
798
  end
799
+ if GNUMERIC_ODS
800
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
801
+ oo.default_sheet = "Name of Sheet 2"
802
+ assert_equal 'I am sheet 2', oo.cell('C',5)
803
+ end
667
804
  if EXCEL
668
805
  oo = Excel.new(File.join("test","numbers1.xls"))
669
806
  oo.default_sheet = "Name of Sheet 2"
@@ -677,14 +814,24 @@ class TestRoo < Test::Unit::TestCase
677
814
  end
678
815
 
679
816
  def test_boundaries
680
- #-- OpenOffice
681
- oo = Openoffice.new(File.join("test","numbers1.ods"))
682
- oo.default_sheet = "Name of Sheet 2"
683
- assert_equal 2, oo.first_column
684
- assert_equal 'B', oo.first_column_as_letter
685
- assert_equal 5, oo.first_row
686
- assert_equal 'E', oo.last_column_as_letter
687
- assert_equal 14, oo.last_row
817
+ if OPENOFFICE
818
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
819
+ oo.default_sheet = "Name of Sheet 2"
820
+ assert_equal 2, oo.first_column
821
+ assert_equal 'B', oo.first_column_as_letter
822
+ assert_equal 5, oo.first_row
823
+ assert_equal 'E', oo.last_column_as_letter
824
+ assert_equal 14, oo.last_row
825
+ end
826
+ if GNUMERIC_ODS
827
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
828
+ oo.default_sheet = "Name of Sheet 2"
829
+ assert_equal 2, oo.first_column
830
+ assert_equal 'B', oo.first_column_as_letter
831
+ assert_equal 5, oo.first_row
832
+ assert_equal 'E', oo.last_column_as_letter
833
+ assert_equal 14, oo.last_row
834
+ end
688
835
  if EXCEL
689
836
  #-- Excel
690
837
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -698,7 +845,6 @@ class TestRoo < Test::Unit::TestCase
698
845
  end
699
846
 
700
847
  def test_multiple_letters
701
- #-- OpenOffice
702
848
  if OPENOFFICE
703
849
  oo = Openoffice.new(File.join("test","numbers1.ods"))
704
850
  oo.default_sheet = "Sheet3"
@@ -708,8 +854,16 @@ class TestRoo < Test::Unit::TestCase
708
854
  assert_equal 'BA', oo.last_column_as_letter
709
855
  assert_equal "i am BA", oo.cell(1,'BA')
710
856
  end
857
+ if GNUMERIC_ODS
858
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
859
+ oo.default_sheet = "Sheet3"
860
+ assert_equal "i am AA", oo.cell('AA',1)
861
+ assert_equal "i am AB", oo.cell('AB',1)
862
+ assert_equal "i am BA", oo.cell('BA',1)
863
+ assert_equal 'BA', oo.last_column_as_letter
864
+ assert_equal "i am BA", oo.cell(1,'BA')
865
+ end
711
866
  if EXCEL
712
- #-- Excel
713
867
  oo = Excel.new(File.join("test","numbers1.xls"))
714
868
  oo.default_sheet = 3 # "Sheet3"
715
869
  assert_equal "i am AA", oo.cell('AA',1)
@@ -720,10 +874,6 @@ class TestRoo < Test::Unit::TestCase
720
874
  end
721
875
  end
722
876
 
723
- def test_setting_cell
724
- assert true
725
- end
726
-
727
877
  def test_argument_error
728
878
  if EXCEL
729
879
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -749,6 +899,13 @@ class TestRoo < Test::Unit::TestCase
749
899
  assert ! oo.empty?('a',15)
750
900
  assert oo.empty?('a',20)
751
901
  end
902
+ if GNUMERIC_ODS
903
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
904
+ oo.default_sheet = oo.sheets.first
905
+ assert oo.empty?('a',14)
906
+ assert ! oo.empty?('a',15)
907
+ assert oo.empty?('a',20)
908
+ end
752
909
  if EXCEL
753
910
  #-- Excel
754
911
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -805,6 +962,14 @@ class TestRoo < Test::Unit::TestCase
805
962
  oo.reload
806
963
  assert_equal 1, oo.cell(1,1)
807
964
  end
965
+ if GNUMERIC_ODS
966
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
967
+ oo.default_sheet = oo.sheets.first
968
+ assert_equal 1, oo.cell(1,1)
969
+
970
+ oo.reload
971
+ assert_equal 1, oo.cell(1,1)
972
+ end
808
973
  if EXCEL
809
974
  oo = Excel.new(File.join("test","numbers1.xls"))
810
975
  oo.default_sheet = 1 # oo.sheets.first
@@ -825,6 +990,15 @@ class TestRoo < Test::Unit::TestCase
825
990
  assert_equal 10, oo.cell('d',1)
826
991
  assert_equal 10, oo.cell('e',1)
827
992
  end
993
+ if GNUMERIC_ODS
994
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
995
+ oo.default_sheet = "Sheet4"
996
+ assert_equal Date.new(2007,06,16), oo.cell('a',1)
997
+ assert_equal 10, oo.cell('b',1)
998
+ assert_equal 10, oo.cell('c',1)
999
+ assert_equal 10, oo.cell('d',1)
1000
+ assert_equal 10, oo.cell('e',1)
1001
+ end
828
1002
  #if EXCEL
829
1003
  # # dieser Test ist fuer Excel sheets eigentlich nicht noetig,
830
1004
  # # da der Bug nur bei OO-Dokumenten auftrat
@@ -860,6 +1034,24 @@ class TestRoo < Test::Unit::TestCase
860
1034
  assert_equal 2, oo.cell('a',2)
861
1035
  assert_equal 3, oo.cell('a',3)
862
1036
  end
1037
+ if OPENOFFICE
1038
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
1039
+ oo.default_sheet = "Sheet5"
1040
+ assert_equal 1, oo.cell('A',1)
1041
+ assert_equal 5, oo.cell('b',1)
1042
+ assert_equal 5, oo.cell('c',1)
1043
+ assert_equal 2, oo.cell('a',2)
1044
+ assert_equal 3, oo.cell('a',3)
1045
+ end
1046
+ if GNUMERIC_ODS
1047
+ oo = Openoffice.new(File.join("test","gnumeric_numbers1.ods"))
1048
+ oo.default_sheet = "Sheet5"
1049
+ assert_equal 1, oo.cell('A',1)
1050
+ assert_equal 5, oo.cell('b',1)
1051
+ assert_equal 5, oo.cell('c',1)
1052
+ assert_equal 2, oo.cell('a',2)
1053
+ assert_equal 3, oo.cell('a',3)
1054
+ end
863
1055
  if EXCEL
864
1056
  oo = Excel.new(File.join("test","numbers1.xls"))
865
1057
  oo.default_sheet = 5
@@ -879,7 +1071,7 @@ class TestRoo < Test::Unit::TestCase
879
1071
  # assert_equal 3, oo.cell('a',3)
880
1072
  #end
881
1073
  end
882
-
1074
+ #2008-01-30
883
1075
  def test_italo_table
884
1076
  local_only do
885
1077
  oo = Openoffice.new(File.join("test","simple_spreadsheet_from_italo.ods"))
@@ -1917,19 +2109,17 @@ class TestRoo < Test::Unit::TestCase
1917
2109
  if OPENOFFICE
1918
2110
  oo = Openoffice.new(File.join("test","numbers1.ods"))
1919
2111
  oo.default_sheet = oo.sheets.first
2112
+ oo.header_line = nil
1920
2113
  rec = oo.find 16
1921
2114
  assert rec
1922
- oo.header_line = nil
1923
2115
  assert_nil oo.header_line
1924
2116
  # keine Headerlines in diesem Beispiel definiert
1925
- after Date.new(2008,1,31) do
1926
- assert_equal "einundvierzig", rec[0]
1927
- #assert_equal false, rec
2117
+ assert_equal "einundvierzig", rec[0]
2118
+ #assert_equal false, rec
1928
2119
 
1929
- rec = oo.find 15
1930
- assert rec
1931
- assert_equal 41,rec
1932
- end
2120
+ rec = oo.find 15
2121
+ assert rec
2122
+ assert_equal 41,rec[0]
1933
2123
  end
1934
2124
  end
1935
2125
 
@@ -1937,16 +2127,15 @@ class TestRoo < Test::Unit::TestCase
1937
2127
  if EXCEL
1938
2128
  oo = Excel.new(File.join("test","numbers1.xls"))
1939
2129
  oo.default_sheet = oo.sheets.first
2130
+ oo.header_line = nil
1940
2131
  rec = oo.find 16
1941
2132
  assert rec
1942
2133
  # keine Headerlines in diesem Beispiel definiert
1943
- after Date.new(2008,1,31) do
1944
- assert_equal "einundvierzig", rec[0]
2134
+ assert_equal "einundvierzig", rec[0]
1945
2135
 
1946
- rec = oo.find 15
1947
- assert rec
1948
- assert_equal 41,rec[0]
1949
- end
2136
+ rec = oo.find 15
2137
+ assert rec
2138
+ assert_equal 41,rec[0]
1950
2139
  end
1951
2140
  end
1952
2141
 
@@ -1954,16 +2143,15 @@ class TestRoo < Test::Unit::TestCase
1954
2143
  if GOOGLE
1955
2144
  oo = Google.new(key_of("numbers1"))
1956
2145
  oo.default_sheet = oo.sheets.first
2146
+ oo.header_line = nil
1957
2147
  rec = oo.find 16
1958
2148
  assert rec
1959
2149
  # keine Headerlines in diesem Beispiel definiert
1960
- after Date.new(2008,1,31) do
1961
- assert_equal "einundvierzig", rec[0]
2150
+ assert_equal "einundvierzig", rec[0]
1962
2151
 
1963
- rec = oo.find 15
1964
- assert rec
1965
- assert_equal 41,rec[0]
1966
- end
2152
+ rec = oo.find 15
2153
+ assert rec
2154
+ assert_equal 41,rec[0]
1967
2155
  end
1968
2156
  end
1969
2157
 
@@ -2347,19 +2535,17 @@ class TestRoo < Test::Unit::TestCase
2347
2535
 
2348
2536
  def test_simple_spreadsheet_find_by_condition_google
2349
2537
  if GOOGLE
2350
- after Date.new(2007,12,15) do
2351
- oo = Google.new(key_of("simple_spreadsheet"))
2352
- oo.default_sheet = oo.sheets.first
2353
- oo.header_line = 3
2354
- erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
2355
- assert_equal Date.new(2007,05,07), erg[1]['Date']
2356
- assert_equal 10.75 , erg[1]['Start time']
2357
- assert_equal 12.50 , erg[1]['End time']
2358
- assert_equal 0 , erg[1]['Pause']
2359
- assert_kind_of Float, erg[1]['Sum']
2360
- assert_equal 1.75 , erg[1]['Sum']
2361
- assert_equal "Task 1" , erg[1]['Comment']
2362
- end
2538
+ oo = Google.new(key_of("simple_spreadsheet"))
2539
+ oo.default_sheet = oo.sheets.first
2540
+ oo.header_line = 3
2541
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
2542
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
2543
+ assert_equal 10.75 , erg[1]['Start time']
2544
+ assert_equal 12.50 , erg[1]['End time']
2545
+ assert_equal 0 , erg[1]['Pause']
2546
+ assert_kind_of Float, erg[1]['Sum']
2547
+ assert_equal 1.75 , erg[1]['Sum']
2548
+ assert_equal "Task 1" , erg[1]['Comment']
2363
2549
  end
2364
2550
  end
2365
2551
 
@@ -2520,11 +2706,11 @@ class TestRoo < Test::Unit::TestCase
2520
2706
  }
2521
2707
  end
2522
2708
  if GOOGLE
2523
- after Date.new(2008,1,31) do
2524
- assert_raise(IOError) {
2525
- # oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
2526
- oo = Google.new('testnichtvorhanden')
2527
- }
2709
+ after Date.new(2008,4,1) do
2710
+ assert_raise(IOError) {
2711
+ # oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
2712
+ oo = Google.new('testnichtvorhanden')
2713
+ }
2528
2714
  end
2529
2715
  end
2530
2716
  end
@@ -2551,6 +2737,48 @@ class TestRoo < Test::Unit::TestCase
2551
2737
  assert_equal "hello from the tests", oo.cell(1,1)
2552
2738
  end
2553
2739
  end
2740
+
2741
+ def test_bug_set_value_with_more_than_one_sheet_google
2742
+ # write.me: http://spreadsheets.google.com/ccc?key=ptu6bbahNZpY0N0RrxQbWdw&hl=en_GB
2743
+ if GOOGLE
2744
+ content1 = 'AAA'
2745
+ content2 = 'BBB'
2746
+ oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
2747
+ oo.default_sheet = oo.sheets.first
2748
+ oo.set_value(1,1,content1)
2749
+ oo.default_sheet = oo.sheets[1]
2750
+ oo.set_value(1,1,content2) # in the second sheet
2751
+ oo.default_sheet = oo.sheets.first
2752
+ assert_equal content1, oo.cell(1,1)
2753
+ oo.default_sheet = oo.sheets[1]
2754
+ assert_equal content2, oo.cell(1,1)
2755
+ end
2756
+ end
2757
+
2758
+ def test_set_value_with_sheet_argument_google
2759
+ if GOOGLE
2760
+ random_row = rand(10)+1
2761
+ random_column = rand(10)+1
2762
+ oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
2763
+ oo.default_sheet = oo.sheets.first
2764
+ content1 = 'ABC'
2765
+ content2 = 'DEF'
2766
+ oo.set_value(random_row,random_column,content1,oo.sheets.first)
2767
+ oo.set_value(random_row,random_column,content2,oo.sheets[1])
2768
+ assert_equal content1, oo.cell(random_row,random_column,oo.sheets.first)
2769
+ assert_equal content2, oo.cell(random_row,random_column,oo.sheets[1])
2770
+ end
2771
+ end
2772
+
2773
+ def test_set_value_for_non_existing_sheet_google
2774
+ if GOOGLE
2775
+ oo = Google.new('ptu6bbahNZpY0N0RrxQbWdw')
2776
+ assert_raise(RangeError) {
2777
+ #oo.default_sheet = "no_sheet"
2778
+ oo.set_value(1,1,"dummy","no_sheet")
2779
+ }
2780
+ end # GOOGLE
2781
+ end
2554
2782
 
2555
2783
  def test_bug_bbu_openoffice
2556
2784
  oo = Openoffice.new(File.join('test','bbu.ods'))
data/website/index.html CHANGED
@@ -33,7 +33,7 @@
33
33
  <h1>roo</h1>
34
34
  <div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/roo"; return false'>
35
35
  Get Version
36
- <a href="http://rubyforge.org/projects/roo" class="numbers">0.9.0</a>
36
+ <a href="http://rubyforge.org/projects/roo" class="numbers">0.9.1</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
@@ -456,10 +456,7 @@ Only the Openoffice- and Excel-parts of this gem are currently working &#8211; t
456
456
  <p>Read the <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/">8 steps for fixing other people&#8217;s code</a> and for section <a href="http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups">8b: Submit patch to Google Groups</a>, use the Google Group above.</p>
457
457
 
458
458
 
459
- <p>&lt;!&#8212;
460
- The trunk repository is <code>svn://rubyforge.org/var/svn/gorank/trunk</code> for anonymous access.
461
- &#8212;&gt;</p>
462
-
459
+ <strike>The trunk repository is <code>svn://rubyforge.org/var/svn/gorank/trunk</code> for anonymous access.</strike>
463
460
 
464
461
  <h2>License</h2>
465
462
 
@@ -482,7 +479,7 @@ The trunk repository is <code>svn://rubyforge.org/var/svn/gorank/trunk</code> fo
482
479
  <li>Dirk Huth f&uuml;rs Testen unter Windows</li>
483
480
  </ul>
484
481
  <p class="coda">
485
- <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, 24th January 2008<br>
482
+ <a href="mailto:thopre@gmail.com">Thomas Preymesser</a>, 27th January 2008<br>
486
483
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
487
484
  </p>
488
485
  </div>
data/website/index.txt CHANGED
@@ -313,9 +313,7 @@ h2. How to submit patches
313
313
 
314
314
  Read the "8 steps for fixing other people's code":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/ and for section "8b: Submit patch to Google Groups":http://drnicwilliams.com/2007/06/01/8-steps-for-fixing-other-peoples-code/#8b-google-groups, use the Google Group above.
315
315
 
316
- <!--
317
- The trunk repository is <code>svn://rubyforge.org/var/svn/gorank/trunk</code> for anonymous access.
318
- -->
316
+ <strike>The trunk repository is <code>svn://rubyforge.org/var/svn/gorank/trunk</code> for anonymous access.</strike>
319
317
 
320
318
  h2. License
321
319
 
@@ -37,7 +37,7 @@
37
37
  </div>
38
38
  <%= body %>
39
39
  <p class="coda">
40
- <a href="mailto:drnicwilliams@gmail.com">Dr Nic</a>, <%= modified.pretty %><br>
40
+ <a href="mailto:thopre@gmail.com">Thomas Preymesser</a>, <%= modified.pretty %><br>
41
41
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
42
42
  </p>
43
43
  </div>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: roo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.0
4
+ version: 0.9.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thomas Preymesser
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-24 00:00:00 +01:00
12
+ date: 2008-03-23 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency