roo 0.6.1 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/roo/version.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  module Roo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 6
5
- TINY = 1
4
+ MINOR = 7
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/test/numbers1.xls CHANGED
Binary file
data/test/test_roo.rb CHANGED
@@ -1,13 +1,82 @@
1
- # damit keine falschen Vermutungen aufkommen: Ich habe religoes rein gar nichts
2
- # mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
1
+ #damit keine falschen Vermutungen aufkommen: Ich habe religoes rein gar nichts
2
+ # mit diesem Bibelbund zu tun, aber die hatten eine ziemlich grosse
3
3
  # Spreadsheet-Datei oeffentlich im Netz, die sich ganz gut zum Testen eignete.
4
4
  #
5
+ #--
6
+ # these test cases were developed to run under Linux OS, some commands
7
+ # (like 'diff') must be changed (or commented out ;-)) if you want to run
8
+ # the tests under another OS
9
+ #
5
10
  require File.dirname(__FILE__) + '/test_helper.rb'
6
11
  #require 'soap/rpc/driver'
7
12
  require 'fileutils'
8
13
  require 'timeout'
14
+
15
+ # helper method
16
+ def local_only
17
+ if ENV["roo_local"] == "thomas-p"
18
+ yield
19
+ end
20
+ end
21
+
22
+ DISPLAY_LOG = false
23
+ DB_LOG = false
24
+
25
+ if DB_LOG
26
+ require 'active_record'
27
+ end
28
+
9
29
  include FileUtils
10
30
 
31
+ if DB_LOG
32
+ def activerecord_connect
33
+ ActiveRecord::Base.establish_connection(:adapter => "mysql",
34
+ :database => "test_runs",
35
+ :host => "localhost",
36
+ :username => "root",
37
+ :socket => "/var/run/mysqld/mysqld.sock")
38
+ end
39
+
40
+ class Testrun < ActiveRecord::Base
41
+ end
42
+ end
43
+
44
+ class Test::Unit::TestCase
45
+ if DB_LOG
46
+ if ! (defined?(@connected) and @connected)
47
+ activerecord_connect
48
+ else
49
+ @connected = true
50
+ end
51
+ end
52
+ alias unlogged_run run
53
+ def run(result, &block)
54
+ t1 = Time.now
55
+ #RAILS_DEFAULT_LOGGER.debug "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
56
+ if DISPLAY_LOG
57
+ print "RUNNING #{self.class} #{@method_name} \t#{Time.now.to_s}"
58
+ end
59
+ unlogged_run result, &block
60
+ t2 = Time.now
61
+ if DISPLAY_LOG
62
+ puts "\t#{t2-t1} seconds"
63
+ end
64
+ # record = {'class' => self.class.to_s,
65
+ # 'test' => @method_name,
66
+ # 'start' => t1,
67
+ # 'duration' => t2-t1}
68
+ # open('test_runs.yml','a') { |f| YAML.dump(record, f) }
69
+ # #--
70
+ if DB_LOG
71
+ domain = Testrun.create(:class => self.class.to_s,
72
+ :test => @method_name,
73
+ :start => t1,
74
+ :duration => t2-t1
75
+ )
76
+ end
77
+ end
78
+ end
79
+
11
80
  class TestRoo < Test::Unit::TestCase
12
81
 
13
82
  OPENOFFICE = true # do Openoffice-Spreadsheet Tests?
@@ -16,13 +85,9 @@ class TestRoo < Test::Unit::TestCase
16
85
 
17
86
  OPENOFFICEWRITE = false # experimental: write access with OO-Documents
18
87
  ONLINE = false
88
+ LONG_RUN = false
89
+ GLOBAL_TIMEOUT = 10*60 # seconds
19
90
 
20
- # helper method
21
- def local_only
22
- if ENV["roo_local"] == "thomas-p"
23
- yield
24
- end
25
- end
26
91
 
27
92
  # helper method
28
93
  def after(d)
@@ -46,6 +111,9 @@ class TestRoo < Test::Unit::TestCase
46
111
  ENV['GOOGLE_KEY'],"Roo Testspreadheet")
47
112
  end
48
113
  end
114
+ if DISPLAY_LOG
115
+ puts "GLOBAL_TIMEOUT = #{GLOBAL_TIMEOUT}"
116
+ end
49
117
  end
50
118
 
51
119
  def test_letters
@@ -324,21 +392,23 @@ class TestRoo < Test::Unit::TestCase
324
392
  end
325
393
 
326
394
  def test_rows
327
- #-- OpenOffice
328
- oo = Openoffice.new(File.join("test","numbers1.ods"))
329
- oo.default_sheet = oo.sheets.first
330
- assert_equal 41, oo.cell('a',12)
331
- assert_equal 42, oo.cell('b',12)
332
- assert_equal 43, oo.cell('c',12)
333
- assert_equal 44, oo.cell('d',12)
334
- assert_equal 45, oo.cell('e',12)
335
- assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
336
- assert_equal "einundvierzig", oo.cell('a',16)
337
- assert_equal "zweiundvierzig", oo.cell('b',16)
338
- assert_equal "dreiundvierzig", oo.cell('c',16)
339
- assert_equal "vierundvierzig", oo.cell('d',16)
340
- assert_equal "fuenfundvierzig", oo.cell('e',16)
341
- assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig"], oo.row(16)
395
+ if OPENOFFICE
396
+ #-- OpenOffice
397
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
398
+ oo.default_sheet = oo.sheets.first
399
+ assert_equal 41, oo.cell('a',12)
400
+ assert_equal 42, oo.cell('b',12)
401
+ assert_equal 43, oo.cell('c',12)
402
+ assert_equal 44, oo.cell('d',12)
403
+ assert_equal 45, oo.cell('e',12)
404
+ assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
405
+ assert_equal "einundvierzig", oo.cell('a',16)
406
+ assert_equal "zweiundvierzig", oo.cell('b',16)
407
+ assert_equal "dreiundvierzig", oo.cell('c',16)
408
+ assert_equal "vierundvierzig", oo.cell('d',16)
409
+ assert_equal "fuenfundvierzig", oo.cell('e',16)
410
+ assert_equal ["einundvierzig", "zweiundvierzig", "dreiundvierzig", "vierundvierzig", "fuenfundvierzig"], oo.row(16)
411
+ end
342
412
  if EXCEL
343
413
  #-- Excel
344
414
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -477,11 +547,15 @@ class TestRoo < Test::Unit::TestCase
477
547
  end
478
548
  end
479
549
 
550
+ def test_first_column_as_letter_openoffice
551
+ if OPENOFFICE #-- OpenOffice
552
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
553
+ oo.default_sheet = oo.sheets.first
554
+ assert_equal 'A', oo.first_column_as_letter
555
+ end
556
+ end
557
+
480
558
  def test_first_column_as_letter
481
- #-- OpenOffice
482
- oo = Openoffice.new(File.join("test","numbers1.ods"))
483
- oo.default_sheet = oo.sheets.first
484
- assert_equal 'A', oo.first_column_as_letter
485
559
  if EXCEL
486
560
  #-- Excel
487
561
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -532,13 +606,15 @@ class TestRoo < Test::Unit::TestCase
532
606
 
533
607
  def test_multiple_letters
