Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
0f688c0
fixed an issue with col_name causing it to fail generating names for …
pdenya Jan 29, 2016
bfedfa4
refactor Creek::Sheet class
Apr 14, 2016
4c52f05
get date attribute from workbookPr and use it during dates conversion
kamilhism Apr 21, 2016
1f5063c
extract dates constants to book class and freeze them
kamilhism Apr 21, 2016
8aba712
Merge pull request #24 from pdenya/master
pythonicrubyist Apr 21, 2016
7e5e6f4
PR ##26 merged.
Apr 21, 2016
e33e6c0
Merge pull request #26 from ilyasgaraev/refactor-creek-sheet-class
pythonicrubyist Apr 21, 2016
26e3cdc
Merge pull request #27 from kamilhism/fix-dates-convert-issues
pythonicrubyist Apr 21, 2016
545e303
chore: Bump up the gem version to 1.1.2
Apr 21, 2016
e361d6f
Fix converting values formatted as percentage (#33)
maciejmajewski Jan 1, 2017
5c6c121
Parsing images (#32)
melcha Jan 1, 2017
b3bc431
add ability to fetch file from remote (#34)
dpsk Jan 5, 2017
75078dd
more robust way to fetch remote file, httparty dependency added. (#35)
dpsk Feb 14, 2017
2e9425e
Fix for temp image path (#39)
melcha Apr 12, 2017
d9b3df7
Change Readme to markdown, add syntax highlighting (#40)
melcha Apr 12, 2017
04a8df2
All the fixes from the Creek forks out there, and more (#47)
Jun 13, 2017
dcbb78f
issue #42 fixed.
pythonicrubyist Jun 14, 2017
5b0033a
Gem version bumped to 2.0.
pythonicrubyist Jun 14, 2017
260c196
Master (#48)
kruzewski Aug 28, 2017
cab8978
Update README.md: additional space symbol. (#50)
harrykiselev Aug 28, 2017
b83a6bf
Remove specs with dependency on external files.
Aug 28, 2017
f4613bb
Updated gemspec to use latest version of nokogiri (1.8.0) which works…
Aralox Nov 26, 2017
9be2b1e
relax nokogiri version restrictions (#58)
westonganger Nov 26, 2017
4a6e491
Gem version bumped to 2.1.
pythonicrubyist Nov 26, 2017
8f715d8
Replace HTTParty with http.rb (#64)
bgentry Apr 23, 2018
ce7e21a
Gem version bumped to 2.2.
pythonicrubyist Apr 23, 2018
801a8fa
Fix inconsistent DateTime conversion (#65)
demimismo May 16, 2018
1ae72a1
Bump up gem version.
pythonicrubyist Jul 13, 2018
dcae13e
[ creek #61 ] implemented.
pythonicrubyist Jul 13, 2018
67f0f22
[ creek #70 ] fixed.
pythonicrubyist Jul 13, 2018
1174baa
[ creek ] add badges to README.
pythonicrubyist Jul 13, 2018
c102541
[ creek ] add badges to README.
pythonicrubyist Jul 13, 2018
3f1f724
[ creek ] add badges to README.
pythonicrubyist Jul 13, 2018
caf40b6
Unescape the special hex code escape sequences (#73)
jarredholman Oct 8, 2018
debb898
Ampersand escaped failing test (#75)
davich Mar 12, 2019
74c6c1c
Ampersand escaped test fixed (#76)
davich Mar 12, 2019
4e1b1b4
bump up gem version.
pythonicrubyist Mar 12, 2019
efd84b9
Ignore runs of phonetic that appears in Japanese (#77)
ledsun Mar 12, 2019
fe8d73a
Bump http version to 4.0 (#78)
radar Mar 12, 2019
31e8499
bump up gem version.
pythonicrubyist Mar 12, 2019
1a5c990
bump up gem version.
pythonicrubyist Mar 12, 2019
6dad61b
nil case handling (#79)
maland Dec 30, 2019
f787567
Remove http requirement (#87)
dbernheisel Dec 30, 2019
c182b8a
[ creek ] upgrade bundler and nokogiri versions.
pythonicrubyist Dec 30, 2019
5449712
[ creek ] #88 fixed. (#91)
pythonicrubyist Mar 8, 2020
e0d5657
[ creek ] #88 gem version bumped up.
pythonicrubyist Mar 8, 2020
a3d887a
Added mapping cell ids with header column name (#93)
Apr 21, 2020
7a022e8
[ creek ] #93 gem version bumped up.
pythonicrubyist Apr 21, 2020
f29af88
Fix BigDecimal (#95)
mdemare Aug 2, 2020
327cf31
Reset headers each time when creating the enumerator. (#98)
ppostma Jul 12, 2021
2ce2466
[ creek ] #98 gem version bumped up.
pythonicrubyist Jul 12, 2021
f8856ee
Merge branch 'master' of https://github.com/pythonicrubyist/creek
pythonicrubyist Jul 12, 2021
494ed05
Handle XML namespaces in worksheets (#101)
bschmeck Nov 29, 2022
4c6b9fa
Support for parsing one cell anchored images (#107)
PavitKaur05 Nov 29, 2022
d149fdb
Run test using github actions (#109)
JunilJacob Nov 29, 2022
e032658
[ creek ] #101 gem version bumped up.
pythonicrubyist Nov 29, 2022
3b7e72d
pythonicrubyist [ creek ] #102 gem version bumped up.
pythonicrubyist Nov 29, 2022
2172e00
Fix download badge (#112)
JunilJacob Jan 9, 2023
9462de1
Limit object allocations (#115)
ThomasSevestre May 3, 2023
a91109d
Add Ruby 3.2 to CI (#113)
petergoldstein May 3, 2023
b6eeda1
pythonicrubyist [ creek ] #113 and #115 gem version bumped up.
pythonicrubyist May 3, 2023
c652789
Removes unused attr_reader and memoizes Book#sheets (#114)
weilandia Jul 3, 2023
67b5cd1
Delete .DS_Store
RHammam1 Jul 3, 2023
f0c683f
Add linter (#119)
DmitriyFirsov Mar 18, 2024
39bffae
Update LICENSE.txt
pythonicrubyist Dec 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 50 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# This workflow uses actions that are not certified by GitHub.
# They are provided by a third-party and are governed by
# separate terms of service, privacy policy, and support
# documentation.
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby

name: Ruby

on:
push:
branches: [ "*" ]
pull_request:
branches: [ "*" ]

permissions:
contents: read

jobs:
lint:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.1"
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run lint
run: bundle exec rubocop

test:

runs-on: ubuntu-latest
strategy:
matrix:
ruby-version: ['2.6', '2.7', '3.0', '3.1', '3.2']
needs:
- lint

steps:
- uses: actions/checkout@v3
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
- name: Run tests
run: bundle exec rake
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,8 @@ spec/reports
test/tmp
test/version_tmp
tmp

# Mac finder artifacts
.DS_Store

.idea
27 changes: 27 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Gemspec/RequiredRubyVersion:
Enabled: false

Layout/LineLength:
Enabled: false
Metrics:
Enabled: false
Naming/ConstantName:
Enabled: false

Style/FrozenStringLiteralComment:
Enabled: false
Style/Documentation:
Enabled: false
Style/AndOr:
Enabled: false
Style/StringConcatenation:
Enabled: false
Style/ClassAndModuleChildren:
Enabled: false
Style/OptionalBooleanParameter:
Enabled: false
Style/TernaryParentheses:
EnforcedStyle: require_parentheses_when_complex

Naming/PredicateName:
Enabled: false
4 changes: 3 additions & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2013 TODO: Write your name
Copyright (c) 2017 Ramtin Vaziri https://www.ramtin-vaziri.com

MIT License

Expand All @@ -20,3 +20,5 @@ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

https://ramtin-vaziri.com
142 changes: 142 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
[![version](https://badge.fury.io/rb/creek.svg)](https://badge.fury.io/rb/creek)
[![downloads](https://img.shields.io/gem/dt/creek)](https://rubygems.org/gems/creek)

# Creek - Stream parser for large Excel (xlsx and xlsm) files.

Creek is a Ruby gem that provides a fast, simple and efficient method of parsing large Excel (xlsx and xlsm) files.


## Installation

Creek can be used from the command line or as part of a Ruby web framework. To install the gem using terminal, run the following command:

```
gem install creek
```

To use it in Rails, add this line to your Gemfile:

```ruby
gem 'creek'
```

## Basic Usage
Creek can simply parse an Excel file by looping through the rows enumerator:

```ruby
require 'creek'
creek = Creek::Book.new 'spec/fixtures/sample.xlsx'
sheet = creek.sheets[0]

sheet.rows.each do |row|
puts row # => {"A1"=>"Content 1", "B1"=>nil, "C1"=>nil, "D1"=>"Content 3"}
end

sheet.simple_rows.each do |row|
puts row # => {"A"=>"Content 1", "B"=>nil, "C"=>nil, "D"=>"Content 3"}
end

sheet.rows_with_meta_data.each do |row|
puts row # => {"collapsed"=>"false", "customFormat"=>"false", "customHeight"=>"true", "hidden"=>"false", "ht"=>"12.1", "outlineLevel"=>"0", "r"=>"1", "cells"=>{"A1"=>"Content 1", "B1"=>nil, "C1"=>nil, "D1"=>"Content 3"}}
end

sheet.simple_rows_with_meta_data.each do |row|
puts row # => {"collapsed"=>"false", "customFormat"=>"false", "customHeight"=>"true", "hidden"=>"false", "ht"=>"12.1", "outlineLevel"=>"0", "r"=>"1", "cells"=>{"A"=>"Content 1", "B"=>nil, "C"=>nil, "D"=>"Content 3"}}
end

sheet.state # => 'visible'
sheet.name # => 'Sheet1'
sheet.rid # => 'rId2'
```

## Filename considerations
By default, Creek will ensure that the file extension is either *.xlsx or *.xlsm, but this check can be circumvented as needed:

```ruby
path = 'sample-as-zip.zip'
Creek::Book.new path, :check_file_extension => false
```

By default, the Rails [file_field_tag](http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html#method-i-file_field_tag) uploads to a temporary location and stores the original filename with the StringIO object. (See [this section](http://guides.rubyonrails.org/form_helpers.html#uploading-files) of the Rails Guides for more information.)

Creek can parse this directly without the need for file upload gems such as Carrierwave or Paperclip by passing the original filename as an option:

```ruby
# Import endpoint in Rails controller
def import
file = params[:file]
Creek::Book.new file.path, check_file_extension: false
end
```

## Parsing images
Creek does not parse images by default. If you want to parse the images,
use `with_images` method before iterating over rows to preload images information. If you don't call this method, Creek will not return images anywhere.

Cells with images will be an array of Pathname objects.
If an image is spread across multiple cells, same Pathname object will be returned for each cell.

```ruby
sheet.with_images.rows.each do |row|
puts row # => {"A1"=>[#<Pathname:/var/folders/ck/l64nmm3d4k75pvxr03ndk1tm0000gn/T/creek__drawing20161101-53599-274q0vimage1.jpeg>], "B2"=>"Fluffy"}
end
```

Images for a specific cell can be obtained with images_at method:

```ruby
puts sheet.images_at('A1') # => [#<Pathname:/var/folders/ck/l64nmm3d4k75pvxr03ndk1tm0000gn/T/creek__drawing20161101-53599-274q0vimage1.jpeg>]

# no images in a cell
puts sheet.images_at('C1') # => nil
```

Creek will most likely return nil for a cell with images if there is no other text cell in that row - you can use *images_at* method for retrieving images in that cell.

## Remote files

```ruby
remote_url = 'http://dev-builds.libreoffice.org/tmp/test.xlsx'
Creek::Book.new remote_url, remote: true
```

## Mapping cells with header names
By default, Creek will map cell names with letter and number(A1, B3 and etc). To be able to get cell values by header column name use ***with_headers*** (can be used only with ***#simple_rows*** method!!!) during creation *(Note: header column is first string of sheet)*

```ruby
creek = Creek::Book.new file.path, with_headers: true
```


## Contributing

Contributions are welcomed. You can fork a repository, add your code changes to the forked branch, ensure all existing unit tests pass, create new unit tests which cover your new changes and finally create a pull request.

After forking and then cloning the repository locally, install the Bundler and then use it
to install the development gem dependencies:

```
gem install bundler
bundle install
```

Once this is complete, you should be able to run the test suite:

```
rake
```

There are some remote tests that are excluded by default. To run those, run

```
bundle exec rspec --tag remote
```

## Bug Reporting

Please use the [Issues](https://github.com/pythonicrubyist/creek/issues) page to report bugs or suggest new enhancements.


## License

Creek has been published under [MIT License](https://github.com/pythonicrubyist/creek/blob/master/LICENSE.txt)
76 changes: 0 additions & 76 deletions README.rdoc

This file was deleted.

4 changes: 2 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "bundler/gem_tasks"
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new('spec')

# If you want to make this the default task
task :default => :spec
task default: :spec
34 changes: 17 additions & 17 deletions creek.gemspec
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'creek/version'

Gem::Specification.new do |spec|
spec.name = "creek"
spec.name = 'creek'
spec.version = Creek::VERSION
spec.authors = ["pythonicrubyist"]
spec.email = ["pythonicrubyist@gmail.com"]
spec.description = %q{A Ruby gem that streams and parses large Excel(xlsx and xlsm) files fast and efficiently.}
spec.summary = %q{A Ruby gem for parsing large Excel(xlsx and xlsm) files.}
spec.homepage = "https://github.com/pythonicrubyist/creek"
spec.license = "MIT"
spec.authors = ['pythonicrubyist']
spec.email = ['pythonicrubyist@gmail.com']
spec.description = 'A Ruby gem that streams and parses large Excel(xlsx and xlsm) files fast and efficiently.'
spec.summary = 'A Ruby gem for parsing large Excel(xlsx and xlsm) files.'
spec.homepage = 'https://github.com/pythonicrubyist/creek'
spec.license = 'MIT'

spec.files = `git ls-files`.split($/)
spec.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]
spec.require_paths = ['lib']

spec.required_ruby_version = '>= 1.9.2'
spec.required_ruby_version = '>= 2.0.0'

spec.add_development_dependency "bundler", "~> 1.3"
spec.add_development_dependency "rake"
spec.add_development_dependency 'rspec', '~> 2.13.0'
spec.add_development_dependency 'pry'
spec.add_development_dependency 'bundler'
spec.add_development_dependency 'pry-byebug'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rspec', '~> 3.6.0'
spec.add_development_dependency 'rubocop'

spec.add_dependency 'nokogiri', '~> 1.6.0'
spec.add_dependency 'nokogiri', '>= 1.10.0'
spec.add_dependency 'rubyzip', '>= 1.0.0'
end
6 changes: 5 additions & 1 deletion lib/creek.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
require "creek/version"
# frozen_string_literal: true

require 'creek/version'
require 'creek/book'
require 'creek/styles/constants'
require 'creek/styles/style_types'
require 'creek/styles/converter'
require 'creek/utils'
require 'creek/styles'
require 'creek/drawing'
require 'creek/sheet'
require 'creek/shared_strings'

Expand Down
Loading