roo 0.5.2 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/History.txt CHANGED
@@ -1,3 +1,6 @@
1
+ == 0.5.3 2007-08-26
2
+ * Excel: can now read zip-ed files
3
+ * Excel: can now read files from http://-URL over the net
1
4
  == 0.5.2 2007-08-26
2
5
  * 1 bugfix
3
6
  * excel: removed debugging output
data/Manifest.txt CHANGED
@@ -24,6 +24,7 @@ test/formula.xls
24
24
  test/only_one_sheet.ods
25
25
  test/only_one_sheet.xls
26
26
  test/bode-v1.xls.zip
27
+ test/bode-v1.ods.zip
27
28
  website/index.html
28
29
  website/index.txt
29
30
  website/javascripts/rounded_corners_lite.inc.js
data/README.txt CHANGED
@@ -3,3 +3,4 @@ README for roo
3
3
 
4
4
  see http://roo.rubyforge.org for examples
5
5
 
6
+ PLEASE DON'T USE THE Google class - its only experimental.
data/lib/roo/excel.rb CHANGED
@@ -25,12 +25,6 @@ class Excel < Openoffice
25
25
  @first_row = @last_row = @first_column = @last_column = nil
26
26
  end
27
27
 
28
- def remove_tmp
29
- if File.exists?(@tmpdir)
30
- FileUtils::rm_r(@tmpdir)
31
- end
32
- end
33
-
34
28
  def sheets
35
29
  #if DateTime.now < Date.new(2007,6,10)
36
30
  # return ["Tabelle1", "Name of Sheet 2", "Sheet3"]
@@ -163,37 +157,6 @@ class Excel < Openoffice
163
157
  false
164
158
  end
165
159
 
166
- def open_from_uri(uri)
167
- require 'open-uri' ;
168
-
169
- script = nil ;
170
- result = nil ;
171
- #uri = "/home/tp/ruby-test/roo/test/numbers1.xls"
172
-
173
- #begin ;
174
- # result = open(page) {|w| script = w.readlines } ;
175
- #rescue => e ;
176
- # puts "e=#{e}, e.class=#{e.class}" ;
177
- # result = [] ;
178
- #end ;
179
- #
180
- # puts "result class=#{result.class}, count=#{result.length}" ; #,
181
- # data=#{result}" ;
182
- # puts "result[0] =>#{result[0].chomp}<=" if result[0] ;
183
-
184
- tempfilename = File.join(@tmpdir, File.basename(uri))
185
- f = File.open( File.join(@tmpdir, File.basename(uri)),"w")
186
- begin
187
- open(uri) do |net|
188
- f.write(net.read)
189
- end
190
- rescue
191
- raise "could not open #{uri}"
192
- end
193
- f.close
194
- File.join(@tmpdir, File.basename(uri))
195
- end
196
-
197
160
  private
198
161
 
199
162
  # check if default_sheet was set
@@ -242,38 +205,4 @@ private
242
205
  raise StandardError, "sheet '#{name}' not found"
243
206
  end
244
207
 
