read_excel 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +33 -0
- data/LICENSE.txt +21 -0
- data/README.md +57 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/read_excel.rb +24 -0
- data/lib/read_excel/version.rb +3 -0
- data/lib/read_excel/xls_reader.rb +46 -0
- data/lib/read_excel/xlsx_reader.rb +47 -0
- data/read_excel.gemspec +22 -0
- metadata +58 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f6e667e22a9b9fccbaaa795e69b2ce3be5125e49882ef1c13fb5e96abd65c3af
|
4
|
+
data.tar.gz: 1503da4043ff4894788bef9ae08012107ac129a195cd4e276f9356ea405ba34f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6c0791b1e9ba1dabed335149dd24ec26dae3f78301f89d51a3d21221b92ed2ecafbdce553e54ada43f3dc00c6e0fcaa6df1a8f044a81b96846fc16c78de5e50a
|
7
|
+
data.tar.gz: 584973fdb9090aaea2a6c694f11bb9f08b1c2c9e94c3c0bdae7883812a042b94b507f1170483998961a65da456da36c5ff0729ae5fbabba8243f10ba86708c76
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at nakamura.hideo74@nihon-u.ac.jp. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
read_excel (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
mini_portile2 (2.4.0)
|
10
|
+
minitest (5.14.2)
|
11
|
+
nokogiri (1.10.10)
|
12
|
+
mini_portile2 (~> 2.4.0)
|
13
|
+
rake (12.3.3)
|
14
|
+
ruby-ole (1.2.12.2)
|
15
|
+
rubyXL (3.4.15)
|
16
|
+
nokogiri (>= 1.10.8)
|
17
|
+
rubyzip (>= 1.3.0)
|
18
|
+
rubyzip (2.3.0)
|
19
|
+
spreadsheet (1.2.6)
|
20
|
+
ruby-ole (>= 1.0)
|
21
|
+
|
22
|
+
PLATFORMS
|
23
|
+
ruby
|
24
|
+
|
25
|
+
DEPENDENCIES
|
26
|
+
minitest (~> 5.0)
|
27
|
+
rake (~> 12.0)
|
28
|
+
read_excel!
|
29
|
+
rubyXL
|
30
|
+
spreadsheet
|
31
|
+
|
32
|
+
BUNDLED WITH
|
33
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Hideo NAKAMURA
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
# ReadExcel
|
2
|
+
|
3
|
+
This ReadExcel rubygem can handle existing excel file both *.xlsx and *.xls. It can only get cell's value and sheet name of excel file.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'read_excel'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle install
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install read_excel
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
require 'read_excel'
|
25
|
+
|
26
|
+
workbook = ReadExcel.new('/path/to/excel_file')
|
27
|
+
|
28
|
+
sheet_count = workbook.worksheets.count
|
29
|
+
|
30
|
+
worksheets = workbook.worksheets
|
31
|
+
|
32
|
+
worksheets.each do |worksheet|
|
33
|
+
p worksheet.name
|
34
|
+
end
|
35
|
+
|
36
|
+
worksheet = worksheets[0]
|
37
|
+
|
38
|
+
row_values = worksheet.row(0) # (row, col) = (0, 0) = 'A1'
|
39
|
+
p row_values[0] # 'A1'
|
40
|
+
p row_values[2] # 'C1'
|
41
|
+
|
42
|
+
row_values = worksheet.row(10000)
|
43
|
+
row_values.empty? # => true empty row returns []
|
44
|
+
```
|
45
|
+
|
46
|
+
## Contributing
|
47
|
+
|
48
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/read_excel. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/read_excel/blob/master/CODE_OF_CONDUCT.md).
|
49
|
+
|
50
|
+
|
51
|
+
## License
|
52
|
+
|
53
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
54
|
+
|
55
|
+
## Code of Conduct
|
56
|
+
|
57
|
+
Everyone interacting in the ReadExcel project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/read_excel/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "read_excel"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/read_excel.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "read_excel/version"
|
2
|
+
require "read_excel/xls_reader"
|
3
|
+
require "read_excel/xlsx_reader"
|
4
|
+
|
5
|
+
class ReadExcel
|
6
|
+
class Error < StandardError; end
|
7
|
+
|
8
|
+
def initialize(filepath)
|
9
|
+
@filepath = filepath
|
10
|
+
if @filepath =~ /xls\Z/i
|
11
|
+
@read_adapter = ReadExcel::XLSReader.new(filepath)
|
12
|
+
elsif @filepath =~ /xlsx\Z/i
|
13
|
+
@read_adapter = ReadExcel::XLSXReader.new(filepath)
|
14
|
+
else
|
15
|
+
raise "#{filepath} doesn't seem excel file."
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
# list of worksheets
|
20
|
+
def worksheets
|
21
|
+
@read_adapter.worksheets
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
# -*- conding: utf-8 -*-
|
2
|
+
require 'spreadsheet'
|
3
|
+
|
4
|
+
class ReadExcel::XLSReader
|
5
|
+
class Worksheet
|
6
|
+
def initialize(worksheet)
|
7
|
+
@worksheet = worksheet
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
@worksheet.name
|
12
|
+
end
|
13
|
+
|
14
|
+
def row(n)
|
15
|
+
values = []
|
16
|
+
if @worksheet.row(n)
|
17
|
+
count = @worksheet.row(n).size
|
18
|
+
(0...count).each do |col|
|
19
|
+
cell = @worksheet.row(n)[col]
|
20
|
+
if cell.class == Spreadsheet::Formula
|
21
|
+
values << cell.value
|
22
|
+
else
|
23
|
+
values << cell
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
values
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(filepath)
|
33
|
+
@workbook = Spreadsheet.open(filepath)
|
34
|
+
@worksheets = []
|
35
|
+
end
|
36
|
+
|
37
|
+
def worksheets
|
38
|
+
if @worksheets.empty?
|
39
|
+
@workbook.worksheets.each do |worksheet|
|
40
|
+
@worksheets << Worksheet.new(worksheet)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@worksheets
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
# -*- conding: utf-8 -*-
|
2
|
+
require 'rubyXL'
|
3
|
+
|
4
|
+
class ReadExcel::XLSXReader
|
5
|
+
class Worksheet
|
6
|
+
def initialize(worksheet)
|
7
|
+
@worksheet = worksheet
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
@worksheet.sheet_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def row(n)
|
15
|
+
values = []
|
16
|
+
if @worksheet[n]
|
17
|
+
count = @worksheet[n].size
|
18
|
+
(0...count).each do |col|
|
19
|
+
cell = @worksheet[n][col]
|
20
|
+
if cell
|
21
|
+
values << cell.value
|
22
|
+
else
|
23
|
+
values << cell
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
values
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize(filepath)
|
33
|
+
@workbook = RubyXL::Parser.parse(filepath)
|
34
|
+
@worksheets = []
|
35
|
+
end
|
36
|
+
|
37
|
+
def worksheets
|
38
|
+
if @worksheets.empty?
|
39
|
+
@workbook.worksheets.each do |worksheet|
|
40
|
+
@worksheets << Worksheet.new(worksheet)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
@worksheets
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/read_excel.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require_relative 'lib/read_excel/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = "read_excel"
|
5
|
+
spec.version = ReadExcel::VERSION
|
6
|
+
spec.authors = ["Hideo NAKAMURA"]
|
7
|
+
spec.email = ["nakamura.hideo@gmail.com"]
|
8
|
+
|
9
|
+
spec.summary = %q{utility for reading excel file both .xls and .xlsx.}
|
10
|
+
spec.description = %q{utility for reading excel file both .xls and .xlsx.}
|
11
|
+
spec.license = "MIT"
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
|
14
|
+
# Specify which files should be added to the gem when it is released.
|
15
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
16
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
17
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
end
|
19
|
+
spec.bindir = "exe"
|
20
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
+
spec.require_paths = ["lib"]
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: read_excel
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Hideo NAKAMURA
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-09-27 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: utility for reading excel file both .xls and .xlsx.
|
14
|
+
email:
|
15
|
+
- nakamura.hideo@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".travis.yml"
|
22
|
+
- CODE_OF_CONDUCT.md
|
23
|
+
- Gemfile
|
24
|
+
- Gemfile.lock
|
25
|
+
- LICENSE.txt
|
26
|
+
- README.md
|
27
|
+
- Rakefile
|
28
|
+
- bin/console
|
29
|
+
- bin/setup
|
30
|
+
- lib/read_excel.rb
|
31
|
+
- lib/read_excel/version.rb
|
32
|
+
- lib/read_excel/xls_reader.rb
|
33
|
+
- lib/read_excel/xlsx_reader.rb
|
34
|
+
- read_excel.gemspec
|
35
|
+
homepage:
|
36
|
+
licenses:
|
37
|
+
- MIT
|
38
|
+
metadata: {}
|
39
|
+
post_install_message:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.3.0
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
requirements:
|
50
|
+
- - ">="
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
requirements: []
|
54
|
+
rubygems_version: 3.0.3
|
55
|
+
signing_key:
|
56
|
+
specification_version: 4
|
57
|
+
summary: utility for reading excel file both .xls and .xlsx.
|
58
|
+
test_files: []
|