If anyone can help me, i would like a button that converts html
view(mostly reports with tables) into a document that can open in msword
or openoffice where i can edit it later.
There is an RTF writer for Ruby. YOu would have to program it
yourself, but it looks fairly easy.
Regards
Mikel
You can give a URL to the MS-Word open prompt (never tried it with
OO, but might work, too).
You can also change the content-type of the page (on the server) and
the browser will hand it off to another application.
Content-type:application/vnd.ms-excel
(since you said tables, I’m thinking it’s spreadsheet-like data)
-Rob
Alias wrote:
If anyone can help me, i would like a button that converts html
view(mostly reports with tables) into a document that can open in msword
or openoffice where i can edit it later.
Yes, generating RTF is not difficult. I’ve not used the Ruby RTF
library, but I have used PyRTF which is for Python, and have rolled my
Java own code for RTF generation in a J2EE app. I looked at the RTF spec
and worked out what to write.
Basically, RTF is a rich text format that can be opened in MS Word or
OpenOffice.org. It uses hierarchical tags ( braces: “{” and “}” ) - with
markup, like HTML does, to say how the text should be displayed, e.g.
headings, fonts, tables, etc.
Here’s what you can try:
In the view I assume you’ll have some form(s) to accept some parameters
used to generate the report, e.g. order_no between 100 and 200, etc.
Apart from generating the HTML report views based on this input, write
other methods in your controllers (or write another controller, as
appropriate), which in turn call methods of a model class. This class
can call the Ruby RTF library to generate the report as an RTF file, and
pass the filename back to the controller (or the controller can specify
the filename as an argument to the model method); some path on the
filesystem will have to be decided, where the file(s) generated will be
stored - you can use RAILS_ROOT as the prefix for this. The controller
can then either send the file to the browser using send_file or
send_data (including setting the Content-type, Content-length and
Disposition HTTP headers appropriately).
Vasudev Ram
Dancing Bison Enterprises
Vasudev Ram wrote:
Alias wrote:
If anyone can help me, i would like a button that converts html
view(mostly reports with tables) into a document that can open in msword
or openoffice where i can edit it later.Yes, generating RTF is not difficult. I’ve not used the Ruby RTF
library, but I have used PyRTF which is for Python, and have rolled my
Java own code for RTF generation in a J2EE app. I looked at the RTF spec
and worked out what to write.
Basically, RTF is a rich text format that can be opened in MS Word or
OpenOffice.org. It uses hierarchical tags ( braces: “{” and “}” ) - with
markup, like HTML does, to say how the text should be displayed, e.g.
headings, fonts, tables, etc.Here’s what you can try:
In the view I assume you’ll have some form(s) to accept some parameters
used to generate the report, e.g. order_no between 100 and 200, etc.
Apart from generating the HTML report views based on this input, write
other methods in your controllers (or write another controller, as
appropriate), which in turn call methods of a model class that acts as a ‘manager’ or ‘helper’ class. This class
can call the Ruby RTF library to generate the report as an RTF file and
pass the filename back to the controller (or the controller can specify
the filename as an argument to the model method); some path on the
filesystem will have to be decided, where the file(s) generated will be
stored - you can use RAILS_ROOT as the prefix for this. The controller
can then either send the file to the browser using send_file or
send_data (including setting the Content-type, Content-length and
Disposition HTTP headers appropriately).Vasudev Ram
Dancing Bison Enterprises
http://www.dancingbison.com
http://jugad.livejournal.com
Conversion of other file formats to PDF download | SourceForge.net
P.S.: In the previous post, insert the words " (after calling the
appropriate other model classes to get the needed data from the DB), "
after “generate the report as an RTF file”.
Note: Its not a requirement to have an underlying database table for
each model class in Rails. I’ve seen that some people have this
misunderstanding, so mentioning it. A model class is just a Ruby class,
and can represent any concept or business logic; typical uses are for
‘manager’ or ‘helper’ classes that do something and also talk to the
other table-backed models to do their work, like getting and setting
table data. That’s the pattern I’ve used in my post above.
- Vasudev