Giter Site home page Giter Site logo

sheets's Introduction

Sheets

Join the chat at https://gitter.im/bspaulding/Sheets

Sheets is a Facade on top of many spreadsheet formats, presenting them as simple, unified, native ruby arrays. It is intended to allow applications to easily import data from a wide variety of spreadsheet formats.

With Sheets, all cell values are strings representing the final, evaluated value of the cell.

This does mean that, in some cases, you will be casting data back into its native format.

However, this eliminates the need to deal with multiple spreadsheet formats and normalize data types in your application logic.

Your application only needs to care about the layout of the spreadsheet, and the format you want the data in.

Usage

Install via Rubygems:

gem install sheets

To retrieve a list of parseable spreadsheet formats at runtime:

Sheets::Base.parseable_formats # => ["csv", "xls", "xlsx", "ods"]

To open a spreadsheet, pass initialize Sheets::Base.new either a file path:

Sheets::Base.new( '/path/to/a/spreadsheet.(format)' )

or a file handle:

Sheets::Base.new( File.open('/path/to/a/spreadsheet.(format)') )

By default, Sheets will use the basename of the file to detect the spreadsheet type. You can override this by passing in the :format option:

This is necessary if you pass Sheets an IO object, like StringIO, that doesn't have metadata like a filename/path.

Sheets::Base.new( an_io_object_with_spreadsheet_data, :format => :xls )

Once you have imported a sheet, you can either grab the array:

sheet = Sheets::Base.new( # ... )
sheet.to_array

or utilize any of the Enumerable functions on the sheet:

sheet = Sheets::Base.new( # ... )
sheet.collect {|row| puts row }

Additionally, you may output the sheet in any of the renderable formats:

Sheets::Base.renderable_formats # => ['csv', 'xls']
sheet = Sheets::Base.new( file )
sheet.to_csv
sheet.to_xls

Sheets::Base will skip the parsing phase if initialized with an array, allowing you to render arrays to a native spreadsheet format:

my_awesome_data = [ ["Date", "Spent", "Earned"], ["2011-04-11", "$0.00", "$5,000.00"] ]
sheet = Sheets::Base.new( my_awesome_data )
sheet.to_csv
sheet.to_xls

Adding Parsers

Parsers subclass Sheets::Parsers::Base, live in the Sheets::Parsers namespace and should respond to two methods:

  • formats: returns an array of string format names (file extensions) that this parser class supports
  • to_array: returns a simple array representation of the spreadsheet.

Parsers have access to @data and @format in order to do their parsing. See lib/sheets/parsers/* for examples.

Adding Renderers

Renderers subclass Sheets::Renderers::Base, live in the Sheets::Renderers namespace and should respond to:

  • formats: returns an array of string format names that this parser class supports
  • to_#{format}: For each format that a renderer supports, it should respond to "to_#{format}", returning the file data of that format.

Renderers are given access to the results of Sheets::Base#to_array as @data. See lib/sheets/renderers/* for examples.

Test Suite Results

Sheets uses Travis-CI for Continuous Integration.

Build Status

Code Climate

License

Sheets is licensed under the MIT License.

Please note that Sheets is dependent upon the Spreadsheet gem, which is licensed under the GPLv3.

Credits

Sheets takes advantage of the work done in these gems:

sheets's People

Contributors

bspaulding avatar mnoble avatar gitter-badger avatar

Stargazers

Morgan Mikel McDaris avatar fannar avatar tohta avatar Angus H. avatar Koichi Shiraishi avatar Andrey Eremin avatar Greg Van de Mosselaer avatar Chris Edwards avatar Taz Singh avatar Vasiliy Ermolovich avatar Thiago Brandão avatar Logan Leger avatar  avatar O.T. avatar  avatar Charles Maresh avatar Kevin Faustino avatar Antono Vasiljev avatar  avatar Georg Ledermann avatar Sebastian Munz avatar  avatar Rida Al Barazi avatar

Watchers

 avatar James Cloos avatar Koichi Shiraishi avatar  avatar

sheets's Issues

Is sheets repository actively maintained?

Thanks for making this gem. We use this gem in our project and wanted to understand if this is still actively maintained. I have fixed two issues in this gem (in my fork) and would like to create PR for it if it's maintained otherwise we can be maintainer for it.

Let us know about it.

Thanks,
AJ

Update Rubyzip (and others?)

Rubyzip < 1.0.0 convention to require "zip/zip" is antiquated in Rubyzip >= 1.0.0 and is breaking all of the things.

@bspaulding Would you be open to a pull request which freshens up the gem dependencies? This would drop support for 1.8.7 which seems reasonable.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.