parseexcel 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Spreadsheet::ParseExcel -- Extract Data from an Excel File
4
+ # Copyright (C) 2003 ywesee -- intellectual capital connected
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
21
+ # hwyss@ywesee.com
22
+ #
23
+ # TestWorkbook -- Spreadsheet::ParseExcel -- 10.06.2003 -- hwyss@ywesee.com
24
+
25
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
26
+
27
+ require 'test/unit'
28
+ require 'parseexcel/workbook'
29
+
30
+ module Spreadsheet
31
+ module ParseExcel
32
+ class Workbook
33
+ attr_accessor :worksheets, :formats
34
+ end
35
+ end
36
+ end
37
+
38
+ class TestWorkbook < Test::Unit::TestCase
39
+ def setup
40
+ @workbook = Spreadsheet::ParseExcel::Workbook.new
41
+ end
42
+ def test_format
43
+ @workbook.format = :foo
44
+ @workbook.formats = [:bar, :baz]
45
+ assert_equal(:foo, @workbook.format)
46
+ assert_equal(:bar, @workbook.format(0))
47
+ assert_equal(:baz, @workbook.format(1))
48
+ end
49
+ def test_sheet_count
50
+ assert_equal(0, @workbook.sheet_count)
51
+ @workbook.worksheets = [:foo, :bar]
52
+ assert_equal(2, @workbook.sheet_count)
53
+ @workbook.worksheets = [:foo]
54
+ assert_equal(1, @workbook.sheet_count)
55
+ end
56
+ def test_worksheet
57
+ @workbook.worksheets = []
58
+ sheet0 = @workbook.worksheet(0)
59
+ assert_instance_of(Spreadsheet::ParseExcel::Worksheet, sheet0)
60
+ assert_equal([sheet0], @workbook.worksheets)
61
+ sheet1 = @workbook.worksheet(1)
62
+ assert_instance_of(Spreadsheet::ParseExcel::Worksheet, sheet0)
63
+ assert_not_equal(sheet0, sheet1)
64
+ assert_equal([sheet0, sheet1], @workbook.worksheets)
65
+ sheet2 = @workbook.worksheet(0)
66
+ assert_instance_of(Spreadsheet::ParseExcel::Worksheet, sheet2)
67
+ assert_equal(sheet0, sheet2)
68
+ assert_equal([sheet0, sheet1], @workbook.worksheets)
69
+ end
70
+ end
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env ruby
2
+ #
3
+ # Spreadsheet::ParseExcel -- Extract Data from an Excel File
4
+ # Copyright (C) 2003 ywesee -- intellectual capital connected
5
+ #
6
+ # This library is free software; you can redistribute it and/or
7
+ # modify it under the terms of the GNU Lesser General Public
8
+ # License as published by the Free Software Foundation; either
9
+ # version 2.1 of the License, or (at your option) any later version.
10
+ #
11
+ # This library is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14
+ # Lesser General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Lesser General Public
17
+ # License along with this library; if not, write to the Free Software
18
+ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
+ #
20
+ # ywesee - intellectual capital connected, Winterthurerstrasse 52, CH-8006 Z�rich, Switzerland
21
+ # hwyss@ywesee.com
22
+ #
23
+ # TestWorksheet -- Spreadsheet::ParseExcel -- 10.06.2003 -- hwyss@ywesee.com
24
+
25
+ $: << File.expand_path("../lib", File.dirname(__FILE__))
26
+
27
+ require 'test/unit'
28
+ require 'parseexcel/worksheet'
29
+ require 'parseexcel/parser'
30
+
31
+ module Spreadsheet
32
+ module ParseExcel
33
+ class Worksheet
34
+ attr_accessor :cells
35
+ attr_reader :min_col, :max_col, :min_row, :max_row, :row_heights
36
+ end
37
+ end
38
+ end
39
+ class StubWorksheetWorkbook
40
+ attr_accessor :flg_1904
41
+ end
42
+
43
+ class TestWorksheet < Test::Unit::TestCase
44
+ def setup
45
+ @sheet = Spreadsheet::ParseExcel::Worksheet.new
46
+ end
47
+ def test_add_cell
48
+ @sheet.add_cell(0,0,'foo')
49
+ assert_equal([['foo']], @sheet.cells)
50
+ assert_equal(0, @sheet.min_col)
51
+ assert_equal(0, @sheet.max_col)
52
+ assert_equal(0, @sheet.min_row)
53
+ assert_equal(0, @sheet.max_row)
54
+ @sheet.add_cell(1,2,'bar')
55
+ assert_equal([['foo'],[nil,nil,'bar']], @sheet.cells)
56
+ assert_equal(0, @sheet.min_col)
57
+ assert_equal(2, @sheet.max_col)
58
+ assert_equal(0, @sheet.min_row)
59
+ assert_equal(1, @sheet.max_row)
60
+ end
61
+ def test_cell
62
+ @sheet.cells = [['foo'],[nil,nil,'bar']]
63
+ assert_equal('foo', @sheet.cell(0,0))
64
+ assert_equal('bar', @sheet.cell(1,2))
65
+ assert_instance_of(Spreadsheet::ParseExcel::Worksheet::Cell, @sheet.cell(1,0))
66
+ end
67
+ def test_row
68
+ @sheet.cells = [['foo'],[nil,nil,'bar']]
69
+ assert_equal(['foo'], @sheet.row(0))
70
+ assert_equal([nil, nil, 'bar'], @sheet.row(1))
71
+ assert_equal([], @sheet.row(2))
72
+ end
73
+ def test_set_dimensions1
74
+ assert_equal(nil, @sheet.min_col)
75
+ assert_equal(nil, @sheet.max_col)
76
+ assert_equal(nil, @sheet.min_row)
77
+ assert_equal(nil, @sheet.max_row)
78
+ @sheet.set_dimensions(1,1)
79
+ assert_equal(1, @sheet.min_col)
80
+ assert_equal(1, @sheet.max_col)
81
+ assert_equal(1, @sheet.min_row)
82
+ assert_equal(1, @sheet.max_row)
83
+ @sheet.set_dimensions(0,2)
84
+ assert_equal(1, @sheet.min_col)
85
+ assert_equal(2, @sheet.max_col)
86
+ assert_equal(0, @sheet.min_row)
87
+ assert_equal(1, @sheet.max_row)
88
+ end
89
+ def test_set_dimensions2
90
+ assert_equal(nil, @sheet.min_col)
91
+ assert_equal(nil, @sheet.max_col)
92
+ assert_equal(nil, @sheet.min_row)
93
+ assert_equal(nil, @sheet.max_row)
94
+ @sheet.set_dimensions(1,1,2)
95
+ assert_equal(1, @sheet.min_col)
96
+ assert_equal(2, @sheet.max_col)
97
+ assert_equal(1, @sheet.min_row)
98
+ assert_equal(1, @sheet.max_row)
99
+ @sheet.set_dimensions(0,2)
100
+ assert_equal(1, @sheet.min_col)
101
+ assert_equal(2, @sheet.max_col)
102
+ assert_equal(0, @sheet.min_row)
103
+ assert_equal(1, @sheet.max_row)
104
+ end
105
+ def test_set_row_height
106
+ @sheet.set_row_height(2, 0)
107
+ assert_equal([nil, nil, 0], @sheet.row_heights)
108
+ @sheet.set_row_height(1, 4)
109
+ assert_equal([nil, 4, 0], @sheet.row_heights)
110
+ end
111
+ def test_enumerable
112
+ @sheet.cells = [[1],[2],[3],[4],[5]]
113
+ result = @sheet.collect { |row| row.first }
114
+ assert_equal([1,2,3,4,5], result)
115
+ result = []
116
+ @sheet.each(2) { |row|
117
+ result << row.first
118
+ }
119
+ assert_equal([3,4,5], result)
120
+ end
121
+ end
122
+ class TestCell < Test::Unit::TestCase
123
+ def setup
124
+ @cell = Spreadsheet::ParseExcel::Worksheet::Cell.new
125
+ end
126
+ def test_to_s
127
+ @cell.value = 'foo'
128
+ assert_equal('foo', @cell.to_s)
129
+ @cell.value = 5
130
+ assert_equal('5', @cell.to_s)
131
+ end
132
+ def test_to_i
133
+ @cell.value = 'foo'
134
+ assert_equal(0, @cell.to_i)
135
+ @cell.value = 5
136
+ assert_equal(5, @cell.to_i)
137
+ @cell.value = '123'
138
+ assert_equal(123, @cell.to_i)
139
+ end
140
+ def test_datetime
141
+ @cell.value = 30025
142
+ @cell.book = StubWorksheetWorkbook.new
143
+ dt = @cell.datetime
144
+ assert_equal(1982, dt.year)
145
+ assert_equal(3, dt.month)
146
+ assert_equal(15, dt.day)
147
+ assert_equal(0, dt.hour)
148
+ assert_equal(0, dt.min)
149
+ assert_equal(0, dt.sec)
150
+ assert_equal(0, dt.msec)
151
+ end
152
+ def test_datetime2
153
+ @cell.value = nil
154
+ @cell.book = StubWorksheetWorkbook.new
155
+ assert_nothing_raised {
156
+ @cell.datetime
157
+ }
158
+ end
159
+ def test_file_dates
160
+ source = File.expand_path('data/dates.xls', File.dirname(__FILE__))
161
+ parser = Spreadsheet::ParseExcel::Parser.new
162
+ book = parser.parse(source)
163
+ sheet = book.worksheet(0)
164
+ expected = Date.new(1900,3,1)
165
+ result = sheet.cell(0,0).date
166
+ assert_equal(expected, result, "Expected #{expected} but was #{result}")
167
+ expected = Date.new(1950,1,1)
168
+ result = sheet.cell(1,0).date
169
+ assert_equal(expected, result, "Expected #{expected} but was #{result}")
170
+ expected = Date.new(1984,3,1)
171
+ result = sheet.cell(2,0).date
172
+ assert_equal(expected, result, "Expected #{expected} but was #{result}")
173
+ expected = Date.new(2000,3,1)
174
+ result = sheet.cell(3,0).date
175
+ assert_equal(expected, result, "Expected #{expected} but was #{result}")
176
+ expected = Date.new(2100,3,1)
177
+ result = sheet.cell(4,0).date
178
+ assert_equal(expected, result, "Expected #{expected} but was #{result}")
179
+ expected = Date.new(2003,3,1)
180
+ result = sheet.cell(5,0).date
181
+ assert_equal(expected, result, "Expected #{expected} but was #{result}")
182
+ end
183
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.8.11
3
+ specification_version: 1
4
+ name: parseexcel
5
+ version: !ruby/object:Gem::Version
6
+ version: 0.5.1
7
+ date: 2006-06-06 00:00:00 +02:00
8
+ summary: Reads Excel documents on any platform
9
+ require_paths:
10
+ - lib
11
+ email: hannes.wyss@gmail.com
12
+ homepage: http://rubyspreadsheet.sf.net
13
+ rubyforge_project:
14
+ description: Reads Excel documents on any platform
15
+ autorequire:
16
+ default_executable:
17
+ bindir: bin
18
+ has_rdoc: false
19
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
20
+ requirements:
21
+ - - ">"
22
+ - !ruby/object:Gem::Version
23
+ version: 0.0.0
24
+ version:
25
+ platform: ruby
26
+ signing_key:
27
+ cert_chain:
28
+ authors:
29
+ - Hannes Wyss
30
+ files:
31
+ - lib/parseexcel
32
+ - lib/parseexcel/olestorage.rb
33
+ - lib/parseexcel/parseexcel.rb
34
+ - lib/parseexcel/worksheet.rb
35
+ - lib/parseexcel/format.rb
36
+ - lib/parseexcel/workbook.rb
37
+ - lib/parseexcel/parser.rb
38
+ - test/data
39
+ - test/suite.rb
40
+ - test/test_format.rb
41
+ - test/test_olestorage.rb
42
+ - test/test_workbook.rb
43
+ - test/test_worksheet.rb
44
+ - test/test_parser.rb
45
+ - test/data/bar.xls
46
+ - test/data/dates.xls
47
+ - test/data/foo.xls
48
+ - test/data/image.xls
49
+ - test/data/nil.xls
50
+ - test/data/umlaut.5.0.xls
51
+ - test/data/umlaut.biff8.xls
52
+ - test/data/float.5.0.xls
53
+ - test/data/float.xls
54
+ - test/data/uncompressed.str.xls
55
+ - test/data/comment.xls
56
+ - test/data/comment.5.0.xls
57
+ - test/data/annotation.xls
58
+ - README
59
+ test_files:
60
+ - test/suite.rb
61
+ rdoc_options: []
62
+
63
+ extra_rdoc_files:
64
+ - README
65
+ executables: []
66
+
67
+ extensions: []
68
+
69
+ requirements: []
70
+
71
+ dependencies: []
72
+