Re: [ruby_ireland] Create Word Documents using Ruby on Rails

1,077 views
Skip to first unread message

Jamie Lawrence

unread,
Oct 11, 2012, 2:15:32 PM10/11/12
to ruby_i...@googlegroups.com
There was a previous thread on this topic almost exactly a year ago (25/10/11). I assume it's an annual class project? I think the advice in that thread still stands. If you want a hosted service, try DocRaptor — not sure if it does RTF/Word files though. 

If you create a Stackoverflow question with specific pieces of code, what you've tried and the error messages you've receieved, then I'm sure others will help you out. 

  Jamie

_______________________
http://ideasasylum.com
@ideasasylum

On Thursday 11 October 2012 at 17:52, Anushank Lal wrote:

Hi,

I am working on Rails project in which I have to generate Docx and RTF document retrieving  data from the Active Records.In those document, I have to show data in the form of charts, graph and tables.

So, on googling i got this http://stackoverflow.com/questions/697505/creating-microsoft-word-docx-documents-in-ruby. Then i tried almost each and every way but nothing helps to achieve my goal.Like

But nothing help.


So, what i am thinking use any open source Rest API which takes xml data and word (docx) as template and generate Word Document, just like Saaspose.

Is, i am going right or there are other ways to do it.Please help 

Thanks in Advance.

--
You received this message because you are subscribed to the Google Groups "Ruby Ireland" group.
To view this discussion on the web, visit https://groups.google.com/d/msg/ruby_ireland/-/yRtRhsdbzL8J.
To post to this group, send an email to ruby_i...@googlegroups.com.
To unsubscribe from this group, send email to ruby_ireland...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/ruby_ireland?hl=en-GB.

Anushank Lal

unread,
Oct 12, 2012, 4:00:04 AM10/12/12
to ruby_i...@googlegroups.com
     
   Thanks for reply. It's a self project for skills building in Reporting. I have already seen that thread and almost implemented each way and it doesn't     satisfied my needs. Some has problems in styles and displaying charts.
In RTF Ruby Library, whether I am not getting how to add styles and dynamic tables or it doesn't support that. So, all this me to nowhere. Docraptor is a paid API and also doesn't support RTW/word files.
So, i trying to get from stackoverflow peoples. if you any ideas please share it.  

Justin Corry

unread,
Oct 12, 2012, 5:55:27 AM10/12/12
to ruby_i...@googlegroups.com
One basic method is as follows -

docx documents are basically just zipped up XML. The general approach should be
1. Use MS-Word to create a document that looks like the one you would like to produce.
2. Use 7-zip or similar to unzip the docx file.
3. Inspect the contents of the XML files. Get an understanding of the XML by manually editing the XML until you can make the chart change as you require (far from trivial).
4. Have your rails app generate XML in the format required by MS-Word.  Use the XML generated by MS-WORD as a template for you rails app. 
5. Zip your output.

Note: for charts a docx will typically include an excel (xlsx) document in the "\word\embeddings\" folder. This too can be unzipped.

Marcin Wyszyński

unread,
Oct 12, 2012, 6:29:07 AM10/12/12
to ruby_i...@googlegroups.com
3. Inspect the contents of the XML files. Get an understanding of the XML by manually editing the XML until you can make the chart change as you require (far from trivial).

Perhaps an easier way would be to generate charts as images from Ruby and then embed them in the document.

Marcin
Reply all
Reply to author
Forward
0 new messages