Plugins - Rails XLS

StarAdd to favorites

Generate XLS documents through the use of ".rxls" views.

Dependencies

  • JDK 1.4 or greater
  • YAJB 0.8.1 or greater
  • Jakarta POI (No need for install. Supplied as part of this package)

Install Instructions for YAJB

You can download YAJB from http://www.cmt.phys.kyushu-u.ac.jp/~M.Sakurai/java/ruby/yajb-0.8.1.tar.gz Extract the tar to a temp directory and run setup.rb to install YAJB.

Usage

In the view template a built-in object called workbook is available to manipulate. View names should use a .rxls as the extension.

# Simple Example

# views/controller_name/report.rxls

sheet = workbook.createSheet("new sheet") row = sheet.createRow(0) row.createCell(0).setCellValue(1) row.createCell(1).setCellValue(1.2) row.createCell(2).setCellValue("This is a Testing Row") row.createCell(3).setCellValue("Guru Krupa")

# controller returns 'default.xls'
def report
   render :action => "report", :layout => false
end

# controller returns 'report.xls'
def report
   @rails_worksheet_name = 'report.xls'
   render :action => "report", :layout => false
end

# For large Worksheet documents

# Use CellBatch to batch the cell inserts/updates

# Use RowGroupBatch to batch the row grouping calls

# When only single sheet is present, the cell as well as row group changes are applied at once aumatically as a single Batch call using a custom java Helper function

# When multiple sheets are present, after doing the sheet specific cell as well as group operations call CellBatch.writeto(sheetobject) for cell updates. Call RowGroupBatch.grouprows(sheetobject) to apply rowGroupings.

# See cell_batch.rb code for options on setting formula cells.

CellBatch.add(5,1,"Row 6 col 1")

CellBatch.add(5,2,"Row 6 col 2")

CellBatch.add(7,1,"Row 8 col 1")

CellBatch.add(8,2,"Row 9 col 2")

RowGroupBatch.add(7,8)

CellBatch.add(9,1,"Two rows above is grouped")

Additional POI Usage Information

See Jakarta POI Project Home Page below for a quick guide on POI Usage

http://jakarta.apache.org/poi/hssf/index.html

Jakarta POI API Doc link is given below:

http://jakarta.apache.org/poi/apidocs/index.html?org/apache/poi/hssf/usermodel/package-summary.html

Venkatasubramaniyan K

http://rubyforge.org/projects/railsxls/

svn://rubyforge.org/var/svn/railsxls

Rails' (MIT)

  • Currently 3.2/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

View Extensions

Tags

Comments

Add a comment
Paul 21 Sep 2007

totally agree w/ adam. if you use the latest version of poi (3.0.1 as I write), you can set column width, row height, etc.)

Adam 10 Jul 2007

I would recommend updating to the latest version of poi as some of the functionality is missing from the 2.5 jar.

Stuart 12 Apr 2007

When you update rails to 1.2 does yajb break your project? it does for mine.. looking for solutions. please email if you have any leads..

Search Plugins

Query syntax

Plugins by Category

Sponsors

Rails Kits: Get Code. Get Moving.

Have a comment?