roo 1.2.2 → 1.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,9 +1,16 @@
1
- == 1.2.2 2008-12-??
1
+ == 1.2.3 2009-01-04
2
+
3
+ * bugfix
4
+ * fixed encoding in #cell at exported Google-spreadsheets (.xls)
5
+
6
+ == 1.2.2 2008-12-14
7
+
2
8
  * 2 enhancements
3
9
  * added celltype :datetime in Excelx
4
10
  * added celltype :datetime in Google
5
11
 
6
12
  == 1.2.1 2008-11-13
13
+
7
14
  * 1 enhancement
8
15
  * added celltype :datetime in Openoffice and Excel
9
16
 
@@ -60,6 +60,7 @@ test/emptysheets.ods
60
60
  test/emptysheets.xls
61
61
  test/datetime.ods
62
62
  test/datetime.xls
63
+ test/datetime.xlsx
63
64
  website/index.html
64
65
  website/index.txt
65
66
  website/javascripts/rounded_corners_lite.inc.js
@@ -91,7 +91,11 @@ class Excel < GenericSpreadsheet
91
91
  yyyy,mm,dd = @cell[sheet][[row,col]].split('-')
92
92
  return Date.new(yyyy.to_i,mm.to_i,dd.to_i)
93
93
  end
94
- return @cell[sheet][[row,col]]
94
+ if celltype(row,col,sheet) == :string
95
+ return platform_specific_iconv(@cell[sheet][[row,col]])
96
+ else
97
+ return @cell[sheet][[row,col]]
98
+ end
95
99
  end
96
100
 
97
101
  # returns the type of a cell:
@@ -265,6 +269,7 @@ class Excel < GenericSpreadsheet
265
269
 
266
270
  def every_second_null?(str)
267
271
  result = true
272
+ return false if str.length < 2
268
273
  0.upto(str.length/2-1) do |i|
269
274
  c = str[i*2,1]
270
275
  n = str[i*2+1,1]
@@ -434,21 +434,56 @@ class GenericSpreadsheet
434
434
  return row,col
435
435
  end
436
436
 
437
+ # def open_from_uri(uri)
438
+ # require 'open-uri' ;
439
+ # tempfilename = File.join(@tmpdir, File.basename(uri))
440
+ # f = File.open(tempfilename,"wb")
441
+ # begin
442
+ # open(uri) do |net|
443
+ # f.write(net.read)
444
+ # end
445
+ # rescue
446
+ # raise "could not open #{uri}"
447
+ # end
448
+ # f.close
449
+ # File.join(@tmpdir, File.basename(uri))
450
+ # end
451
+
452
+ # OpenURI::HTTPError
453
+ # def open_from_uri(uri)
454
+ # require 'open-uri'
455
+ # #existiert URL?
456
+ # r = Net::HTTP.get_response(URI.parse(uri))
457
+ # raise "URL nicht verfuegbar" unless r.is_a? Net::HTTPOK
458
+ # tempfilename = File.join(@tmpdir, File.basename(uri))
459
+ # f = File.open(tempfilename,"wb")
460
+ # open(uri) do |net|
461
+ # f.write(net.read)
462
+ # end
463
+ # # rescue
464
+ # # raise "could not open #{uri}"
465
+ # # end
466
+ # f.close
467
+ # File.join(@tmpdir, File.basename(uri))
468
+ # end
469
+
437
470
  def open_from_uri(uri)
438
- require 'open-uri' ;
439
- tempfilename = File.join(@tmpdir, File.basename(uri))
440
- f = File.open(tempfilename,"wb")
471
+ require 'open-uri'
472
+ response = ''
441
473
  begin
442
- open(uri) do |net|
443
- f.write(net.read)
444
- end
445
- rescue
474
+ open(uri, "User-Agent" => "Ruby/#{RUBY_VERSION}") { |net|
475
+ response = net.read
476
+ tempfilename = File.join(@tmpdir, File.basename(uri))
477
+ f = File.open(tempfilename,"wb")
478
+ f.write(response)
479
+ f.close
480
+ }
481
+ rescue OpenURI::HTTPError
446
482
  raise "could not open #{uri}"
