roo 0.0.3 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,9 @@
1
+ == 0.1.0 2007-05-31
2
+
3
+ * 1 major enhancement:
4
+ * new methods first/last row/column
5
+ * new method officeversion
6
+
1
7
  == 0.0.3 2007-05-30
2
8
 
3
9
  * 1 minor enhancement:
@@ -4,6 +4,7 @@ require 'rexml/document'
4
4
  # require 'matrix'
5
5
  require 'fileutils'
6
6
  require 'zip/zipfilesystem'
7
+ require 'date'
7
8
 
8
9
  class Openoffice
9
10
 
@@ -19,7 +20,9 @@ class Openoffice
19
20
  @doc = REXML::Document.new file
20
21
  @cell = Hash.new
21
22
  @cell_type = Hash.new
22
- FileUtils::rm_r(@tmpdir)
23
+ if DateTime.now < Date.new(2007,6,1)
24
+ FileUtils::rm_r(@tmpdir)
25
+ end
23
26
  @default_sheet = nil
24
27
  end
25
28
 
@@ -54,26 +57,17 @@ class Openoffice
54
57
  # returns an array of sheets in the spreadsheet
55
58
  def sheets
56
59
  return_sheets = []
57
- # p valid_xml?(doc)
58
60
  oo_document_count = 0
59
61
  @doc.each_element do |oo_document|
60
62
  oo_document_count += 1
61
- #p oo_document
62
63
  oo_element_count = 0
63
64
  oo_document.each_element do |oo_element|
64
65
  oo_element_count += 1
65
- # p oo_element.name
66
66
  if oo_element.name == "body"
67
- # puts "Body gefunden "
68
67
  oo_element.each_element do |be|
69
- # p be.name
70
68
  if be.name == "spreadsheet"
71
69
  be.each_element do |se|
72
- # p se
73
70
  if se.name == "table"
74
- # puts "table gefunden"
75
- #se.each_element
76
- # p se.attributes['name']
77
71
  return_sheets << se.attributes['name']
78
72
  end
79
73
  end
@@ -81,9 +75,7 @@ class Openoffice
81
75
  end
82
76
  end
83
77
  end
84
- # puts oo_element_count.to_s+" oo_element_count "
85
78
  end
86
- # puts oo_document_count.to_s+" oo_document_count "
87
79
  return_sheets
88
80
  end
89
81
 
@@ -92,12 +84,14 @@ class Openoffice
92
84
  @default_sheet = s
93
85
  end
94
86
 
87
+ # version of the openoffice document
95
88
  def officeversion
96
89
  read_cells unless @cells_read
97
90
  @officeversion
98
91
  end
99
92
 
100
93
  def to_s
94
+ read_cells unless @cells_read
101
95
  @cell.inspect
102
96
  end
103
97
 
@@ -116,9 +110,69 @@ class Openoffice
116
110
  }
117
111
  result
118
112
  end
113
+
114
+ # returns the number of the last non-empty row
115
+ def last_row
116
+ read_cells unless @cells_read
117
+ result = 0
118
+ @cell.each_pair {|key,value|
119
+ y,x = key.split(',')
120
+ y = y.to_i
121
+ result = [result, y].max
122
+ }
123
+ result
124
+ end
125
+
126
+ # returns the number of the last non-empty column
127
+ def last_column
128
+ read_cells unless @cells_read
129
+ result = 0
130
+ @cell.each_pair {|key,value|
131
+ y,x = key.split(',')
132
+ x = x.to_i
133
+ result = [result, x].max
134
+ }
135
+ result
136
+ end
137
+
138
+ # returns the number of the first non-empty row
139
+ def first_row
140
+ read_cells unless @cells_read
141
+ result = 999_999 # more than a spreadsheet can hold
142
+ @cell.each_pair {|key,value|
143
+ y,x = key.split(',')
144
+ y = y.to_i
145
+ result = [result, y].min
146
+ }
147
+ result
148
+ end
149
+
150
+ # returns the number of the first non-empty column
151
+ def first_column
152
+ read_cells unless @cells_read
153
+ result = 999_999 # more than a spreadsheet can hold
154
+ @cell.each_pair {|key,value|
155
+ y,x = key.split(',')
156
+ x = x.to_i
157
+ result = [result, x].min
158
+ }
159
+ result
160
+ end
161
+
162
+ def first_column_as_letter
163
+ number_to_letter(first_column)
164
+ end
165
+
166
+ def last_column_as_letter
167
+ number_to_letter(last_column)
168
+ end
119
169
 
120
170
  private
121
171
 
172
+ def number_to_letter(n)
173
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"[n-1,1]
174
+ end
175
+
122
176
  # read all cells in the selected sheet
123
177
  def read_cells
124
178
  oo_document_count = 0
@@ -150,6 +204,10 @@ private
150
204
  rep = te.attributes["number-columns-repeated"]
151
205
  # p "rep = "+rep.to_s
152
206
  elsif te.name == "table-row"
207
+ if te.attributes['number-rows-repeated']
208
+ skip_y = te.attributes['number-rows-repeated'].to_i
209
+ y = y + skip_y - 1 # minus 1 because this line will be counted as a line element
210
+ end
153
211
  # p te
154
212
  te.each_element do |tr|
155
213
  # p tr
@@ -1,8 +1,8 @@
1
1
  module Roo #:nodoc:
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 0
5
- TINY = 3
4
+ MINOR = 1
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -76,4 +76,39 @@ class TestRoo < Test::Unit::TestCase
76
76
  assert_equal [41.0,42.0,43.0,44.0,45.0], oo.row(12)
77
77
  end
78
78
 
79
+ def test_last_row
80
+ oo = Openoffice.new("test/numbers1.ods")
81
+ oo.default_sheet = oo.sheets.first
82
+ assert_equal 18, oo.last_row
83
+ end
84
+
85
+ def test_last_column
86
+ oo = Openoffice.new("test/numbers1.ods")
87
+ oo.default_sheet = oo.sheets.first
88
+ assert_equal 7, oo.last_column
89
+ end
90
+
91
+ def test_last_column_as_letter
92
+ oo = Openoffice.new("test/numbers1.ods")
93
+ oo.default_sheet = oo.sheets.first
94
+ assert_equal 'G', oo.last_column_as_letter
95
+ end
96
+
97
+ def test_first_row
98
+ oo = Openoffice.new("test/numbers1.ods")
99
+ oo.default_sheet = oo.sheets.first
100
+ assert_equal 1, oo.first_row
101
+ end
102
+
103
+ def test_first_column
104
+ oo = Openoffice.new("test/numbers1.ods")
105
+ oo.default_sheet = oo.sheets.first
106
+ assert_equal 1, oo.first_column
107
+ end
108
+
109
+ def test_first_column_as_letter
110
+ oo = Openoffice.new("test/numbers1.ods")
111
+ oo.default_sheet = oo.sheets.first
112
+ assert_equal 'A', oo.first_column_as_letter
113
+ end
79
114
  end
@@ -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.0.3</a>
36
+ <a href="http://rubyforge.org/projects/roo" class="numbers">0.1.0</a>
37
37
  </div>
38
38
  <h2>What</h2>
39
39
 
metadata CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.0
3
3
  specification_version: 1
4
4
  name: roo
5
5
  version: !ruby/object:Gem::Version
6
- version: 0.0.3
7
- date: 2007-05-30 00:00:00 +02:00
6
+ version: 0.1.0
7
+ date: 2007-05-31 00:00:00 +02:00
8
8
  summary: roo can access the contents of OpenOffice-Spreadsheets
9
9
  require_paths:
10
10
  - lib