245
- def process_zipfile(zip, path='')
246
- ret=nil
247
- if zip.file.file? path
248
- #puts %{#{path}: "#{zip.read(path)}"}
249
- puts %{#{path}: }
250
- # extract and return filename
251
- @tmpdir = "oo_"+$$.to_s
252
- unless File.exists?(@tmpdir)
253
- FileUtils::mkdir(@tmpdir)
254
- end
255
- #file = File.new(File.join(@tmpdir, path))
256
- file = File.open(File.join(@tmpdir, path),"w")
257
- file.write(zip.read(path))
258
- file.close
259
- return File.join(@tmpdir, path)
260
- else
261
- unless path.empty?
262
- path += '/'
263
- puts path
264
- end
265
- zip.dir.foreach(path) do |filename|
266
- ret = process_zipfile(zip, path + filename)
267
- end
268
- end
269
- ret
270
- end
271
-
272
- def unzip(filename)
273
- ret = nil
274
- Zip::ZipFile.open(filename) do |zip|
275
- ret = process_zipfile zip
276
- end
277
- ret
278
- end
279
208
  end
@@ -13,10 +13,15 @@ class Openoffice
13
13
 
14
14
  @@nr = 0
15
15
 
16
- # initialization and opening of a spreasheet file
17
- # file will be created if 'create' is true
18
- # and the file does not exist
16
+ # initialization and opening of a spreadsheet file
17
+ # values for packed: :zip
19
18
  def initialize(filename, packed=nil) #, create = false)
19
+ @tmpdir = "oo_"+$$.to_s
20
+ unless File.exists?(@tmpdir)
21
+ FileUtils::mkdir(@tmpdir)
22
+ end
23
+ filename = open_from_uri(filename) if filename[0,7] == "http://"
24
+ filename = unzip(filename) if packed and packed == :zip
20
25
  if filename[-4..-1] != ".ods"
21
26
  warn "are you sure, this is an openoffice file?"
22
27
  end
@@ -25,10 +30,6 @@ class Openoffice
25
30
  #end
26
31
  @cells_read = false
27
32
  @filename = filename
28
- @tmpdir = "oo_"+$$.to_s
29
- unless File.exists?(@tmpdir)
30
- FileUtils::mkdir(@tmpdir)
31
- end
32
33
  @@nr += 1
33
34
  @file_nr = @@nr
34
35
  extract_content
@@ -60,7 +61,7 @@ class Openoffice
60
61
  # the empty files in an openoffice zip-file
61
62
  load 'base64include.rb'
62
63
  # puts @@empty_spreadsheet
63
- f = File.open(filename,'w')
64
+ f = File.open(filename,'wb')
64
65
  f.print(Base64.decode64(@@empty_spreadsheet))
65
66
  f.close
66
67
  end
@@ -154,6 +155,12 @@ class Openoffice
154
155
  end
155
156
  end
156
157
 
158
+ def remove_tmp
159
+ if File.exists?(@tmpdir)
160
+ FileUtils::rm_r(@tmpdir)
161
+ end
162
+ end
163
+
157
164
  # returns an array of sheet names in the spreadsheet
158
165
  def sheets
159
166
  return_sheets = []
@@ -378,6 +385,39 @@ class Openoffice
378
385
  result
379
386
  end
380
387
 
388
+ protected
389
+
390
+ def process_zipfile_packed(zip, path='')
391
+ ret=nil
392
+ if zip.file.file? path
393
+ # extract and return filename
394
+ @tmpdir = "oo_"+$$.to_s
395
+ unless File.exists?(@tmpdir)
396
+ FileUtils::mkdir(@tmpdir)
397
+ end
398
+ file = File.open(File.join(@tmpdir, path),"wb")
399
+ file.write(zip.read(path))
400
+ file.close
401
+ return File.join(@tmpdir, path)
402
+ else
403
+ unless path.empty?
404
+ path += '/'
405
+ end
406
+ zip.dir.foreach(path) do |filename|
407
+ ret = process_zipfile_packed(zip, path + filename)
408
+ end
409
+ end
410
+ ret
411
+ end
412
+
413
+ def unzip(filename)
414
+ ret = nil
415
+ Zip::ZipFile.open(filename) do |zip|
416
+ ret = process_zipfile_packed zip
417
+ end
418
+ ret
419
+ end
420
+
381
421
  private
382
422
  # read the version of the OO-Version
383
423
  def oo_version
@@ -516,7 +556,7 @@ private
516
556
  def process_zipfile(zip, path='')
517
557
  if zip.file.file? path
518
558
  if path == "content.xml"
519
- open(@tmpdir+'/'+@file_nr.to_s+'_roo_content.xml','w') {|f|
559
+ open(@tmpdir+'/'+@file_nr.to_s+'_roo_content.xml','wb') {|f|
520
560
  f << zip.read(path)
521
561
  }
522
562
  end
@@ -596,4 +636,20 @@ private
596
636
  def Openoffice.oo_type_2_roo_type(ootype)
597
637
  return A_ROO_TYPE[ootype]
598
638
  end
639
+
640
+
641
+ def open_from_uri(uri)
642
+ require 'open-uri' ;
643
+ tempfilename = File.join(@tmpdir, File.basename(uri))
644
+ f = File.open(tempfilename,"wb")
645
+ begin
646
+ open(uri) do |net|
647
+ f.write(net.read)
648
+ end
649
+ rescue
650
+ raise "could not open #{uri}"
651
+ end
652
+ f.close
653
+ File.join(@tmpdir, File.basename(uri))
654
+ end
599
655
  end # class
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 = 5
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
Binary file
data/test/test_roo.rb CHANGED
@@ -1057,17 +1057,40 @@ class TestRoo < Test::Unit::TestCase
1057
1057
 
1058
1058
  end
1059
1059
 
1060
- def test_open_from_uri_and_zipped
1061
- url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
1062
- excel = Excel.new(url, :zip)
1063
- assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1064
- excel.remove_tmp # don't forget to remove the temporary files
1060
+ def test_excel_open_from_uri_and_zipped
1061
+ after Date.new(2007,8,30) do
1062
+ url = 'http://stiny-leonhard.de/bode-v1.xls.zip'
1063
+ excel = Excel.new(url, :zip)
1064
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1065
+ excel.remove_tmp # don't forget to remove the temporary files
1066
+ end
1065
1067
  end
1066
1068
 
1067
- def test_zipped
1068
- excel = Excel.new(File.join("test","bode-v1.xls.zip"), :zip)
1069
- assert excel
1070
- assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1071
- excel.remove_tmp # don't forget to remove the temporary files
1069
+ def test_openoffice_open_from_uri_and_zipped
1070
+ after Date.new(2007,8,30) do
1071
+ url = 'http://spazioinwind.libero.it/s2/rata.ods.zip'
1072
+ sheet = Openoffice.new(url, :zip)
1073
+ assert_equal 'ist "e" im Nenner von H(s)', sheet.cell('b', 5)
1074
+ sheet.remove_tmp # don't forget to remove the temporary files
1075
+ end
1076
+ end
1077
+
1078
+ def test_excel_zipped
1079
+ after Date.new(2007,8,30) do
1080
+ excel = Excel.new(File.join("test","bode-v1.xls.zip"), :zip)
1081
+ assert excel
1082
+ assert_equal 'ist "e" im Nenner von H(s)', excel.cell('b', 5)
1083
+ excel.remove_tmp # don't forget to remove the temporary files
1084
+ end
1085
+ end
1086
+
1087
+ def test_openoffice_zipped
1088
+ after Date.new(2007,8,10) do
1089
+ oo = Openoffice.new(File.join("test","bode-v1.ods.zip"), :zip)
1090
+ assert oo
1091
+ oo.default_sheet = oo.sheets.first
1092
+ assert_equal 'ist "e" im Nenner von H(s)', oo.cell('b', 5)
1093
+ oo.remove_tmp # don't forget to remove the temporary files
1094
+ end
1072
1095
  end
1073
1096
  end # class
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.5.2</a>
36
+ <a href="http://rubyforge.org/projects/roo" class="numbers">0.5.3</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
@@ -271,15 +271,17 @@ is the setting of the default-worksheet. OpenOffice uses the name of the workshe
271
271
  <h3>Accessing Spreadsheet over the Web</h3>
272
272
 
273
273
 
274
- You can even read excel-spreadsheets from a http-address:
274
+ You can even read openoffice or excel-spreadsheets from a http-address:
275
275
  <pre>
276
276
  <code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls").
277
+ oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods").
277
278
  </code>
278
279
  </pre>
279
280
 
280
281
  or a zipped file:
281
282
  <pre>
282
283
  <code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls.zip",:zip).
284
+ oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods.zip",:zip).
283
285
  </code>
284
286
  </pre>
285
287
 
data/website/index.txt CHANGED
@@ -172,15 +172,17 @@ Old .sxc OpenOffice files are currently not supported - please load these files
172
172
 
173
173
  h3. Accessing Spreadsheet over the Web
174
174
 
175
- You can even read excel-spreadsheets from a http-address:
175
+ You can even read openoffice or excel-spreadsheets from a http-address:
176
176
  <pre>
177
177
  <code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls").
178
+ oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods").
178
179
  </code>
179
180
  </pre>
180
181
 
181
182
  or a zipped file:
182
183
  <pre>
183
184
  <code>oo = Excel.new("http://www.somedomain.com/simple_spreadsheet.xls.zip",:zip).
185
+ oo = Openoffice.new("http://www.somedomain.com/simple_spreadsheet.ods.zip",:zip).
184
186
  </code>
185
187
  </pre>
186
188
 
metadata CHANGED
@@ -3,7 +3,7 @@ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: roo
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.5.2
6
+ version: 0.5.3
7
7
  date: 2007-08-26 00:00:00 +02:00
8
8
  summary: roo can access the contents of OpenOffice-Spreadsheets and Excel-Spreadsheets
9
9
  require_paths:
@@ -55,6 +55,7 @@ files:
55
55
  - test/only_one_sheet.ods
56
56
  - test/only_one_sheet.xls
57
57
  - test/bode-v1.xls.zip
58
+ - test/bode-v1.ods.zip
58
59
  - website/index.html
59
60
  - website/index.txt
60
61
  - website/javascripts/rounded_corners_lite.inc.js