447
483
  end
448
- f.close
449
484
  File.join(@tmpdir, File.basename(uri))
450
485
  end
451
-
486
+
452
487
  def open_from_stream(stream)
453
488
  tempfilename = File.join(@tmpdir, "spreadsheet")
454
489
  f = File.open(tempfilename,"wb")
@@ -2,7 +2,7 @@ module Roo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 1
4
4
  MINOR = 2
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
Binary file
@@ -113,7 +113,7 @@ class TestRoo < Test::Unit::TestCase
113
113
  EXCELX = true # do Excel-X Tests? (.xlsx-files)
114
114
 
115
115
  OPENOFFICEWRITE = false # experimental: write access with OO-Documents
116
- ONLINE = false
116
+ ONLINE = true
117
117
  LONG_RUN = false
118
118
  GLOBAL_TIMEOUT = 48.minutes #*60 # 2*12*60 # seconds
119
119
 
@@ -1972,7 +1972,7 @@ class TestRoo < Test::Unit::TestCase
1972
1972
  end
1973
1973
 
1974
1974
  def test_excel_zipped
1975
- after Date.new(2008,12,31) do
1975
+ after Date.new(2009,1,10) do
1976
1976
  if EXCEL
1977
1977
  $log.level = Logger::DEBUG
1978
1978
  excel = Excel.new(File.join("test","bode-v1.xls.zip"), :zip)
@@ -3398,23 +3398,23 @@ class TestRoo < Test::Unit::TestCase
3398
3398
  end
3399
3399
 
3400
3400
  def test_should_raise_file_not_found_error
