Giter VIP home page Giter VIP logo

rubiod's Introduction

RubiOD - work with OpenDocument in pure Ruby

The rubiod gem is intended to provide cute ruby-style interface to work with OASIS Open Document Format files. For now it supports some functionality to read/modify OD spreadsheets (.ods).

About this fork

based on netoctone -> github.com/netoctone/rubiod.git

Changes:

  • including unit-tests

  • file can be build in-memory (see ‘Rails example’)

  • improved handling:

    • new row/cell managment allows to read/write any cell

    • hide/show rows

  • named cells

Requirements

rubiod works with ruby 1.8.7 or higher. It is dependent on libxml-ruby and rubyzip gems

Download and installation

At least two ways available:

  1. Build gem from source:

    git clone https://github.com/McBen/rubiod.git
    cd rubiod
    gem build rubiod.gemspec
    gem install rubiod-version.gem
  2. Or add following line to Gemfile (if it’s in use):

    gem 'rubiod', :git => 'https://github.com/McBen/rubiod.git'
    

ODS Showcase

Some examples of work with rubiod

Load rubiod itself

require 'rubygems'
require 'rubiod'

Load spreadsheet

Document initializer takes a path to file or any IO object

spread = Rubiod::Spreadsheet.new('path/to/file.ods')

File.open('path/to/file.ods', 'r') do |f|
  Rubiod::Spreadsheet.new(f)
end

Extract document parts

RubiOD allows to work separately with worksheets and rows of document:

worksheet = spread['Worksheet']
worksheet = spread[0]

row = spread[0, 10]

row = worksheet[10]

Read data

puts spread['Worksheet', 0, 0]
puts worksheet[0, 0]
puts row[0]

Modify data

Setting new value in a cell:

spread[0, 1, 5] = 'new data'
worksheet[1, 5] = 10
row[5] = object

Inserting new row after specified one, applying the same formatting:

worksheet.insert 10

Deleting an entire row (with shifting lower ones up):

worksheet.delete 11

Using names cells

oldvalue = spread.labels["myCell"].value
spread.labels["myCell"] = "new value"

Apply modifications

spread.save

Rails example

Loading a template, render some text into it and send the file to the client:

class myController
  def downloadSpreadsheet
    report = Rubiod::Spreadsheet.new("app/templates/spread.ots")

    table = report["Table1"]
    table[1,1] = @order.customer.name
    table[1,3] = @order.customer_reference

    send_data report.generate, type: 'application/vnd.oasis.opendocument.spreadsheet',
                              disposition: 'attachment',
                              filename: 'your_file.ods'    
  end
end

License

RubiOD is released under the MIT license.

rubiod's People

Contributors

mcben avatar netoctone avatar

Watchers

 avatar  avatar  avatar

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.