Report in DOC/Word

Hello all,

I need to create a report and export it to Word/DOC in my Rails App…
The problem is that is must be .doc. Can’t be .docx (XML) or RTF and my
app
is in a Linux box.

Somebody can help me with that ??

Thanks,

Marcello P. wrote:

Hello all,

I need to create a report and export it to Word/DOC in my Rails App…
The problem is that is must be .doc. Can’t be .docx (XML) or RTF and my
app
is in a Linux box.

Don’t do this. MS Word documents have no place on the Web and do not
play nice with Web browsers. If you need something editable in MS Word,
use HTML – Word does an incredible job of importing it.

Somebody can help me with that ??

Thanks,

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

OK… I Understand…
But this is a requirement from my client…

On Tue, Sep 29, 2009 at 10:04 AM, Marnen Laibow-Koser <

Marcello P. wrote:

OK… I Understand…
But this is a requirement from my client…

If it were my client, I’d be asking why. The fact that the client
excluded RTF suggests that the client is being unreasonable – I can
think of no use case where RTF shouldn’t be just as good an option as
MS Word format.

On Tue, Sep 29, 2009 at 10:04 AM, Marnen Laibow-Koser <

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On 29 Sep 2009, at 16:13, Marnen Laibow-Koser wrote:

OK… I Understand…
But this is a requirement from my client…

If it were my client, I’d be asking why. The fact that the client
excluded RTF suggests that the client is being unreasonable – I can
think of no use case where RTF shouldn’t be just as good an option
as
MS Word format.

And to put it quite simple: the old Word format is a closed format and
there is no rubygem available for reading or writing Word files on
Linux since no one has gone through the effort of reverse engineering
it (and there are more than enough alternative solutions available
such as RTF and HTML).

Best regards

Peter De Berdt

Peter De Berdt wrote:

On 29 Sep 2009, at 16:13, Marnen Laibow-Koser wrote:

OK… I Understand…
But this is a requirement from my client…

If it were my client, I’d be asking why. The fact that the client
excluded RTF suggests that the client is being unreasonable – I can
think of no use case where RTF shouldn’t be just as good an option
as
MS Word format.

And to put it quite simple: the old Word format is a closed format and
there is no rubygem available for reading or writing Word files on
Linux since no one has gone through the effort of reverse engineering
it (and there are more than enough alternative solutions available
such as RTF and HTML).

I believe you may be incorrect on the reverse-engineering part. Plenty
of other software reads and writes old MS Word files – which means that
someone figured out the spec…

Best regards

Peter De Berdt

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

It can sorta be done but you will need a Windows server running with
Office
installed on it. You’ll then host part of the app there, use some
mechanism
to trigger the word doc build on that machine. You use Win32OLE Ruby
libraries to make Word do your bidding.

http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/241606

In other words, I hope you’re getting paid a lot of money to make this
happen, because it’s simply not possible without going to extraordinary
lengths.

It may sound unhelpful, but the rest of the replies here are really
trying
to get you to fight back on this requirement, as its nearly impossible
to
work with. However, I understand your need and desire to make your
client’s
wishes come true.

Best of luck!

The real reason is that Ruby is open-source, mostly volunteer, and most
people who make things in Ruby don’t tend to use Windows. For example,
I am
probably capable of writing something that would pass, but I’ve got
other
things to do and none of my clients are paying me to write a Word
export.
If I do need one, I’ll write one or pay someone else to write it for me,
or
use the hacky Windows solution I outlined above. Thankfully, as you’ve
suggested, I get my clients to agree to something less difficult to
implement. RTF should be a fine solution.

I wonder what would happen if the OP generated RTF or HTML, gave it a
.doc
extention with the correct content type? I know an HTML table with the
vnd-excel content type opens nicely in Excel. :slight_smile:

On Tue, Sep 29, 2009 at 9:47 AM, Marnen Laibow-Koser <

Brian H. wrote:

It can sorta be done but you will need a Windows server running with
Office
installed on it. You’ll then host part of the app there, use some
mechanism
to trigger the word doc build on that machine. You use Win32OLE Ruby
libraries to make Word do your bidding.

