Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gbiczo/oxcelix
Oxcelix - A fast and simple .xlsx file parser
https://github.com/gbiczo/oxcelix
Last synced: 3 months ago
JSON representation
Oxcelix - A fast and simple .xlsx file parser
- Host: GitHub
- URL: https://github.com/gbiczo/oxcelix
- Owner: gbiczo
- License: mit
- Created: 2013-10-01T21:21:10.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2018-11-01T19:12:38.000Z (over 5 years ago)
- Last Synced: 2024-03-18T06:46:08.023Z (3 months ago)
- Language: Ruby
- Size: 192 KB
- Stars: 19
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES
- License: LICENSE
Lists
- awesome-ruby - oxcelix - A fast Excel 2007/2010 (.xlsx) file parser that returns a collection of Matrix objects (Spreadsheets)
README
Oxcelix
=======![]()
[![Build Status](https://travis-ci.org/gbiczo/oxcelix.svg?branch=0.4.0)](https://travis-ci.org/gbiczo/oxcelix)Oxcelix - A fast and simple .xlsx file parser
Description
-----------Oxcelix is an xlsx (Excel 2007/2010) parser. The result of the parsing is a
Workbook which is an array of Sheet objects, which in turn store the data in
Matrix objects. Matrices consist of Cell objects to maintain comments and
formatting/style dataOxcelix uses the great Ox gem (http://rubygems.org/gems/ox) for fast SAX-parsing.
Synopsis
--------To process an xlsx file:
`require 'oxcelix'`
`w = Oxcelix::Workbook.new('whatever.xlsx')`To omit certain sheets:
`w = Oxcelix::Workbook.new('whatever.xlsx', :exclude => ['sheet1', 'sheet2'])`
Include only some of the sheets:
`w = Oxcelix::Workbook.new('whatever.xlsx', :include => ['sheet1', 'sheet2', 'sheet3'])`
To have the values of the merged cells copied over the mergegroup:
`w = Oxcelix::Workbook.new('whatever.xlsx', :copymerge => true)`
Convert a Sheet object into a collection of ruby values or formatted ruby strings:
`require 'oxcelix'`
`w = Oxcelix::Workbook.new('whatever.xlsx', :copymerge => true)`
`w.sheets[0].to_ru # returns a Matrix of DateTime, Integer, etc objects`
`w.sheets[0].to_fmt # returns a Matrix of formatted Strings based on the above.`
OR:
`require 'oxcelix'`
`w = Oxcelix::RuValueWorkbook.new('whatever.xlsx', :copymerge => true)`
`w = Oxcelix::FormattedWorkbook.new('whatever.xlsx', :copymerge => true)`You can parse an Excel file partially to save memory:
`require 'oxcelix'`
`w = Oxcelix::Workbook.new('whatever.xlsx', :cellrange => ('A3'..'R42')) # will only parse the cells included in the given range on every included sheet`
`w = Oxcelix::Workbook.new('whatever.xlsx', :paginate => [5,2]) # will only parse the second five-row group of every included sheet.`Installation
------------`gem install oxcelix`
Advantages over other Excel parsers
-----------------------------------Excel file processing involves XML document parsing. Usually, this is achieved by DOM-parsing the data with a suitable XML library.
The main drawbacks of this approach are memory usage and speed. The resulting object tree will be roughly as big as the original file, and during the parsing, they will both be stored in the memory, which can cause quite some complications when processing huge files. Also, interpreting every bit of an excel spreadsheet will slow down unnecessarily the process, if we only need the data stored in that file.
The solution for the memory-consumption problem is SAX stream parsing. This ensures that only the relevant XML elements get processed,
without having to load the whole XML file in memory.Oxcelix uses the SAX parser offered by Peter Ohler's Ox gem. I found Ox SAX parser quite fast, so to further speed up the parsing.
For a comparison of XML parsers, please consult the Ox homepage[http://www.ohler.com/dev/xml_with_ruby/xml_with_ruby.html].
TODO
----
* Support for inline strings to be added
* include/exclude mechanism should extend to cell areas inside Sheet objects
* Further improvement to the formatting algorithms. Theoretically, to_fmt should be able to
split conditional-formatting strings and to display e.g. thousands separated number strings