534
608
  #-- OpenOffice
535
- oo = Openoffice.new(File.join("test","numbers1.ods"))
536
- oo.default_sheet = "Sheet3"
537
- assert_equal "i am AA", oo.cell('AA',1)
538
- assert_equal "i am AB", oo.cell('AB',1)
539
- assert_equal "i am BA", oo.cell('BA',1)
540
- assert_equal 'BA', oo.last_column_as_letter
541
- assert_equal "i am BA", oo.cell(1,'BA')
609
+ if OPENOFFICE
610
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
611
+ oo.default_sheet = "Sheet3"
612
+ assert_equal "i am AA", oo.cell('AA',1)
613
+ assert_equal "i am AB", oo.cell('AB',1)
614
+ assert_equal "i am BA", oo.cell('BA',1)
615
+ assert_equal 'BA', oo.last_column_as_letter
616
+ assert_equal "i am BA", oo.cell(1,'BA')
617
+ end
542
618
  if EXCEL
543
619
  #-- Excel
544
620
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -560,22 +636,28 @@ class TestRoo < Test::Unit::TestCase
560
636
  oo = Excel.new(File.join("test","numbers1.xls"))
561
637
  before Date.new(2007,7,20) do
562
638
  assert_raise(ArgumentError) {
563
- oo.default_sheet = "first sheet"
639
+ #oo.default_sheet = "first sheet"
640
+ oo.default_sheet = "Tabelle1"
641
+ }
642
+ end
643
+ after Date.new(2007,7,20) do
644
+ assert_nothing_raised(ArgumentError) {
645
+ # oo.default_sheet = 1
646
+ #oo.default_sheet = "first sheet"
647
+ oo.default_sheet = "Tabelle1"
564
648
  }
565
649
  end
566
- assert_nothing_raised(ArgumentError) {
567
- oo.default_sheet = 1
568
- }
569
650
  end
570
651
  end
571
652
 
572
653
  def test_empty_eh
573
- #-- OpenOffice
574
- oo = Openoffice.new(File.join("test","numbers1.ods"))
575
- oo.default_sheet = oo.sheets.first
576
- assert oo.empty?('a',14)
577
- assert ! oo.empty?('a',15)
578
- assert oo.empty?('a',20)
654
+ if OPENOFFICE #-- OpenOffice
655
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
656
+ oo.default_sheet = oo.sheets.first
657
+ assert oo.empty?('a',14)
658
+ assert ! oo.empty?('a',15)
659
+ assert oo.empty?('a',20)
660
+ end
579
661
  if EXCEL
580
662
  #-- Excel
581
663
  oo = Excel.new(File.join("test","numbers1.xls"))
@@ -725,19 +807,19 @@ class TestRoo < Test::Unit::TestCase
725
807
  # assert_equal 2, oo.cell('B',2)
726
808
  # assert_equal 1, oo.cell('C',2)
727
809
  # are stored as strings, not numbers
728
-
810
+
729
811
  assert_equal 1, oo.cell('A',2).to_i
730
812
  assert_equal 2, oo.cell('B',2).to_i
731
813
  assert_equal 1, oo.cell('C',2).to_i
732
-
814
+
733
815
  assert_equal 1, oo.cell('A',3)
734
816
  assert_equal 3, oo.cell('B',3)
735
817
  assert_equal 1, oo.cell('C',3)
736
-
818
+
737
819
  assert_equal 'A', oo.cell('A',4)
738
820
  assert_equal 'A', oo.cell('B',4)
739
821
  assert_equal 'A', oo.cell('C',4)
740
-
822
+
741
823
  # assert_equal '0.01', oo.cell('A',5)
742
824
  # assert_equal '0.01', oo.cell('B',5)
743
825
  # assert_equal '0.01', oo.cell('C',5)
@@ -747,34 +829,34 @@ class TestRoo < Test::Unit::TestCase
747
829
  assert_equal 0.01, oo.cell('C',5)
748
830
 
749
831
  assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5)
750
-
751
-
752
- # 1.0
753
-
754
- # Cells values in row 1:
755
- assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
756
- assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
757
- assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
758
-
759
- # Cells values in row 2:
760
- assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
761
- assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
762
- assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
763
-
764
- # Cells values in row 3:
765
- assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
766
- assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
767
- assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
768
-
769
- # Cells values in row 4:
770
- assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
771
- assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
772
- assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
773
-
774
- # Cells values in row 5:
775
- assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
776
- assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
777
- assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
832
+
833
+
834
+ # 1.0
835
+
836
+ # Cells values in row 1:
837
+ assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
838
+ assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
839
+ assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
840
+
841
+ # Cells values in row 2:
842
+ assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
843
+ assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
844
+ assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
845
+
846
+ # Cells values in row 3:
847
+ assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
848
+ assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
849
+ assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
850
+
851
+ # Cells values in row 4:
852
+ assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
853
+ assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
854
+ assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
855
+
856
+ # Cells values in row 5:
857
+ assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
858
+ assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
859
+ assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
778
860
 
779
861
  oo = Excel.new(File.join("test","simple_spreadsheet_from_italo.xls"))
780
862
  oo.default_sheet = oo.sheets.first
@@ -787,19 +869,19 @@ class TestRoo < Test::Unit::TestCase
787
869
  # assert_equal 2, oo.cell('B',2)
788
870
  # assert_equal 1, oo.cell('C',2)
789
871
  # are stored as strings, not numbers
790
-
872
+
791
873
  assert_equal 1, oo.cell('A',2).to_i
792
874
  assert_equal 2, oo.cell('B',2).to_i
793
875
  assert_equal 1, oo.cell('C',2).to_i
794
-
876
+
795
877
  assert_equal 1, oo.cell('A',3)
796
878
  assert_equal 3, oo.cell('B',3)
797
879
  assert_equal 1, oo.cell('C',3)
798
-
880
+
799
881
  assert_equal 'A', oo.cell('A',4)
800
882
  assert_equal 'A', oo.cell('B',4)
801
883
  assert_equal 'A', oo.cell('C',4)
802
-
884
+
803
885
  # assert_equal '0.01', oo.cell('A',5)
804
886
  # assert_equal '0.01', oo.cell('B',5)
805
887
  # assert_equal '0.01', oo.cell('C',5)
@@ -809,42 +891,42 @@ class TestRoo < Test::Unit::TestCase
809
891
  assert_equal 0.01, oo.cell('C',5)
810
892
 
811
893
  assert_equal 0.03, oo.cell('a',5)+oo.cell('b',5)+oo.cell('c',5)
