Git Product home page Git Product logo

spreadbase's Introduction

CI

SpreadBase!!

... because Excel IS a database.

Status

The library itself is stable, and can be regularly used.

I plan to add features on request, but if nobody asks for them, I will update the project very infrequently.

What is SpreadBase©?

SpreadBase© is a set of APIs for programmatically accessing spreadsheets (currently, only OpenDocument 1.2).

Usage

Install/require the gem:

gem install spreadbase

require 'spreadbase'

Create/open a document:

document = SpreadBase::Document.new( "Today's menu.ods" )

Add a table:

document.tables << SpreadBase::Table.new(
  'Transistors', [
    [ 'Roasted 6502',                                 38.911 ],
    [ '65000 with side dishes of Copper and Blitter', 512.0  ],
  ]
)

Modify an existing table; can be done also directly on the array:

table = document.tables.first

table.insert_row( 0, [ 'Dish',                    'Price' ] )
table.insert_row( 2, [ '8080, with an 8-bit bus', 8       ] )

table.insert_column( 2, [ 'Availability', Date.today, Time.now + 42, 'Never!!' ] )

Add another (empty) table:

table_2 = SpreadBase::Table.new( 'Loud and annoying customers' )

document.tables << table_2

Append a column:

table_2.append_column( [ 'Name' ] )

Append a row:

table_2.append_row( [ 'Fabrizio F.' ] )

Read a column, or a range of columns:

table.column( 0 )

# [ 'Dish', 'Roasted 6502', '8080, with an 8-bit bus', '65000 with side dishes of Copper and Blitter' ]

table.column( 0 .. 1 )

# [ [ 'Dish',  'Roasted 6502', '8080, with an 8-bit bus', '65000 with side dishes of Copper and Blitter' ],
#   [ 'Price', 38.911,         8,                         512.0                                          ] ]

Read a row, or a range of rows:

table.row( 1 )

# [ 'Roasted 6502', 38.911 ]

table.row( 1 .. 2 )

# [ [ 'Roasted 6502', 38.911 ], [ '8080, with an 8-bit bus', 8 ] ]

Read a cell:

price_8080 = document.tables[ 0 ][ 1, 2 ]

When a cell value is read from an existing file, the data type is directly converted to the closest ruby one.

Write to a cell:

document.tables[ 0 ][ 1, 2 ] = price_8080 + 0.080

Print a table:

puts document.tables[ 0 ].to_s( :with_headers => true )

+----------------------------------------------+--------+---------------------------+
| Dish                                         | Price  | Availability              |
+----------------------------------------------+--------+---------------------------+
| Roasted 6502                                 | 38.911 | 2012-04-21                |
| 8080, with an 8-bit bus                      | 8.08   | 2012-04-21 11:45:08 +0200 |
| 65000 with side dishes of Copper and Blitter | 512.0  | Never!!                   |
+----------------------------------------------+--------+---------------------------+

Print a document:

puts document.to_s( :with_headers => true )

Transistors:

  +----------------------------------------------+--------+---------------------------+
  | Dish                                         | Price  | Availability              |
  +----------------------------------------------+--------+---------------------------+
  | Roasted 6502                                 | 38.911 | 2012-04-21                |
  | 8080, with an 8-bit bus                      | 8.08   | 2012-04-21 11:45:08 +0200 |
  | 65000 with side dishes of Copper and Blitter | 512.0  | Never!!                   |
  +----------------------------------------------+--------+---------------------------+

Loud and annoying customers:

  +-------------+
  | Name        |
  +-------------+
  | Fabrizio F. |
  +-------------+

Save the document:

document.save

Enjoy many other APIs.

Notes

  • Numbers are decoded to Fixnum or Float, depending on the existence of the fractional part. Alternatively, numbers with a fractional part can be decoded as Bigdecimal, using the option:

    SpreadBase::Document.new( "Random numbers für alle!.ods", floats_as_bigdecimal: true )

  • The gem is tested on all the supported Ruby versions (see Build), and used mainly on Linux.

  • The column widths are retained (decoding/encoding), but at the current version, they're not [officially] accessible via any API.

Currently unsupported features

  • Styles; Date and and [Date]Times are formatted as, respectively, '%Y-%m-%d' and '%Y-%m-%d %H:%M:%S %z'
  • Percentage data type - they're handled using their float value (e.g. 50% = 0.5)

Roadmap/Todo

https://github.com/saveriomiroddi/spreadbase/wiki/Todo-%28roadmap%29

spreadbase's People

Contributors

64kramsystem avatar taichi-ishitani avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

spreadbase's Issues

Deprecated warnings

I've been getting these warnings lately on every instance creation. I guess we could remove the entire constant out of the module.

/home/matt/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/spreadbase-0.1.3/lib/spreadbase/helpers/helpers.rb:34: warning: constant ::Fixnum is deprecated
/home/matt/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/spreadbase-0.1.3/lib/spreadbase/codecs/open_document_12_modules/encoding.rb:178: warning: constant ::Fixnum is deprecated

Add bigdecimal into gemspec

Hi @64kramsystem ,

I got the warning below when using the spreadbase gem with Ruby 3.3.

/opt/rbenv/versions/3.3.0/lib/ruby/gems/3.3.0/gems/spreadbase-0.4.0/lib/spreadbase/codecs/open_document_12_modules/encoding.rb:3: warning: bigdecimal was loaded from the standard library, but will no longer be part of the default gems since Ruby 3.4.0. Add bigdecimal to your Gemfile or gemspec. Also contact author of spreadbase-0.4.0 to add bigdecimal into its gemspec.

To fix this warning, we need to add the bigdecimal gem to the gemspec. However there is version confliction between spreadbase gem and bigdecimal gem.

`rubyzip` dependency is too loose

See:

WARNING:  open-ended dependency on rubyzip (>= 1.3.0) is not recommended
  if rubyzip is semantically versioned, use:
    add_runtime_dependency 'rubyzip', '~> 1.3', '>= 1.3.0'

How do I create a column like this?

Hi, I use your library to create an ods file, but I don't know how do I create this column with one cell like this:

+-----+------+
|a|
+-----+-------+
|a1 |a2 |
+-----+-------+

Thanks in advance!

Regards,Herman

Fix build

Builds are failing, due to timezone issues, which don't happen locally.

Sample:

3) SpreadBase::Table return the data as string (:to_s)
   Failure/Error: @sample_table.to_s.should == expected_string
     expected: "+------------+---------------------------+---------------------------+\n| 1          | 1.1                       | 1.33                      |\n| 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0200 |\n| true       | a                         | NIL                       |\n+------------+---------------------------+---------------------------+\n"
          got: "+------------+---------------------------+---------------------------+\n| 1          | 1.1                       | 1.33                      |\n| 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0000 |\n| true       | a                         | NIL                       |\n+------------+---------------------------+---------------------------+\n" (using ==)
     Diff:
     @@ -1,6 +1,6 @@
      +------------+---------------------------+---------------------------+
      | 1          | 1.1                       | 1.33                      |
     -| 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0200 |
     +| 2012-04-10 | 2012-04-11 23:33:42 +0000 | 2012-04-11 23:33:42 +0000 |
      | true       | a                         | NIL                       |
      +------------+---------------------------+---------------------------+
   # ./spec/elements/table_spec.rb:326:in `block (2 levels) in <top (required)>'

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.