I wonder if you could somehow script OpenOffice to do it without needing
Window or Mac OS to run MS Office. Of course, it’s still a Bad Idea.

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On 29 Sep 2009, at 16:47, Marnen Laibow-Koser wrote:

that
someone figured out the spec…

It’s done through OLE and you need a Windows server for it. Plenty of
examples for that.

You could also try the OpenOffice conversion route, but the number of
hoops and the amount of work you’re getting yourself into is going to
be so staggering I wouldn’t want to be in your place.

Basically, you would have to go through these steps:
• Create an ODT template manually with placeholders, like [%value-to-
replace%]
• When instantiating the template with real data in Ruby, unzip the
template ODT (it’s a zipped XML), and run against the XML the textual
replace of the placeholders with the actual values.
• Zip the ODT back
• Run the conversion ODT -> DOC via OpenOffice command line interface.

Best regards

Peter De Berdt

Peter De Berdt wrote:

On 29 Sep 2009, at 16:47, Marnen Laibow-Koser wrote:

that
someone figured out the spec…

It’s done through OLE and you need a Windows server for it. Plenty of
examples for that.

That’s one way, yes.

You could also try the OpenOffice conversion route, but the number of
hoops and the amount of work you’re getting yourself into is going to
be so staggering I wouldn’t want to be in your place.

Basically, you would have to go through these steps:
• Create an ODT template manually with placeholders, like [%value-to-
replace%]
• When instantiating the template with real data in Ruby, unzip the
template ODT (it’s a zipped XML), and run against the XML the textual
replace of the placeholders with the actual values.
• Zip the ODT back

Doubtful. It should be possible to use OOo’s mail merge feature (if
that’s scriptable) and not generate the XML from scratch.

• Run the conversion ODT → DOC via OpenOffice command line interface.

Best regards

Peter De Berdt

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Peter De Berdt wrote:

On 29 Sep 2009, at 18:23, Marnen Laibow-Koser wrote:

Doubtful. It should be possible to use OOo’s mail merge feature (if
that’s scriptable) and not generate the XML from scratch.

Wish you all the best of luck :slight_smile:

You’ll notice I’m not the one doing it. :slight_smile:

Best regards

Peter De Berdt

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

On 29 Sep 2009, at 18:23, Marnen Laibow-Koser wrote:

Doubtful. It should be possible to use OOo’s mail merge feature (if
that’s scriptable) and not generate the XML from scratch.

Wish you all the best of luck :slight_smile:

Best regards

Peter De Berdt

Peter De Berdt wrote:

On 29 Sep 2009, at 18:23, Marnen Laibow-Koser wrote:

Doubtful. It should be possible to use OOo’s mail merge feature (if
that’s scriptable) and not generate the XML from scratch.

Wish you all the best of luck :slight_smile:

Even (potentially) easier: generate HTML, have OOo convert.

Best regards

Peter De Berdt

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]

Not a pure-ruby solution, but perhaps you could hack up a little web
service that uses http://poi.apache.org/ to do the manipulation, and
talk to it from ruby? Or is there a way to embed a JVM and call Poi
directly?

dwh

This is pretty much exactly what’s done on one of the apps I maintain.
We have a zipped template, which we use together with ruby to generate
(in the same manner as any html template) an .odt open office
document. We then have Star Office (which is pretty much open office)
running on another server which is used to convert the .odt file to
both pdf and doc formats.

This is very unreliable, it breaks often, and is complicated enough
that it essentially runs via ‘black magic’. While the answers others
have given to ‘not ever do this’ aren’t terribly helpful considering
it’s a requirement for you, I have to say, yes it can be done in this
manner, but you should be warned it’s a real world of hurt. If this
wasn’t a feature already implemented before my time, I would be doing
everything in my power to avoid having to do so.

Denis H. wrote:

Not a pure-ruby solution, but perhaps you could hack up a little web
service that uses http://poi.apache.org/ to do the manipulation, and
talk to it from ruby?

Shell interface, maybe?

Or is there a way to embed a JVM and call Poi
directly?

RJB with JRuby.

Note that these ideas, while clever, are all bad ideas (including my
own), because serving MS Word files from a Web app is always a bad idea.

dwh

Best,

Marnen Laibow-Koser
http://www.marnen.org
[email protected]