812
-
813
-
814
- # 1.0
815
-
816
- # Cells values in row 1:
817
- assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
818
- assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
819
- assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
820
-
821
- # Cells values in row 2:
822
- assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
823
- assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
824
- assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
825
-
826
- # Cells values in row 3:
827
- assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
828
- assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
829
- assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
830
-
831
- # Cells values in row 4:
832
- assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
833
- assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
834
- assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
835
-
836
- # Cells values in row 5:
837
- #assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
838
- #assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
839
- #assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
840
- # why do we get floats here? in the spreadsheet the cells were defined
841
- # to be percentage
842
- # TODO: should be fixed
843
- # the excel gem does not support the cell type 'percentage' these
844
- # cells are returned to be of the type float.
845
- assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
846
- assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
847
- assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
894
+
895
+
896
+ # 1.0
897
+
898
+ # Cells values in row 1:
899
+ assert_equal "1:string", oo.cell(1, 1)+":"+oo.celltype(1, 1).to_s
900
+ assert_equal "1:string",oo.cell(1, 2)+":"+oo.celltype(1, 2).to_s
901
+ assert_equal "1:string",oo.cell(1, 3)+":"+oo.celltype(1, 3).to_s
902
+
903
+ # Cells values in row 2:
904
+ assert_equal "1:string",oo.cell(2, 1)+":"+oo.celltype(2, 1).to_s
905
+ assert_equal "2:string",oo.cell(2, 2)+":"+oo.celltype(2, 2).to_s
906
+ assert_equal "1:string",oo.cell(2, 3)+":"+oo.celltype(2, 3).to_s
907
+
908
+ # Cells values in row 3:
909
+ assert_equal "1.0:float",oo.cell(3, 1).to_s+":"+oo.celltype(3, 1).to_s
910
+ assert_equal "3.0:float",oo.cell(3, 2).to_s+":"+oo.celltype(3, 2).to_s
911
+ assert_equal "1.0:float",oo.cell(3, 3).to_s+":"+oo.celltype(3, 3).to_s
912
+
913
+ # Cells values in row 4:
914
+ assert_equal "A:string",oo.cell(4, 1)+":"+oo.celltype(4, 1).to_s
915
+ assert_equal "A:string",oo.cell(4, 2)+":"+oo.celltype(4, 2).to_s
916
+ assert_equal "A:string",oo.cell(4, 3)+":"+oo.celltype(4, 3).to_s
917
+
918
+ # Cells values in row 5:
919
+ #assert_equal "0.01:percentage",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
920
+ #assert_equal "0.01:percentage",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
921
+ #assert_equal "0.01:percentage",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
922
+ # why do we get floats here? in the spreadsheet the cells were defined
923
+ # to be percentage
924
+ # TODO: should be fixed
925
+ # the excel gem does not support the cell type 'percentage' these
926
+ # cells are returned to be of the type float.
927
+ assert_equal "0.01:float",oo.cell(5, 1).to_s+":"+oo.celltype(5, 1).to_s
928
+ assert_equal "0.01:float",oo.cell(5, 2).to_s+":"+oo.celltype(5, 2).to_s
929
+ assert_equal "0.01:float",oo.cell(5, 3).to_s+":"+oo.celltype(5, 3).to_s
848
930
  end
849
931
 
850
932
  end
@@ -867,7 +949,7 @@ class TestRoo < Test::Unit::TestCase
867
949
  [7, 2, "=SUM([.$A$1:.B6])"],
868
950
  [7, 3, "=[Sheet2.A1]"],
869
951
  [8, 2, "=SUM([.$A$1:.B7])"],
870
- ], oo.formulas
952
+ ], oo.formulas(oo.sheets.first)
871
953
 
872
954
  after Date.new(2007,6,25) do
873
955
  # setting a cell
@@ -881,7 +963,41 @@ class TestRoo < Test::Unit::TestCase
881
963
  #after Date.new(2007,7,30) do
882
964
  # assert_equal 21, oo.solve('a',7)
883
965
  #end
966
+ end
967
+ if defined? excel_supports_formulas
968
+ if EXCEL
969
+ oo = Excel.new(File.join("test","formula.xls"))
970
+ oo.default_sheet = oo.sheets.first
971
+ assert_equal 1, oo.cell('A',1)
972
+ assert_equal 2, oo.cell('A',2)
973
+ assert_equal 3, oo.cell('A',3)
974
+ assert_equal 4, oo.cell('A',4)
975
+ assert_equal 5, oo.cell('A',5)
976
+ assert_equal 6, oo.cell('A',6)
977
+ assert_equal :formula, oo.celltype('A',7)
978
+ assert_equal 21, oo.cell('A',7)
979
+ assert_equal " = [Sheet2.A1]", oo.formula('C',7)
980
+ assert_nil oo.formula('A',6)
981
+ assert_equal [[7, 1, " = SUM([.A1:.A6])"],
982
+ [7, 2, " = SUM([.$A$1:.B6])"],
983
+ [7, 3, " = [Sheet2.A1]"],
984
+ [8, 2, " = SUM([.$A$1:.B7])"],
985
+ ], oo.formulas
986
+
987
+ after Date.new(2007,6,25) do
988
+ # setting a cell
989
+ oo.set('A',15, 41)
990
+ assert_equal 41, oo.cell('A',15)
991
+ oo.set('A',16, "41")
992
+ assert_equal "41", oo.cell('A',16)
993
+ oo.set('A',17, 42.5)
994
+ assert_equal 42.5, oo.cell('A',17)
995
+ end
996
+ #after Date.new(2007,7,30) do
997
+ # assert_equal 21, oo.solve('a',7)
998
+ #end
884
999
 
1000
+ end
885
1001
  end
886
1002
  end
887
1003
 
@@ -896,14 +1012,10 @@ class TestRoo < Test::Unit::TestCase
896
1012
  assert_equal 8, oo.last_column
897
1013
 
898
1014
  oo.default_sheet = oo.sheets.first
899
- #assert_nil oo.first_row
900
1015
  assert_equal 5, oo.first_row
901
- #assert_nil oo.last_row
902
1016
  assert_equal 10, oo.last_row
903
1017
  assert_equal 3, oo.first_column
904
- #assert_nil oo.first_column
905
1018
  assert_equal 7, oo.last_column
906
- #assert_nil oo.last_column
907
1019
 
908
1020
  oo.default_sheet = oo.sheets[2]
909
1021
  assert_equal 7, oo.first_row
@@ -913,8 +1025,6 @@ class TestRoo < Test::Unit::TestCase
913
1025
  end
914
1026
  if EXCEL
915
1027
  oo = Excel.new(File.join("test","borders.xls"))
916
- #p oo.sheets
917
- #p oo.sheets[1]
918
1028
  oo.default_sheet = oo.sheets[1]
919
1029
  assert_equal 6, oo.first_row
920
1030
  assert_equal 11, oo.last_row
@@ -922,14 +1032,10 @@ class TestRoo < Test::Unit::TestCase
922
1032
  assert_equal 8, oo.last_column
923
1033
 
924
1034
  oo.default_sheet = 1 # oo.sheets.first
925
- #assert_nil oo.first_row
926
1035
  assert_equal 5, oo.first_row
927
- #assert_nil oo.last_row
928
1036
  assert_equal 10, oo.last_row
929
1037
  assert_equal 3, oo.first_column
930
- #assert_nil oo.first_column
931
1038
  assert_equal 7, oo.last_column
932
- #assert_nil oo.last_column
933
1039
 
934
1040
  oo.default_sheet = 3 # oo.sheets[2]
935
1041
  assert_equal 7, oo.first_row
@@ -1031,7 +1137,7 @@ class TestRoo < Test::Unit::TestCase
1031
1137
  #threads.each {|t| t.join }
1032
1138
  puts "fertig"
1033
1139
  Process.kill("INT",pid)
