parseexcel_mod 0.0.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
data/usage-en.txt ADDED
@@ -0,0 +1,112 @@
1
+ Installing Programs with install.rb / setup.rb
2
+ ==============================================
3
+
4
+ Overview
5
+ --------
6
+
7
+ Type these lines on command line:
8
+ ("#" line may require root privilege)
9
+
10
+ $ ruby install.rb config
11
+ $ ruby install.rb setup
12
+ # ruby install.rb install
13
+
14
+
15
+ There's no difference in a usage between install.rb
16
+ and setup.rb.
17
+
18
+ $ ruby setup.rb config
19
+ $ ruby setup.rb setup
20
+ # ruby setup.rb install
21
+
22
+
23
+ Details
24
+ -------
25
+
26
+ Usage of install.rb/setup.rb is:
27
+
28
+ ruby install.rb <global options>
29
+ ruby install.rb [<global options>] <task> [<task options>]
30
+
31
+
32
+ -q,--quiet
33
+ suppress message outputs
34
+ --verbose
35
+ output messages verbosely (default)
36
+ -h,--help
37
+ prints help and quit
38
+ -v,--version
39
+ prints version and quit
40
+ --copyright
41
+ prints copyright and quit
42
+
43
+ These are acceptable tasks:
44
+ config
45
+ saves configurations
46
+ show
47
+ prints current configurations
48
+ setup
49
+ compiles extentions
50
+ install
51
+ installs files
52
+ clean
53
+ cleans created files
54
+
55
+ Task Options for Config
56
+ -----------------------
57
+
58
+ --prefix=PATH
59
+ a prefix of the installing directory path
60
+ --std-ruby=PATH
61
+ the directory for standard ruby libraries
62
+ --site-ruby-common=PATH
63
+ the directory for version-independent non-standard
64
+ ruby libraries
65
+ --site-ruby=PATH
66
+ the directory for non-standard ruby libraries
67
+ --bin-dir=PATH
68
+ the directory for commands
69
+ --rb-dir=PATH
70
+ the directory for ruby scripts
71
+ --so-dir=PATH
72
+ the directory for ruby extentions
73
+ --data-dir=PATH
74
+ the directory for shared data
75
+ --ruby-path=PATH
76
+ path to set to #! line
77
+ --ruby-prog=PATH
78
+ the ruby program using for installation
79
+ --make-prog=NAME
80
+ the make program to compile ruby extentions
81
+ --without-ext
82
+ forces to install.rb never to compile/install
83
+ ruby extentions.
84
+ --rbconfig=PATH
85
+ your rbconfig.rb to load
86
+
87
+ You can view default values of these options by typing
88
+
89
+ $ ruby install.rb --help
90
+
91
+
92
+ In addition, setup.rb accepts these options:
93
+ --with=NAME,NAME,NAME...
94
+ package names which you want to install
95
+ --without=NAME,NAME,NAME...
96
+ package names which you do not want to install
97
+
98
+ [NOTE] You can pass options for extconf.rb like this:
99
+
100
+ ruby install.rb config -- --with-tklib=/usr/lib/libtk-ja.so.8.0
101
+
102
+
103
+ Task Options for Install
104
+ ------------------------
105
+
106
+ --no-harm
107
+ prints what to do and done nothing really.
108
+ --prefix=PATH
109
+ a prefix of the installing directory path.
110
+ This option may help binary package maintainers.
111
+ A default value is an empty string.
112
+
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: parseexcel_mod
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - t0pep0
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-12-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '1.3'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.3'
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: ParseExcel with utf8
47
+ email:
48
+ - t0pep0.gentoo@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - COPYING
55
+ - Gemfile
56
+ - LICENSE.txt
57
+ - README
58
+ - README.md
59
+ - Rakefile
60
+ - lib/parseexcel_mod.rb
61
+ - lib/parseexcel_mod/format.rb
62
+ - lib/parseexcel_mod/olestorage.rb
63
+ - lib/parseexcel_mod/parseexcel_mod.rb
64
+ - lib/parseexcel_mod/parser.rb
65
+ - lib/parseexcel_mod/version.rb
66
+ - lib/parseexcel_mod/workbook.rb
67
+ - lib/parseexcel_mod/worksheet.rb
68
+ - parseexcel_mod.gemspec
69
+ - test/data/annotation.xls
70
+ - test/data/bar.xls
71
+ - test/data/comment.5.0.xls
72
+ - test/data/comment.xls
73
+ - test/data/dates.xls
74
+ - test/data/float.5.0.xls
75
+ - test/data/float.xls
76
+ - test/data/foo.xls
77
+ - test/data/image.xls
78
+ - test/data/nil.xls
79
+ - test/data/umlaut.5.0.xls
80
+ - test/data/umlaut.biff8.xls
81
+ - test/data/uncompressed.str.xls
82
+ - test/suite.rb
83
+ - test/test_format.rb
84
+ - test/test_olestorage.rb
85
+ - test/test_parser.rb
86
+ - test/test_workbook.rb
87
+ - test/test_worksheet.rb
88
+ - usage-en.txt
89
+ homepage: https://github.com/t0pep0/parseexcel_mod
90
+ licenses:
91
+ - MIT
92
+ post_install_message:
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ required_rubygems_version: !ruby/object:Gem::Requirement
103
+ none: false
104
+ requirements:
105
+ - - ! '>='
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 1.8.23
111
+ signing_key:
112
+ specification_version: 3
113
+ summary: Parse excel
114
+ test_files:
115
+ - test/data/annotation.xls
116
+ - test/data/bar.xls
117
+ - test/data/comment.5.0.xls
118
+ - test/data/comment.xls
119
+ - test/data/dates.xls
120
+ - test/data/float.5.0.xls
121
+ - test/data/float.xls
122
+ - test/data/foo.xls
123
+ - test/data/image.xls
124
+ - test/data/nil.xls
125
+ - test/data/umlaut.5.0.xls
126
+ - test/data/umlaut.biff8.xls
127
+ - test/data/uncompressed.str.xls
128
+ - test/suite.rb
129
+ - test/test_format.rb
130
+ - test/test_olestorage.rb
131
+ - test/test_parser.rb
132
+ - test/test_workbook.rb
133
+ - test/test_worksheet.rb
134
+ has_rdoc: