All Projects → westonganger → rodf

westonganger / rodf

Licence: MIT license
ODF generation library for Ruby

Programming Languages

ruby
36898 projects - #4 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to rodf

Yii2 Export
A library to export server/db data in various formats (e.g. excel, html, pdf, csv etc.)
Stars: ✭ 153 (+206%)
Mutual labels:  export, spreadsheet
workbook
simple framework for containing spreadsheet like data
Stars: ✭ 13 (-74%)
Mutual labels:  spreadsheet, ods
easy-excel
🚀 快速读写Excel文件,简单高效
Stars: ✭ 118 (+136%)
Mutual labels:  spreadsheet, ods
Spout
Read and write spreadsheet files (CSV, XLSX and ODS), in a fast and scalable way
Stars: ✭ 3,861 (+7622%)
Mutual labels:  spreadsheet, ods
svelte-datagrid
Svelte data grid spreadsheet best best features and performance from excel
Stars: ✭ 48 (-4%)
Mutual labels:  export, spreadsheet
sheet2dict
Simple XLSX and CSV to dictionary converter
Stars: ✭ 206 (+312%)
Mutual labels:  export, spreadsheet
convey
CSV processing and web related data types mutual conversion
Stars: ✭ 16 (-68%)
Mutual labels:  spreadsheet, ods
Phpspreadsheet
A pure PHP library for reading and writing spreadsheet files
Stars: ✭ 10,627 (+21154%)
Mutual labels:  spreadsheet, ods
Documentserver
ONLYOFFICE Document Server is an online office suite comprising viewers and editors for texts, spreadsheets and presentations, fully compatible with Office Open XML formats: .docx, .xlsx, .pptx and enabling collaborative editing in real time.
Stars: ✭ 2,335 (+4570%)
Mutual labels:  spreadsheet, ods
spreadsheet
Yii2 extension for export to Excel
Stars: ✭ 79 (+58%)
Mutual labels:  export, spreadsheet
Spreadsheet architect
Spreadsheet Architect is a library that allows you to create XLSX, ODS, or CSV spreadsheets super easily from ActiveRecord relations, plain Ruby objects, or tabular data.
Stars: ✭ 1,160 (+2220%)
Mutual labels:  export, spreadsheet
medium-editor-handsontable
📊 Handsontable extension for MediumEditor
Stars: ✭ 50 (+0%)
Mutual labels:  spreadsheet
Photostation Upload Lr Plugin
Photo StatLr (aka PhotoStation Upload) is a Lightroom Publish and Export Service Plugin that enables the export /publishing of photos and videos from Lr to a Synology Photo Station. It uploads the photos/videos and all required thumbnails. It can download comments and ratings and do a real two-way synch of various metadata (tags, ratings, labels).
Stars: ✭ 159 (+218%)
Mutual labels:  export
Rats
Movie Ratings Synchronization with Python
Stars: ✭ 156 (+212%)
Mutual labels:  export
PivotHelper
PivotHelper is a utility web app that generates Pivot tables and charts from CSV files and Microsoft Excel spreadsheets.
Stars: ✭ 26 (-48%)
Mutual labels:  spreadsheet
Portphp
Data import/export framework for PHP
Stars: ✭ 225 (+350%)
Mutual labels:  export
Flares
Flares 🔥 is a CloudFlare DNS backup tool
Stars: ✭ 156 (+212%)
Mutual labels:  export
Poi Tl
Generate awesome word(docx) with template
Stars: ✭ 2,306 (+4512%)
Mutual labels:  export
Laravel Translatable String Exporter
Translatable String Exporter for Laravel
Stars: ✭ 149 (+198%)
Mutual labels:  export
open2fa
Two-factor authentication app with import/export for iOS and macOS. All codes encrypted with AES 256. FaceID & TouchID support included. Written with love in SwiftUI ❤️
Stars: ✭ 24 (-52%)
Mutual labels:  export

RODF

Gem Version CI Status RubyGems Downloads Buy Me a Coffee

RODF is a library for writing to ODF output from Ruby. It mainly focuses creating ODS spreadsheets.

As well as writing ODS spreadsheets, this library also can write ODT text documents but it is undocumented and will require knowledge of the ODF spec. It currently does not support ODP Slide shows. Also this is NOT an ODF reading library.

Install

gem install rodf

Usage

RODF works pretty much like Builder, but with ODF-aware constructs. For example:

RODF::Spreadsheet.file("my-spreadsheet.ods") do
  table 'My first table from Ruby' do
    row do
      cell 'Hello world!'
    end
  end
end

For access to variables and methods from outer code you can use block parameter:

@data = 'Hello world!'

RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
  sheet.table 'My first table from Ruby' do |table|
    table.row do |row|
      row.cell @data
    end
  end
end

Adding many rows or cells at once is supported as well:

RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
  sheet.table 'My first table from Ruby' do |t|
    t.add_rows([
      [1, 'Alice'],
      [2, { value: 'Bob', color: '#ff0000'}],
      [3, 'Carol']
    ])

    t.row do |r|
      r.add_cells ['ID', 'Name']
    end
  end
end