1034
- pid=Process.wait
1140
+ pid = Process.wait
1035
1141
  puts "child terminated, pid= #{pid}, status= #{$?.exitstatus}"
1036
1142
  end
1037
1143
  end # false
@@ -1085,7 +1191,7 @@ class TestRoo < Test::Unit::TestCase
1085
1191
  # end
1086
1192
 
1087
1193
  #def test_create_spreadsheet1
1088
- # name=File.join('test','createdspreadsheet.ods')
1194
+ # name = File.join('test','createdspreadsheet.ods')
1089
1195
  # rm(name) if File.exists?(File.join('test','createdspreadsheet.ods'))
1090
1196
  # # anlegen, falls noch nicht existierend
1091
1197
  # s = Openoffice.new(name,true)
@@ -1152,7 +1258,8 @@ class TestRoo < Test::Unit::TestCase
1152
1258
  if ONLINE
1153
1259
  url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
1154
1260
  sheet = Openoffice.new(url, :zip)
1155
- assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
1261
+ #has been changed: assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
1262
+ assert_in_delta 0.001, 505.14, sheet.cell('c', 33).to_f
1156
1263
  sheet.remove_tmp # don't forget to remove the temporary files
1157
1264
  end
1158
1265
  end
@@ -1173,71 +1280,69 @@ class TestRoo < Test::Unit::TestCase
1173
1280
  end
1174
1281
 
1175
1282
  def test_bug_ric
1176
- oo = Openoffice.new(File.join("test","ric.ods"))
1177
- oo.default_sheet = oo.sheets.first
1178
- assert oo.empty?('A',1)
1179
- assert oo.empty?('B',1)
1180
- assert oo.empty?('C',1)
1181
- assert oo.empty?('D',1)
1182
- expected = 1
1183
- letter = 'e'
1184
- while letter <= 'u'
1185
- assert_equal expected, oo.cell(letter,1)
1186
- letter.succ!
1187
- expected += 1
1188
- end
1189
- #assert_equal 2, oo.cell('f',1)
1190
- #assert_equal 3, oo.cell('g',1)
1191
- #assert_equal 4, oo.cell('h',1)
1192
- #assert_equal 5, oo.cell('i',1)
1193
- #assert_equal 6, oo.cell('j',1)
1194
- #assert_equal 7, oo.cell('k',1)
1195
- #assert_equal 8, oo.cell('l',1)
1196
- #assert_equal 9, oo.cell('m',1)
1197
- #assert_equal 10, oo.cell('n',1)
1198
- #assert_equal 11, oo.cell('o',1)
1199
- #assert_equal 12, oo.cell('p',1)
1200
- #assert_equal 13, oo.cell('q',1)
1201
- #assert_equal 14, oo.cell('r',1)
1202
- #assert_equal 15, oo.cell('s',1)
1203
- #assert_equal 16, oo.cell('t',1)
1204
- #assert_equal 17, oo.cell('u',1)
1205
- assert_equal 'J', oo.cell('v',1)
1206
- assert_equal 'P', oo.cell('w',1)
1207
- assert_equal 'B', oo.cell('x',1)
1208
- assert_equal 'All', oo.cell('y',1)
1209
- assert_equal 0, oo.cell('a',2)
1210
- assert oo.empty?('b',2)
1211
- assert oo.empty?('c',2)
1212
- assert oo.empty?('d',2)
1213
-
1214
- #'e'.upto('s') {|letter|
1215
- # assert_equal 'B', oo.cell(letter,2)
1216
- #}
1217
- after Date.new(2007,10,1) do
1218
- assert_equal 'B', oo.cell('e',2)
1219
- assert_equal 'B', oo.cell('f',2)
1220
- assert_equal 'B', oo.cell('g',2)
1221
- assert_equal 'B', oo.cell('h',2)
1222
- assert_equal 'B', oo.cell('i',2)
1223
- assert_equal 'B', oo.cell('j',2)
1224
- assert_equal 'B', oo.cell('k',2)
1225
- assert_equal 'B', oo.cell('l',2)
1226
- assert_equal 'B', oo.cell('m',2)
1227
- assert_equal 'B', oo.cell('n',2)
1228
- assert_equal 'B', oo.cell('o',2)
1229
- assert_equal 'B', oo.cell('p',2)
1230
- assert_equal 'B', oo.cell('q',2)
1231
- assert_equal 'B', oo.cell('r',2)
1232
- assert_equal 'B', oo.cell('s',2)
1233
- end
1234
-
1235
- assert oo.empty?('t',2)
1236
- assert oo.empty?('u',2)
1237
- assert_equal 0 , oo.cell('v',2)
1238
- assert_equal 0 , oo.cell('w',2)
1239
- assert_equal 15 , oo.cell('x',2)
1240
- assert_equal 15 , oo.cell('y',2)
1283
+ oo = Openoffice.new(File.join("test","ric.ods"))
1284
+ oo.default_sheet = oo.sheets.first
1285
+ assert oo.empty?('A',1)
1286
+ assert oo.empty?('B',1)
1287
+ assert oo.empty?('C',1)
1288
+ assert oo.empty?('D',1)
1289
+ expected = 1
1290
+ letter = 'e'
1291
+ while letter <= 'u'
1292
+ assert_equal expected, oo.cell(letter,1)
1293
+ letter.succ!
1294
+ expected += 1
1295
+ end
1296
+ #assert_equal 2, oo.cell('f',1)
1297
+ #assert_equal 3, oo.cell('g',1)
1298
+ #assert_equal 4, oo.cell('h',1)
1299
+ #assert_equal 5, oo.cell('i',1)
1300
+ #assert_equal 6, oo.cell('j',1)
1301
+ #assert_equal 7, oo.cell('k',1)
1302
+ #assert_equal 8, oo.cell('l',1)
1303
+ #assert_equal 9, oo.cell('m',1)
1304
+ #assert_equal 10, oo.cell('n',1)
1305
+ #assert_equal 11, oo.cell('o',1)
1306
+ #assert_equal 12, oo.cell('p',1)
1307
+ #assert_equal 13, oo.cell('q',1)
1308
+ #assert_equal 14, oo.cell('r',1)
1309
+ #assert_equal 15, oo.cell('s',1)
1310
+ #assert_equal 16, oo.cell('t',1)
1311
+ #assert_equal 17, oo.cell('u',1)
1312
+ assert_equal 'J', oo.cell('v',1)
1313
+ assert_equal 'P', oo.cell('w',1)
1314
+ assert_equal 'B', oo.cell('x',1)
1315
+ assert_equal 'All', oo.cell('y',1)
1316
+ assert_equal 0, oo.cell('a',2)
1317
+ assert oo.empty?('b',2)
1318
+ assert oo.empty?('c',2)
1319
+ assert oo.empty?('d',2)
1320
+
1321
+ #'e'.upto('s') {|letter|
1322
+ # assert_equal 'B', oo.cell(letter,2)
1323
+ #}
1324
+ assert_equal 'B', oo.cell('e',2)
1325
+ assert_equal 'B', oo.cell('f',2)
1326
+ assert_equal 'B', oo.cell('g',2)
1327
+ assert_equal 'B', oo.cell('h',2)
1328
+ assert_equal 'B', oo.cell('i',2)
1329
+ assert_equal 'B', oo.cell('j',2)
1330
+ assert_equal 'B', oo.cell('k',2)
1331
+ assert_equal 'B', oo.cell('l',2)
1332
+ assert_equal 'B', oo.cell('m',2)
1333
+ assert_equal 'B', oo.cell('n',2)
1334
+ assert_equal 'B', oo.cell('o',2)
1335
+ assert_equal 'B', oo.cell('p',2)
1336
+ assert_equal 'B', oo.cell('q',2)
1337
+ assert_equal 'B', oo.cell('r',2)
1338
+ assert_equal 'B', oo.cell('s',2)
1339
+
1340
+ assert oo.empty?('t',2)
1341
+ assert oo.empty?('u',2)
1342
+ assert_equal 0 , oo.cell('v',2)
1343
+ assert_equal 0 , oo.cell('w',2)
1344
+ assert_equal 15 , oo.cell('x',2)
1345
+ assert_equal 15 , oo.cell('y',2)
1241
1346
  end
