Ruby on Rails
Rails XLS Plugin (Version #21)
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)
INSTALLATION INSTRUCTIONS
- First, YAJB (yet another java bridge) needs to be installed
- You can download YAJB from here
Extract the tar to a temp directory and run setup.rb to install YAJB.
- Next, install the Rails XLS plugin itself into your Rails project: ruby script/plugin install svn://rubyforge.org//var/svn/railsxls/trunk/
Usage
Example Objective: You want to generate a downloadable Excel workbook called mydoc.xls
- Create a controller named main and a view named _make_my_excel_doc_ (i.e. ruby script/generate controller main make_my_excel_doc)
- There is now a file within the app/views/main directory called make_my_excel_doc.rhtml. Rename this file to make_my_excel_doc.rxls. View names must use a .rxls as the extension.
- Open the file main_controller.rb in the app/controllers directory.
- Open the file renamed in Step 2 (make_my_excel_doc.rxls) and delete any text found within the file.
- This rxls file is where you specify what information will end up in your Excel document. The rxls files have access to a built-in object called workbook to manipulate the workbook that will be generated.
- Fire up webrick (or whatever server you have) and navigate to http://localhost:3000/main/make_my_excel_doc and you should be prompted to download your Excel workbook.
- For large Worksheet documents
- To overcome YAJB’s out of process call overhead, a custom Java Helper is bundled with this plugin. This gives pretty much a very fast method to write cells.
- 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.write_to(sheet_object) for cell updates. Call RowGroupBatch.group_rows(sheet_object) 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
Homepage:
http://rubyforge.org/projects/railsxls/
Install with:
ruby script/plugin install svn://rubyforge.org//var/svn/railsxls/trunk/
See also Plugins
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)
INSTALLATION INSTRUCTIONS
- First, YAJB (yet another java bridge) needs to be installed
- You can download YAJB from here
Extract the tar to a temp directory and run setup.rb to install YAJB.
- Next, install the Rails XLS plugin itself into your Rails project: ruby script/plugin install svn://rubyforge.org//var/svn/railsxls/trunk/
Usage
Example Objective: You want to generate a downloadable Excel workbook called mydoc.xls
- Create a controller named main and a view named _make_my_excel_doc_ (i.e. ruby script/generate controller main make_my_excel_doc)
- There is now a file within the app/views/main directory called make_my_excel_doc.rhtml. Rename this file to make_my_excel_doc.rxls. View names must use a .rxls as the extension.
- Open the file main_controller.rb in the app/controllers directory.
- Open the file renamed in Step 2 (make_my_excel_doc.rxls) and delete any text found within the file.
- This rxls file is where you specify what information will end up in your Excel document. The rxls files have access to a built-in object called workbook to manipulate the workbook that will be generated.
- Fire up webrick (or whatever server you have) and navigate to http://localhost:3000/main/make_my_excel_doc and you should be prompted to download your Excel workbook.
- For large Worksheet documents
- To overcome YAJB’s out of process call overhead, a custom Java Helper is bundled with this plugin. This gives pretty much a very fast method to write cells.
- 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.write_to(sheet_object) for cell updates. Call RowGroupBatch.group_rows(sheet_object) 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
Homepage:
http://rubyforge.org/projects/railsxls/
Install with:
ruby script/plugin install svn://rubyforge.org//var/svn/railsxls/trunk/
See also Plugins
Created on July 12, 2007 20:05
by
Paul Danese (216.41.34.85)