Procedural style

The declarative style shown above is just syntatic sugar. A more procedural style can also be used. Like so:

ss = RODF::Spreadsheet.new

t = ss.table 'My first table from Ruby'
r = t.row
c = r.cell 'Hello world!'

# two methods to write to file
ss.write_to 'my-spreadsheet.ods'
# or
File.write('my-spreadsheet.ods', ss.bytes) # you can send your data in Rails over HTTP using the bytes method

Both styles can be mixed and matched at will:

ss = RODF::Spreadsheet.new

ss.table 'My first table from Ruby' do |t|
  t.row do |r|
    r.cell 'Hello world!'
  end
end

ss.write_to 'my-spreadsheet.ods'

Styling and Formatting

RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|

  sheet.style 'red-cell', family: :cell do |s|
    s.property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
  end

  sheet.style 'row-height', family: :row do |s|
    s.property :row, 'row-height' => '18pt', 'use-optimal-row-height' => 'true'
  end

  sheet.table 'Red text table' do |t|
    t.row style: 'row-height' do |r|
      r.cell 'Red', style: 'red-cell'
    end
  end

  sheet.table 'Text with Paragraphs' do |t|
    t.row style: 'row-height' do |r|
      r.cell do |cell|
        cell.paragraph do |paragraph|
          text_array = my_text_content.split("\n").select{|x| !x.empty? }

          text_array.each do |str|
            if str.start_with?("#")
              paragraph.span(str, style: 'red-cell')
            else
              paragraph.span(str)
            end
          end
        end
      end
    end
  end

end

Conditional formatting is also possible:

RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|

  sheet.office_style 'red-cell', family: :cell do |s|
    s.property :text, 'font-weight' => 'bold', 'color' => '#ff0000'
  end

  sheet.office_style 'green-cell', family: :cell do |s|
    s.property :text, 'font-weight' => 'bold', 'color' => '#00ff00'
  end

  # conditional formating must be defined as style and the value of
  # apply-style-name must be an office_style
  sheet.style 'cond1', family: :cell do |s|
    s.property :conditional, 'condition' => 'cell-content()<0', 'apply-style-name' => 'red-cell'

    s.property :conditional, 'condition' => 'cell-content()>0', 'apply-style-name' => 'green-cell'
  end

  sheet.table 'Red text table' do |t|
    t.row do |r|
      r.cell 'Red force', style: 'red-cell'
    end
    t.row do |r|
      r.cell '-4', type: :float, style: 'cond1'
    end
    t.row do |r|
      r.cell '0', type: :float, style: 'cond1'
    end
    t.row do |r|
      r.cell '5', type: :float, style: 'cond1'
    end
  end
end

Changing Columns Widths

Adding columns or columns width to your spreadsheet can be done with the following

RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
  sheet.table "foo" do |t|
    sheet.style('default-col-width', family: :column) do |s|
      s.property(:column, 'column-width' => '1.234in')
    end

    col_count.times do
      t.column style: 'default-col-width'
    end

    ### OR

    ### Warning this will overwrite any existing table columns (cells remain unaffected)
    sheet.set_column_widths(
      table: t, 
      column_widths: [
        {'column-width' => '1in'},
        {'column-width' => '2cm'},
        {'column-width' => '2.54cm'},
      ],
    )
  end
end

Columns Types

Available columns types are:

  • :string
  • :float
  • :date
  • :time
  • :currency
  • :percentage

Style List

### family: :cell or "table-cell"
style "my-cell-style", family: :cell do
  property :text,
    'font-weight' => :bold, #options are :bold, :thin
    'font-size' => 12,
    'font-name' => 'Arial',
    'font-style' => 'italic',
    'text-underline-style' => 'solid', # solid, dashed, dotted, double
    'text-underline-type' => 'single',
    'text-line-through-style' => 'solid',
    align: true,
    color: "#000000"

  property :cell,
    'background-color' => "#DDDDDD",
    'wrap-option' => 'wrap',
    'vertical_align' => 'automatic',
    'border-top' => '0.75pt solid #999999',
    'border-bottom' => '0.75pt solid #999999',
    'border-left' => '0.75pt solid #999999',
    'border-right' => '0.75pt solid #999999',
    'writing-mode' => 'lr-tb',

end

### family: :column or "table-column"
style('my-col-style', family: :column) do
  property :column,
    'column-width' => '4.0cm'
end

### family: :row or "table-row"
style('my-row-style', family: :row) do
  property :row,
    'row-height' => '18pt',
    'use-optimal-row-height' => 'true'
end

### family: :table
style('my-row-style', family: :table) do
  property :table,
    'writing-mode' => 'lr-tb',

Adding Arbitrary XML Attributes

RODF::Spreadsheet.file("my-spreadsheet.ods") do |sheet|
  sheet.table 'My first table from Ruby', attributes: {'table-protected' => 'true'} do |table|
    table.row do |row|
      row.cell @data
    end
  end
end

Production Usage Examples

Credits

Originally Created by @thiagoarrais

Maintained by @westonganger since 2016, for simplified ODS spreadsheet creation within the spreadsheet_architect gem

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].