1242
1347
 
1243
1348
  def test_mehrteilig
@@ -1248,57 +1353,39 @@ class TestRoo < Test::Unit::TestCase
1248
1353
  end
1249
1354
  end
1250
1355
 
1251
- def test_to_csv
1252
- after Date.new(2007,10,20) do
1356
+ def test_to_csv_openoffice
1357
+ if LONG_RUN
1253
1358
  if OPENOFFICE
1254
1359
  assert_nothing_raised(Timeout::Error) {
1255
- Timeout::timeout(40*60*2) do |timeout_length|
1256
- #puts Time.now.to_s + "test_to_csv Openoffice gestartet"
1257
- oo = Openoffice.new(File.join("test","Bibelbund.ods"))
1360
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1361
+ oo = Openoffice.new(File.join("test","Bibelbund500.ods"))
1258
1362
  oo.default_sheet = oo.sheets.first
1259
1363
  assert_equal "Tagebuch des Sekret\303\244rs. Letzte Tagung 15./16.11.75 Schweiz", oo.cell(45,'A')
1260
1364
  assert_equal "Tagebuch des Sekret\303\244rs. Nachrichten aus Chile", oo.cell(46,'A')
1261
1365
  assert_equal "Tagebuch aus Chile Juli 1977", oo.cell(55,'A')
1262
- #puts Time.now.to_s + "vor to_csv"
1263
- #assert oo.to_csv
1264
- #puts Time.now.to_s + "nach to_csv"
1265
-
1266
- #puts Time.now.to_s + "vor to_csv(datei)"
1267
1366
  assert oo.to_csv("/tmp/Bibelbund.csv")
1268
- #puts Time.now.to_s + "nach to_csv(datei)"
1269
- #puts Time.now.to_s + "vor File.exist"
1270
1367
  assert File.exists?("/tmp/Bibelbund.csv")
1271
- #puts Time.now.to_s + "nach File.exist"
1272
1368
  assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
1273
- #puts Time.now.to_s + "test_to_csv Openoffice beendet"
1274
1369
  end # Timeout
1275
1370
  } # nothing_raised
1276
1371
  end # OPENOFFICE
1277
- end # after
1372
+ end
1373
+ end
1278
1374
 
1279
- after Date.new(2007,10,20) do
1375
+ def test_to_csv_excel
1376
+ if LONG_RUN
1280
1377
  if EXCEL
1281
1378
  assert_nothing_raised(Timeout::Error) {
1282
- Timeout::timeout(40*60*2) do |timeout_length|
1283
- #puts Time.now.to_s + "test_to_csv Excel gestartet"
1284
- oo = Excel.new(File.join("test","Bibelbund.xls"))
1379
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1380
+ oo = Excel.new(File.join("test","Bibelbund500.xls"))
1285
1381
  oo.default_sheet = oo.sheets.first
1286
- #puts Time.now.to_s + "vor to_csv"
1287
- #assert oo.to_csv
1288
- #puts Time.now.to_s + "nach to_csv"
1289
- #Timeout:timeout(3*60)) do |timeout_length|
1290
- #puts Time.now.to_s + "vor to_csv(datei)"
1291
1382
  assert oo.to_csv("/tmp/Bibelbund.csv")
1292
- #puts Time.now.to_s + "nach to_csv(datei)"
1293
- #puts Time.now.to_s + "vor File.exist"
1294
1383
  assert File.exists?("/tmp/Bibelbund.csv")
1295
- #puts Time.now.to_s + "nach File.exist"
1296
1384
  assert_equal "", `diff test/Bibelbund.csv /tmp/Bibelbund.csv`
1297
- #puts Time.now.to_s + "test_to_csv Excel beendet"
1298
1385
  end
1299
1386
  }
1300
1387
  end
1301
- end
1388
+ end # LONG_RUN
1302
1389
  end # def to_csv
1303
1390
 
1304
1391
  def test_bug_mehrere_datum
@@ -1373,4 +1460,515 @@ class TestRoo < Test::Unit::TestCase
1373
1460
  end # Excel
1374
1461
  end
1375
1462
 