3401
- after Date.new(2008,12,31) do
3402
- if OPENOFFICE
3403
- assert_raise(IOError) {
3404
- oo = Openoffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
3405
- }
3406
- end
3407
- if EXCEL
3408
- assert_raise(IOError) {
3409
- oo = Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
3410
- }
3411
- end
3412
- if EXCELX
3413
- assert_raise(IOError) {
3414
- oo = Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
3415
- }
3416
- end
3417
- if GOOGLE
3401
+ if OPENOFFICE
3402
+ assert_raise(IOError) {
3403
+ oo = Openoffice.new(File.join('testnichtvorhanden','Bibelbund.ods'))
3404
+ }
3405
+ end
3406
+ if EXCEL
3407
+ assert_raise(IOError) {
3408
+ oo = Excel.new(File.join('testnichtvorhanden','Bibelbund.xls'))
3409
+ }
3410
+ end
3411
+ if EXCELX
3412
+ assert_raise(IOError) {
3413
+ oo = Excelx.new(File.join('testnichtvorhanden','Bibelbund.xlsx'))
3414
+ }
3415
+ end
3416
+ if GOOGLE
3417
+ after Date.new(2009,1,15) do
3418
3418
  assert_raise(IOError) {
3419
3419
  # oo = Google.new(key_of('testnichtvorhanden'+'Bibelbund.ods'))
3420
3420
  oo = Google.new('testnichtvorhanden')
@@ -3422,7 +3422,7 @@ class TestRoo < Test::Unit::TestCase
3422
3422
  end
3423
3423
  end
3424
3424
  end
3425
-
3425
+
3426
3426
  def test_bug_cell_no_default_sheet
3427
3427
  if GOOGLE
3428
3428
  oo = Google.new(key_of("numbers1"))
@@ -3876,20 +3876,20 @@ Sheet 3:
3876
3876
  end
3877
3877
 
3878
3878
  def test_bug_row_column_fixnum_float
3879
- if EXCEL
3880
- ex = Excel.new(File.join('test','bug-row-column-fixnum-float.xls'))
3881
- ex.default_sheet = ex.sheets.first
3882
- assert_equal 42.5, ex.cell('b',2)
3883
- assert_equal 43 , ex.cell('c',2)
3884
- assert_equal ['hij',42.5, 43], ex.row(2)
3885
- assert_equal ['def',42.5, 'nop'], ex.column(2)
3886
- end
3879
+ if EXCEL
3880
+ ex = Excel.new(File.join('test','bug-row-column-fixnum-float.xls'))
3881
+ ex.default_sheet = ex.sheets.first
3882
+ assert_equal 42.5, ex.cell('b',2)
3883
+ assert_equal 43 , ex.cell('c',2)
3884
+ assert_equal ['hij',42.5, 43], ex.row(2)
3885
+ assert_equal ['def',42.5, 'nop'], ex.column(2)
3886
+ end
3887
3887
 
3888
3888
  end
3889
3889
 
3890
3890
  def test_bug_c2
3891
3891
  if EXCEL
3892
- after Date.new(2008,12,25) do
3892
+ after Date.new(2009,1,6) do
3893
3893
  local_only do
3894
3894
  expected = ['Supermodel X','T6','Shaun White','Jeremy','Custom',
3895
3895
  'Warhol','Twin','Malolo','Supermodel','Air','Elite',
@@ -3914,7 +3914,7 @@ Sheet 3:
3914
3914
  end
3915
3915
 
3916
3916
  def test_bug_c2_parseexcel
3917
- after Date.new(2008,12,11) do
3917
+ after Date.new(2009,1,10) do
3918
3918
  local_only do
3919
3919
  #-- this is OK
3920
3920
  @workbook = Spreadsheet::ParseExcel.parse(File.join('test',"problem.xls"))
@@ -3993,7 +3993,7 @@ Sheet 3:
3993
3993
 
3994
3994
  def test_compare_csv_excelx_excel
3995
3995
  if EXCELX
3996
- after Date.new(2008,12,10) do
3996
+ after Date.new(2008,12,30) do
3997
3997
  # parseexcel bug
3998
3998
  local_only do
3999
3999
  s1 = Excel.new(File.join("test","problem.xls"))
@@ -4015,7 +4015,7 @@ Sheet 3:
4015
4015
  end
4016
4016
 
4017
4017
  def test_problemx_csv_imported
4018
- after Date.new(2008,12,26) do
4018
+ after Date.new(2009,1,6) do
4019
4019
  if EXCEL
4020
4020
  local_only do
4021
4021
  # wieder eingelesene CSV-Datei aus obigem Test
@@ -4164,24 +4164,24 @@ Sheet 3:
4164
4164
  end
4165
4165
 
4166
4166
  def test_open_from_uri
4167
- if ONLINE
4168
- if OPENOFFICE
4169
- assert_raises(RuntimeError) {
4170
- oo = Openoffice.new("http://gibbsnichtdomainxxxxx.com/file.ods")
4171
- }
4172
- end
4173
- if EXCEL
4174
- assert_raises(RuntimeError) {
4175
- oo = Excel.new("http://gibbsnichtdomainxxxxx.com/file.xls")
4176
- }
4177
- end
4178
- if EXCELX
4179
- assert_raises(RuntimeError) {
4180
- oo = Excelx.new("http://gibbsnichtdomainxxxxx.com/file.xlsx")
4181
- }
4182
- end
4167
+ if ONLINE
4168
+ if OPENOFFICE
4169
+ assert_raises(RuntimeError) {
4170
+ oo = Openoffice.new("http://gibbsnichtdomainxxxxx.com/file.ods")
4171
+ }
4183
4172
  end
4173
+ if EXCEL
4174
+ assert_raises(RuntimeError) {
4175
+ oo = Excel.new("http://gibbsnichtdomainxxxxx.com/file.xls")
4176
+ }
4177
+ end
4178
+ if EXCELX
4179
+ assert_raises(RuntimeError) {
4180
+ oo = Excelx.new("http://gibbsnichtdomainxxxxx.com/file.xlsx")
4181
+ }
4184
4182
  end
4183
+ end
4184
+ end
4185
4185
 
4186
4186
  def test_bug_last_row_excel
4187
4187
  if EXCEL
@@ -4369,7 +4369,7 @@ Sheet 3:
4369
4369
 
4370
4370
  def test_possible_bug_snowboard_cells
4371
4371
  local_only do
4372
- after Date.new(2008,12,26) do
4372
+ after Date.new(2009,1,6) do
4373
4373
  # warten auf Bugfix in parseexcel
4374
4374
  if EXCEL
4375
4375
  ex = Excel.new(File.join('test','problem.xls'))
@@ -4697,24 +4697,26 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
4697
4697
  def test_huge_table_timing_10_000_openoffice
4698
4698
  after Date.new(2009,1,1) do
4699
4699
  if OPENOFFICE
4700
- assert_nothing_raised(Timeout::Error) {
4701
- Timeout::timeout(3.minutes) do |timeout_length|
4702
- oo = Openoffice.new("/home/tp/ruby-test/too-testing/speedtest_10000.ods")
4703
- # process every cell
4704
- sum = 0
4705
- oo.sheets.each {|sheet|
4706
- oo.default_sheet = sheet
4707
- for row in oo.first_row..oo.last_row do
4708
- for col in oo.first_column..oo.last_column do
4709
- c = oo.cell(row,col)
4710
- sum += c.length if c
4700
+ if LONG_RUN
4701
+ assert_nothing_raised(Timeout::Error) {
4702
+ Timeout::timeout(3.minutes) do |timeout_length|
4703
+ oo = Openoffice.new("/home/tp/ruby-test/too-testing/speedtest_10000.ods")
4704
+ # process every cell
4705
+ sum = 0
4706
+ oo.sheets.each {|sheet|
4707
+ oo.default_sheet = sheet
4708
+ for row in oo.first_row..oo.last_row do
4709
+ for col in oo.first_column..oo.last_column do
4710
+ c = oo.cell(row,col)
4711
+ sum += c.length if c
4712
+ end
4711
4713
  end
4712
- end
4713
- p sum
4714
- assert sum > 0
4715
- }
4716
- end
4717
- }
4714
+ p sum
4715
+ assert sum > 0
4716
+ }
4717
+ end
4718
+ }
4719
+ end
4718
4720
  end
4719
4721
  end
4720
4722
  end
@@ -4722,24 +4724,26 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
4722
4724
  def test_huge_table_timing_10_000_excel
4723
4725
  after Date.new(2009,1,1) do
4724
4726
  if EXCEL
4725
- assert_nothing_raised(Timeout::Error) {
4726
- Timeout::timeout(3.minutes) do |timeout_length|
4727
- oo = Excel.new("/home/tp/ruby-test/too-testing/speedtest_10000.xls")
4728
- # process every cell
4729
- sum = 0
4730
- oo.sheets.each {|sheet|
4731
- oo.default_sheet = sheet
4732
- for row in oo.first_row..oo.last_row do
4733
- for col in oo.first_column..oo.last_column do
4734
- c = oo.cell(row,col)
4735
- sum += c.length if c
4727
+ if LONG_RUN
4728
+ assert_nothing_raised(Timeout::Error) {
4729
+ Timeout::timeout(3.minutes) do |timeout_length|
4730
+ oo = Excel.new("/home/tp/ruby-test/too-testing/speedtest_10000.xls")
4731
+ # process every cell
4732
+ sum = 0
4733
+ oo.sheets.each {|sheet|
4734
+ oo.default_sheet = sheet
4735
+ for row in oo.first_row..oo.last_row do
4736
+ for col in oo.first_column..oo.last_column do
4737
+ c = oo.cell(row,col)
4738
+ sum += c.length if c
4739
+ end
4736
4740
  end
4737
- end
4738
- p sum
4739
- assert sum > 0
4740
- }
4741
- end
4742
- }
4741
+ p sum
4742
+ assert sum > 0
4743
+ }
4744
+ end
4745
+ }
4746
+ end
4743
4747
  end
4744
4748
  end
4745
4749
  end
@@ -4747,24 +4751,26 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
4747
4751
  def test_huge_table_timing_10_000_google
4748
4752
  after Date.new(2009,1,1) do
4749
4753
  if GOOGLE
4750
- assert_nothing_raised(Timeout::Error) {
4751
- Timeout::timeout(3.minutes) do |timeout_length|
4752
- oo = Excel.new(key_of("/home/tp/ruby-test/too-testing/speedtest_10000.xls"))
4753
- # process every cell
4754
- sum = 0
4755
- oo.sheets.each {|sheet|
4756
- oo.default_sheet = sheet
4757
- for row in oo.first_row..oo.last_row do
4758
- for col in oo.first_column..oo.last_column do
4759
- c = oo.cell(row,col)
4760
- sum += c.length if c
4754
+ if LONG_RUN
4755
+ assert_nothing_raised(Timeout::Error) {
4756
+ Timeout::timeout(3.minutes) do |timeout_length|
4757
+ oo = Excel.new(key_of("/home/tp/ruby-test/too-testing/speedtest_10000.xls"))
4758
+ # process every cell
4759
+ sum = 0
4760
+ oo.sheets.each {|sheet|
4761
+ oo.default_sheet = sheet
4762
+ for row in oo.first_row..oo.last_row do
4763
+ for col in oo.first_column..oo.last_column do
4764
+ c = oo.cell(row,col)
4765
+ sum += c.length if c
4766
+ end
4761
4767
  end
4762
- end
4763
- p sum
4764
- assert sum > 0
4765
- }
4766
- end
4767
- }
4768
+ p sum
4769
+ assert sum > 0
4770
+ }
4771
+ end
4772
+ }
4773
+ end
4768
4774
  end
4769
4775
  end
4770
4776
  end
@@ -4772,26 +4778,56 @@ This attached file is the newer format of Microsoft Excel (.xlsx).
4772
4778
  def test_huge_table_timing_10_000_excelx
4773
4779
  after Date.new(2009,1,1) do
4774
4780
  if EXCELX
4775
- assert_nothing_raised(Timeout::Error) {
4776
- Timeout::timeout(3.minutes) do |timeout_length|
4777
- oo = Excelx.new("/home/tp/ruby-test/too-testing/speedtest_10000.xlsx")
4778
- # process every cell
4779
- sum = 0
4780
- oo.sheets.each {|sheet|
4781
- oo.default_sheet = sheet
4782
- for row in oo.first_row..oo.last_row do
4783
- for col in oo.first_column..oo.last_column do
4784
- c = oo.cell(row,col)
4785
- sum += c.length if c
4781
+ if LONG_RUN
4782
+ assert_nothing_raised(Timeout::Error) {
4783
+ Timeout::timeout(3.minutes) do |timeout_length|
4784
+ oo = Excelx.new("/home/tp/ruby-test/too-testing/speedtest_10000.xlsx")
4785
+ # process every cell
4786
+ sum = 0
4787
+ oo.sheets.each {|sheet|
4788
+ oo.default_sheet = sheet
4789
+ for row in oo.first_row..oo.last_row do
4790
+ for col in oo.first_column..oo.last_column do
4791
+ c = oo.cell(row,col)
4792
+ sum += c.length if c
4793
+ end
4786
4794
  end
4787
- end
4788
- p sum
4789
- assert sum > 0
4790
- }
4791
- end
4792
- }
4795
+ p sum
4796
+ assert sum > 0
4797
+ }
4798
+ end
4799
+ }
4800
+ end
4793
4801
  end
4794
4802
  end
4795
4803
  end
4796
4804
 
4805
+ # Eine Spreadsheetdatei wird nicht als Dateiname sondern direkt als Dokument
4806
+ # geoeffnettest_problemx_csv_imported
4807
+ def test_from_stream_openoffice
4808
+ after Date.new(2009,1,6) do
4809
+ if OPENOFFICE
4810
+ filecontent = nil
4811
+ File.open(File.join("test","numbers1.ods")) do |f|
4812
+ filecontent = f.read
4813
+ p filecontent.class
4814
+ p filecontent.size
4815
+ #p filecontent
4816
+ assert filecontent.size > 0
4817
+ # #stream macht das gleiche wie #new liest abe aus Stream anstatt Datei
4818
+ oo = Openoffice.stream(filecontent)
4819
+ end
4820
+ #oo = Openoffice.open()
4821
+ end
4822
+ end
4823
+ end
4824
+
4825
+
4826
+ def test_bug_encoding_exported_from_google
4827
+ if EXCEL
4828
+ xl = Excel.new(File.join("test","numbers1_from_google.xls"))
4829
+ xl.default_sheet = xl.sheets.first
4830
+ assert_equal 'test', xl.cell(2,'F')
4831
+ end
4832
+ end
4797
4833
  end # class
@@ -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">1.2.1</a>
36
+ <a href="http://rubyforge.org/projects/roo" class="numbers">1.2.2</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
  <p>This gem allows you to access the content of</p>
@@ -155,10 +155,12 @@ returned:</p>
155
155
  <li>:percentage</li>
156
156
  <li>:formula</li>
157
157
  <li>:time</li>
158
+ <li>:datetime</li>
158
159
  </ul>
159
160
  <p>Numeric values are returned as type :float, the return value is a Ruby Float object (note: integer values like 42 are returned as 42.0 &#8211; not as a Fixnum 42 object).</p>
160
161
  <p>String values are returned as type :string and Ruby String object.</p>
161
162
  <p>Date values are returned as type :date and as a Ruby Date object.</p>
163
+ <p>Datetime values are returned as type :datetime and as a Ruby DateTime object.</p>
162
164
  <p>Percentage are return as type :percentage and as Ruby Float object with the <br />
163
165
  range from 0.0 to 1.0.</p>
164
166
  <p>Formulas are returned as type :formula &#8211; the value of the cell is the computed<br />
@@ -372,7 +374,7 @@ h2. Feature Requests / Bugs</p>
372
374
  <li>Thanks to Ryan Waldron for a bug-fix patch in Google set_value</li>
373
375
  </ul>
374
376
  <p class="coda">
375
- <a href="mailto:thopre@gmail.com">Thomas Preymesser</a>, 26th September 2008<br>
377
+ <a href="mailto:thopre@gmail.com">Thomas Preymesser</a>, 8th December 2008<br>
376
378
  Theme extended from <a href="http://rb2js.rubyforge.org/">Paul Battley</a>
377
379
  </p>
378
380
  </div>
@@ -146,7 +146,7 @@ String values are returned as type :string and Ruby String object.
146
146
 
147
147
  Date values are returned as type :date and as a Ruby Date object.
148
148
 
149
- Datetime values are returned as type :datedate and as a Ruby DateTime object.
149
+ Datetime values are returned as type :datetime and as a Ruby DateTime object.
150
150
 
151
151
  Percentage are return as type :percentage and as Ruby Float object with the
152
152
  range from 0.0 to 1.0.
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: 1.2.2
4
+ version: 1.2.3
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-12-08 00:00:00 +01:00
12
+ date: 2009-01-05 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -138,6 +138,7 @@ files:
138
138
  - test/emptysheets.xls
139
139
  - test/datetime.ods
140
140
  - test/datetime.xls
141
+ - test/datetime.xlsx
141
142
  - website/index.html
142
143
  - website/index.txt
143
144
  - website/javascripts/rounded_corners_lite.inc.js