1463
+ def test_multiple_sheets
1464
+ if OPENOFFICE
1465
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
1466
+ 2.times do
1467
+ oo.default_sheet = "Tabelle1"
1468
+ assert_equal 1, oo.cell(1,1)
1469
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
1470
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
1471
+ sheetname = 'Sheet5'
1472
+ assert_equal :date, oo.celltype('A',4,sheetname)
1473
+ assert_equal :date, oo.celltype('B',4,sheetname)
1474
+ assert_equal :date, oo.celltype('C',4,sheetname)
1475
+ assert_equal :date, oo.celltype('D',4,sheetname)
1476
+ assert_equal :date, oo.celltype('E',4,sheetname)
1477
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
1478
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
1479
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
1480
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
1481
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
1482
+ assert_equal :float, oo.celltype('A',5,sheetname)
1483
+ assert_equal :float, oo.celltype('B',5,sheetname)
1484
+ assert_equal :float, oo.celltype('C',5,sheetname)
1485
+ assert_equal :float, oo.celltype('D',5,sheetname)
1486
+ assert_equal :float, oo.celltype('E',5,sheetname)
1487
+ assert_equal 42, oo.cell('A',5,sheetname)
1488
+ assert_equal 42, oo.cell('B',5,sheetname)
1489
+ assert_equal 42, oo.cell('C',5,sheetname)
1490
+ assert_equal 42, oo.cell('D',5,sheetname)
1491
+ assert_equal 42, oo.cell('E',5,sheetname)
1492
+ assert_equal :string, oo.celltype('A',6,sheetname)
1493
+ assert_equal :string, oo.celltype('B',6,sheetname)
1494
+ assert_equal :string, oo.celltype('C',6,sheetname)
1495
+ assert_equal :string, oo.celltype('D',6,sheetname)
1496
+ assert_equal :string, oo.celltype('E',6,sheetname)
1497
+ assert_equal "ABC", oo.cell('A',6,sheetname)
1498
+ assert_equal "ABC", oo.cell('B',6,sheetname)
1499
+ assert_equal "ABC", oo.cell('C',6,sheetname)
1500
+ assert_equal "ABC", oo.cell('D',6,sheetname)
1501
+ assert_equal "ABC", oo.cell('E',6,sheetname)
1502
+ oo.reload
1503
+ end
1504
+ end
1505
+ if EXCEL
1506
+ oo = Excel.new(File.join("test","numbers1.xls"))
1507
+ 2.times do
1508
+ oo.default_sheet = "Tabelle1"
1509
+ assert_equal 1, oo.cell(1,1)
1510
+ assert_equal 1, oo.cell(1,1,"Tabelle1")
1511
+ assert_equal "I am sheet 2", oo.cell('C',5,"Name of Sheet 2")
1512
+ sheetname = 'Sheet5'
1513
+ assert_equal :date, oo.celltype('A',4,sheetname)
1514
+ assert_equal :date, oo.celltype('B',4,sheetname)
1515
+ assert_equal :date, oo.celltype('C',4,sheetname)
1516
+ assert_equal :date, oo.celltype('D',4,sheetname)
1517
+ assert_equal :date, oo.celltype('E',4,sheetname)
1518
+ assert_equal Date.new(2007,11,21), oo.cell('A',4,sheetname)
1519
+ assert_equal Date.new(2007,11,21), oo.cell('B',4,sheetname)
1520
+ assert_equal Date.new(2007,11,21), oo.cell('C',4,sheetname)
1521
+ assert_equal Date.new(2007,11,21), oo.cell('D',4,sheetname)
1522
+ assert_equal Date.new(2007,11,21), oo.cell('E',4,sheetname)
1523
+ assert_equal :float, oo.celltype('A',5,sheetname)
1524
+ assert_equal :float, oo.celltype('B',5,sheetname)
1525
+ assert_equal :float, oo.celltype('C',5,sheetname)
1526
+ assert_equal :float, oo.celltype('D',5,sheetname)
1527
+ assert_equal :float, oo.celltype('E',5,sheetname)
1528
+ assert_equal 42, oo.cell('A',5,sheetname)
1529
+ assert_equal 42, oo.cell('B',5,sheetname)
1530
+ assert_equal 42, oo.cell('C',5,sheetname)
1531
+ assert_equal 42, oo.cell('D',5,sheetname)
1532
+ assert_equal 42, oo.cell('E',5,sheetname)
1533
+ assert_equal :string, oo.celltype('A',6,sheetname)
1534
+ assert_equal :string, oo.celltype('B',6,sheetname)
1535
+ assert_equal :string, oo.celltype('C',6,sheetname)
1536
+ assert_equal :string, oo.celltype('D',6,sheetname)
1537
+ assert_equal :string, oo.celltype('E',6,sheetname)
1538
+ assert_equal "ABC", oo.cell('A',6,sheetname)
1539
+ assert_equal "ABC", oo.cell('B',6,sheetname)
1540
+ assert_equal "ABC", oo.cell('C',6,sheetname)
1541
+ assert_equal "ABC", oo.cell('D',6,sheetname)
1542
+ assert_equal "ABC", oo.cell('E',6,sheetname)
1543
+ oo.reload
1544
+ end
1545
+ end
1546
+ end
1547
+
1548
+ def test_bug_empty_sheet
1549
+ oo = Openoffice.new(File.join("test","formula.ods"))
1550
+ oo.default_sheet = 'Sheet3' # is an empty sheet
1551
+ assert_nothing_raised(NoMethodError) {
1552
+ oo.to_csv(File.join("/","tmp","emptysheet.csv"))
1553
+ }
1554
+ assert_equal "", `cat /tmp/emptysheet.csv`
1555
+ end
1556
+
1557
+ def test_find_by_row_openoffice
1558
+ if LONG_RUN
1559
+ if OPENOFFICE
1560
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1561
+ oo = Openoffice.new(File.join("test","Bibelbund500.ods"))
1562
+ oo.default_sheet = oo.sheets.first
1563
+ rec = oo.find 20
1564
+ assert rec
1565
+ # assert_equal "Brief aus dem Sekretariat", rec[0]
1566
+ #p rec
1567
+ assert_equal "Brief aus dem Sekretariat", rec[0]['TITEL']
1568
+
1569
+ rec = oo.find 22
1570
+ assert rec
1571
+ # assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
1572
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]['TITEL']
1573
+ end
1574
+ end
1575
+ end
1576
+ end
1577
+
1578
+ def test_find_by_row_excel
1579
+ if LONG_RUN
1580
+ if EXCEL
1581
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1582
+ oo = Excel.new(File.join("test","Bibelbund500.xls"))
1583
+ oo.default_sheet = oo.sheets.first
1584
+ rec = oo.find 20
1585
+ assert rec
1586
+ assert_equal "Brief aus dem Sekretariat", rec[0]
1587
+
1588
+ rec = oo.find 22
1589
+ assert rec
1590
+ assert_equal "Brief aus dem Skretariat. Tagung in Amberg/Opf.",rec[0]
1591
+ end
1592
+ end
1593
+ end
1594
+ end
1595
+
1596
+ def test_find_by_conditions_openoffice
1597
+ if LONG_RUN
1598
+ if OPENOFFICE
1599
+ assert_nothing_raised(Timeout::Error) {
1600
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1601
+ oo = Openoffice.new(File.join("test","Bibelbund500.ods"))
1602
+ oo.default_sheet = oo.sheets.first
1603
+ #-----------------------------------------------------------------
1604
+ zeilen = oo.find(:all, :conditions => {
1605
+ 'TITEL' => 'Brief aus dem Sekretariat'
1606
+ }
1607
+ )
1608
+ assert_equal 2, zeilen.size
1609
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1610
+ "INTERNET"=>nil,
1611
+ "SEITE"=>316.0,
1612
+ "KENNUNG"=>"Aus dem Bibelbund",
1613
+ "OBJEKT"=>"Bibel+Gem",
1614
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1615
+ "NUMMER"=>"1982-3",
1616
+ "TITEL"=>"Brief aus dem Sekretariat"},
1617
+ {"VERFASSER"=>"Almassy, Annelene von",
1618
+ "INTERNET"=>nil,
1619
+ "SEITE"=>222.0,
1620
+ "KENNUNG"=>"Aus dem Bibelbund",
1621
+ "OBJEKT"=>"Bibel+Gem",
1622
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1623
+ "NUMMER"=>"1983-2",
1624
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1625
+
1626
+ #----------------------------------------------------------
1627
+ zeilen = oo.find(:all,
1628
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
1629
+ )
1630
+ assert_equal 13, zeilen.size
1631
+ #----------------------------------------------------------
1632
+ zeilen = oo.find(:all, :conditions => {
1633
+ 'TITEL' => 'Brief aus dem Sekretariat',
1634
+ 'VERFASSER' => 'Almassy, Annelene von',
1635
+ }
1636
+ )
1637
+ assert_equal 2, zeilen.size
1638
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1639
+ "INTERNET"=>nil,
1640
+ "SEITE"=>316.0,
1641
+ "KENNUNG"=>"Aus dem Bibelbund",
1642
+ "OBJEKT"=>"Bibel+Gem",
1643
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1644
+ "NUMMER"=>"1982-3",
1645
+ "TITEL"=>"Brief aus dem Sekretariat"},
1646
+ {"VERFASSER"=>"Almassy, Annelene von",
1647
+ "INTERNET"=>nil,
1648
+ "SEITE"=>222.0,
1649
+ "KENNUNG"=>"Aus dem Bibelbund",
1650
+ "OBJEKT"=>"Bibel+Gem",
1651
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1652
+ "NUMMER"=>"1983-2",
1653
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1654
+
1655
+ # Result as an array
1656
+ zeilen = oo.find(:all,
1657
+ :conditions => {
1658
+ 'TITEL' => 'Brief aus dem Sekretariat',
1659
+ 'VERFASSER' => 'Almassy, Annelene von',
1660
+ }, :array => true)
1661
+ assert_equal 2, zeilen.size
1662
+ assert_equal [
1663
+ [
1664
+ "Brief aus dem Sekretariat",
1665
+ "Almassy, Annelene von",
1666
+ "Bibel+Gem",
1667
+ "1982-3",
1668
+ 316.0,
1669
+ nil,
1670
+ "#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1671
+ "Aus dem Bibelbund",
1672
+ ],
1673
+ [
1674
+ "Brief aus dem Sekretariat",
1675
+ "Almassy, Annelene von",
1676
+ "Bibel+Gem",
1677
+ "1983-2",
1678
+ 222.0,
1679
+ nil,
1680
+ "#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1681
+ "Aus dem Bibelbund",
1682
+ ]] , zeilen
1683
+ end # Timeout
1684
+ } # nothing_raised
1685
+ end
1686
+ end
1687
+ end
1688
+
1689
+ def test_find_by_conditions_excel
1690
+ if LONG_RUN
1691
+ if EXCEL
1692
+ assert_nothing_raised(Timeout::Error) {
1693
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1694
+ oo = Excel.new(File.join("test","Bibelbund500.xls"))
1695
+ oo.default_sheet = oo.sheets.first
1696
+ #-----------------------------------------------------------------
1697
+ zeilen = oo.find(:all, :conditions => {
1698
+ 'TITEL' => 'Brief aus dem Sekretariat'
1699
+ }
1700
+ )
1701
+ assert_equal 2, zeilen.size
1702
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1703
+ "INTERNET"=>nil,
1704
+ "SEITE"=>316.0,
1705
+ "KENNUNG"=>"Aus dem Bibelbund",
1706
+ "OBJEKT"=>"Bibel+Gem",
1707
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1708
+ "NUMMER"=>"1982-3",
1709
+ "TITEL"=>"Brief aus dem Sekretariat"},
1710
+ {"VERFASSER"=>"Almassy, Annelene von",
1711
+ "INTERNET"=>nil,
1712
+ "SEITE"=>222.0,
1713
+ "KENNUNG"=>"Aus dem Bibelbund",
1714
+ "OBJEKT"=>"Bibel+Gem",
1715
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1716
+ "NUMMER"=>"1983-2",
1717
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1718
+
1719
+ #----------------------------------------------------------
1720
+ zeilen = oo.find(:all,
1721
+ :conditions => { 'VERFASSER' => 'Almassy, Annelene von' }
1722
+ )
1723
+ assert_equal 13, zeilen.size
1724
+ #----------------------------------------------------------
1725
+ zeilen = oo.find(:all, :conditions => {
1726
+ 'TITEL' => 'Brief aus dem Sekretariat',
1727
+ 'VERFASSER' => 'Almassy, Annelene von',
1728
+ }
1729
+ )
1730
+ assert_equal 2, zeilen.size
1731
+ assert_equal [{"VERFASSER"=>"Almassy, Annelene von",
1732
+ "INTERNET"=>nil,
1733
+ "SEITE"=>316.0,
1734
+ "KENNUNG"=>"Aus dem Bibelbund",
1735
+ "OBJEKT"=>"Bibel+Gem",
1736
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1982-3.pdf#",
1737
+ "NUMMER"=>"1982-3",
1738
+ "TITEL"=>"Brief aus dem Sekretariat"},
1739
+ {"VERFASSER"=>"Almassy, Annelene von",
1740
+ "INTERNET"=>nil,
1741
+ "SEITE"=>222.0,
1742
+ "KENNUNG"=>"Aus dem Bibelbund",
1743
+ "OBJEKT"=>"Bibel+Gem",
1744
+ "PC"=>"#C:\\Bibelbund\\reprint\\BuG1983-2.pdf#",
1745
+ "NUMMER"=>"1983-2",
1746
+ "TITEL"=>"Brief aus dem Sekretariat"}] , zeilen
1747
+ end # Timeout
1748
+ } # nothing_raised
1749
+ end
1750
+ end
1751
+ end
1752
+
1753
+ def test_columns_openoffice
1754
+ 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)]
1755
+ if OPENOFFICE
1756
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1757
+ oo = Openoffice.new(File.join('test','numbers1.ods'))
1758
+ oo.default_sheet = oo.sheets.first
1759
+ assert_equal expected, oo.column(1)
1760
+ assert_equal expected, oo.column('a')
1761
+ end
1762
+ end
1763
+ end
1764
+
1765
+ def test_columns_excel
1766
+ 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)]
1767
+ if EXCEL
1768
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1769
+ oo = Excel.new(File.join('test','numbers1.xls'))
1770
+ oo.default_sheet = oo.sheets.first
1771
+ assert_equal expected, oo.column(1)
1772
+ assert_equal expected, oo.column('a')
1773
+ end
1774
+ end
1775
+ end
1776
+
1777
+ def test_column_huge_document_openoffice
1778
+ if LONG_RUN
1779
+ if OPENOFFICE
1780
+ assert_nothing_raised(Timeout::Error) {
1781
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1782
+ #puts Time.now.to_s + "column Openoffice gestartet"
1783
+ oo = Openoffice.new(File.join('test','Bibelbund500.ods'))
1784
+ oo.default_sheet = oo.sheets.first
1785
+ #assert_equal 3735, oo.column('a').size
1786
+ assert_equal 499, oo.column('a').size
1787
+ #puts Time.now.to_s + "column Openoffice beendet"
1788
+ end
1789
+ }
1790
+ end
1791
+ end
1792
+ end
1793
+
1794
+ def test_column_huge_document_excel
1795
+ if LONG_RUN
1796
+ if EXCEL
1797
+ assert_nothing_raised(Timeout::Error) {
1798
+ Timeout::timeout(GLOBAL_TIMEOUT) do |timeout_length|
1799
+ #puts Time.now.to_s + "column Excel gestartet"
1800
+ oo = Excel.new(File.join('test','Bibelbund500.xls'))
1801
+ oo.default_sheet = oo.sheets.first
1802
+ #assert_equal 3735, oo.column('a').size
1803
+ assert_equal 499, oo.column('a').size
1804
+ #puts Time.now.to_s + "column Excel beendet"
1805
+ end
1806
+ }
1807
+ end
1808
+ end
1809
+ end
1810
+
1811
+ def test_simple_spreadsheet_find_by_condition_openoffice
1812
+ oo = Openoffice.new(File.join("test","simple_spreadsheet.ods"))
1813
+ oo.default_sheet = oo.sheets.first
1814
+ oo.header_line = 3
1815
+ erg = oo.find(:all, :conditions => {'Comment' => 'Task 1'})
1816
+ assert_equal Date.new(2007,05,07), erg[1]['Date']
1817
+ assert_equal 10.75 , erg[1]['Start time']
1818
+ assert_equal 12.50 , erg[1]['End time']
1819
+ assert_equal 0 , erg[1]['Pause']
1820
+ assert_equal 1.75 , erg[1]['Sum']
1821
+ assert_equal "Task 1" , erg[1]['Comment']
1822
+ end
1823
+
1824
+ def DONT_test_false_encoding
1825
+ ex = Excel.new(File.join('test','false_encoding.xls'))
1826
+ ex.default_sheet = ex.sheets.first
1827
+ assert_equal "Sheet1", ex.sheets.first
1828
+ ex.first_row.upto(ex.last_row) do |row|
1829
+ ex.first_column.upto(ex.last_column) do |col|
1830
+ content = ex.cell(row,col)
1831
+ puts "#{row}/#{col}"
1832
+ #puts content if ! ex.empty?(row,col) or ex.formula?(row,col)
1833
+ if ex.formula?(row,col)
1834
+ #! ex.empty?(row,col)
1835
+ puts content
1836
+ end
1837
+ end
1838
+ end
1839
+ end
1840
+
1841
+ def test_bug_false_borders_with_formulas
1842
+ ex = Excel.new(File.join('test','false_encoding.xls'))
1843
+ ex.default_sheet = ex.sheets.first
1844
+ assert_equal 1, ex.first_row
1845
+ assert_equal 3, ex.last_row
1846
+ assert_equal 1, ex.first_column
1847
+ assert_equal 4, ex.last_column
1848
+ end
1849
+
1850
+ def test_fe
1851
+ ex = Excel.new(File.join('test','false_encoding.xls'))
1852
+ ex.default_sheet = ex.sheets.first
1853
+ #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2007,11,1), ex.cell('a',1)
1854
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('a',1)
1855
+ #DOES NOT WORK IN EXCEL FILES: assert_equal '=TODAY()', ex.formula('a',1)
1856
+
1857
+ #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2008,2,9), ex.cell('B',1)
1858
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('B',1)
1859
+ #DOES NOT WORK IN EXCEL FILES: assert_equal "=A1+100", ex.formula('B',1)
1860
+
1861
+ #DOES NOT WORK IN EXCEL FILES: assert_equal Date.new(2008,2,9), ex.cell('C',1)
1862
+ #DOES NOT WORK IN EXCEL FILES: assert_equal true, ex.formula?('C',1)
1863
+ #DOES NOT WORK IN EXCEL FILES: assert_equal "=C1", ex.formula('C',1)
1864
+
1865
+ assert_equal 'H1', ex.cell('A',2)
1866
+ assert_equal 'H2', ex.cell('B',2)
1867
+ assert_equal 'H3', ex.cell('C',2)
1868
+ assert_equal 'H4', ex.cell('D',2)
1869
+ assert_equal 'R1', ex.cell('A',3)
1870
+ assert_equal 'R2', ex.cell('B',3)
1871
+ assert_equal 'R3', ex.cell('C',3)
1872
+ assert_equal 'R4', ex.cell('D',3)
1873
+ end
1874
+
1875
+ def test_excel_does_not_support_formulas
1876
+ ex = Excel.new(File.join('test','false_encoding.xls'))
1877
+ ex.default_sheet = ex.sheets.first
1878
+ assert_raise(RuntimeError) {
1879
+ void = ex.formula('a',1)
1880
+ }
1881
+ assert_raise(RuntimeError) {
1882
+ void = ex.formula?('a',1)
1883
+ }
1884
+ assert_raise(RuntimeError) {
1885
+ void = ex.formulas(ex.sheets.first)
1886
+ }
1887
+
1888
+ end
1889
+
1890
+ def test_info
1891
+ expected_templ = "File: test/numbers1%s\n"+
1892
+ "Number of sheets: 5\n"+
1893
+ "Sheets: Tabelle1, Name of Sheet 2, Sheet3, Sheet4, Sheet5\n"+
1894
+ "Sheet 1:\n"+
1895
+ " First row: 1\n"+
1896
+ " Last row: 18\n"+
1897
+ " First column: A\n"+
1898
+ " Last column: G\n"+
1899
+ "Sheet 2:\n"+
1900
+ " First row: 5\n"+
1901
+ " Last row: 14\n"+
1902
+ " First column: B\n"+
1903
+ " Last column: E\n"+
1904
+ "Sheet 3:\n"+
1905
+ " First row: 1\n"+
1906
+ " Last row: 1\n"+
1907
+ " First column: A\n"+
1908
+ " Last column: BA\n"+
1909
+ "Sheet 4:\n"+
1910
+ " First row: 1\n"+
1911
+ " Last row: 1\n"+
1912
+ " First column: A\n"+
1913
+ " Last column: E\n"+
1914
+ "Sheet 5:\n"+
1915
+ " First row: 1\n"+
1916
+ " Last row: 6\n"+
1917
+ " First column: A\n"+
1918
+ " Last column: E"
1919
+ if OPENOFFICE
1920
+ ext = ".ods"
1921
+ expected = sprintf(expected_templ,ext)
1922
+ oo = Openoffice.new(File.join("test","numbers1.ods"))
1923
+ assert_equal expected, oo.info
1924
+ end
1925
+ if EXCEL
1926
+ ext = ".xls"
1927
+ expected = sprintf(expected_templ,ext)
1928
+ oo = Excel.new(File.join("test","numbers1.xls"))
1929
+ assert_equal expected, oo.info
1930
+ end
1931
+ end
1932
+
1933
+ def test_bug_excel_numbers1_sheet5_last_row
1934
+ oo = Excel.new(File.join("test","numbers1.xls"))
1935
+ oo.default_sheet = "Tabelle1"
1936
+ assert_equal 1, oo.first_row
1937
+ assert_equal 18, oo.last_row
1938
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
1939
+ assert_equal Openoffice.letter_to_number('G'), oo.last_column
1940
+ oo.default_sheet = "Name of Sheet 2"
1941
+ assert_equal 5, oo.first_row
1942
+ assert_equal 14, oo.last_row
1943
+ assert_equal Openoffice.letter_to_number('B'), oo.first_column
1944
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
1945
+ oo.default_sheet = "Sheet3"
1946
+ assert_equal 1, oo.first_row
1947
+ assert_equal 1, oo.last_row
1948
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
1949
+ assert_equal Openoffice.letter_to_number('BA'), oo.last_column
1950
+ oo.default_sheet = "Sheet4"
1951
+ assert_equal 1, oo.first_row
1952
+ assert_equal 1, oo.last_row
1953
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
1954
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
1955
+ oo.default_sheet = "Sheet5"
1956
+ assert_equal 1, oo.first_row
1957
+ assert_equal 6, oo.last_row
1958
+ assert_equal Openoffice.letter_to_number('A'), oo.first_column
1959
+ assert_equal Openoffice.letter_to_number('E'), oo.last_column
1960
+ end
1961
+
1962
+ def test_should_raise_file_not_found_error
1963
+ if OPENOFFICE
1964
+ assert_raise(IOError) {
1965
+ oo = Openoffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
1966
+ }
1967
+ end
1968
+ if EXCEL
1969
+ assert_raise(IOError) {
1970
+ oo = Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
1971
+ }
1972
+ end
1973
+ end
1376
1974
  end # class