[Solved] Store Writer document as doc/docx

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

[Solved] Store Writer document as doc/docx

Post by _savage »

I've created a Writer document and now I would like to store it. So far I've simply used

Code: Select all

document.storeToURL("file:///path/to/file.odt", ())
document.dispose()
which has worked fine to store the document in odt format. This wiki entry indicates that there are more storage options documented here.

I'd like to store this document in doc or docx format. It seems to work to just change the file extension in the URL, but considering that there are two different kinds of docx export filters, how can I be more precise here? I assume it's got to do with FilterName and perhaps FilterOptions but the documentation seems somewhat sparse.
Last edited by RoryOF on Wed Oct 14, 2015 6:25 pm, edited 2 times in total.
Reason: Added green tick [RoryOF, Moderator]
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Store Writer document as doc/docx

Post by Villeroy »

Recent MSOffice versions support ODF. There is no need to help spreading that pestilence of a file format cynically called "Office Open XML".
Storing an ODF document under a file name ending with .docx does exactly that.
"writer_OOXML" may be a possible filter name (if using LibreOffice).

btw: why don't you tell us the bare minimum about your setup? The office suite? Version? Python language?
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Post by _savage »

Villeroy wrote:Storing an ODF document under a file name ending with .docx does exactly that. "writer_OOXML" may be a possible filter name (if using LibreOffice).
Thanks, I'll try this one. Is that the filter used when I use the .docx file extension?
Villeroy wrote:btw: why don't you tell us the bare minimum about your setup? The office suite? Version? Python language?
I guess that might help ;) Using AOO 4.1.1 and LO 5.0.2 (Mac) and LO 4.4.4.3 (Linux). Python 3.3 (which is what ships as part of the office drops).
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Store Writer document as doc/docx

Post by Villeroy »

Villeroy wrote:Storing an ODF document under a file name ending with .docx does exactly that.
Let your code store an ODF with an arbitrary name suffix (.foo .docx .xdoc .anything or none).
Call menu:File>Properties ... and see that the result of this operation is an ODF document with an unusual name suffix.

OpenOffice can not store .docx (which is a true feature).
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Post by _savage »

I just have to make sure that the document can be opened by people who use Microsoft Word. And sometimes they don't have the latest version of it, so I thought going the .doc route might be the safest thing to do.

Didn't know that I can just rename a .odt to .docx though...
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Store Writer document as doc/docx

Post by Zizi64 »

the document can be opened by people who use Microsoft Word. And sometimes they don't have the latest version of it,
...But they can get the Apache OpenOffice and/or LibreOffice for free...

Always use the International Standard ODF file format, if you want to work efficiently with the open source office suites.
(ISO 26300.2006) https://en.wikipedia.org/wiki/OpenDocument
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Post by _savage »

Zizi64 wrote:...But they can get the Apache OpenOffice and/or LibreOffice for free...
That argument has no relevance. I am not the one who decides how other people work, and what tools they are required/choose to use. As such, I have not much choice in file formats.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Store Writer document as doc/docx

Post by Zizi64 »

I am not the one who decides how other people work,
But you can suggest it. Maybe they do not know this alternative, maybe they never heard about Apache OpenOffice or LibreOffice and the International Document Standard (ODF).
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Store Writer document as doc/docx

Post by RoryOF »

One can set default saving as .doc in /Tools /Options /Load-Save /General by using the "always save as" dropdown. If one needs to ensure that the widest possible audience can read/modify your files (including those who have never progressed beyond MS Office 97) then .doc format is the best choice. If one only requires that they can read the files, send PDF files (/File /Export as PDF).

Note that it is always best to work in OO's native formats (.ODT for text documents) and save as .DOC only when necessary. If using OO's native formats, it is good to be leisurely about the computer shutdown process, as those files take a little longer to write than flat files and there may also be hardware/software file buffering active on your computer.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Post by _savage »

Thanks. Since I generate the documents from a script, it might be an option to save .odt and .doc and have the customer choose which one they'd like to continue with.

But to answer the initial question: changing the file's extension is enough then? No need for further property values?
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Store Writer document as doc/docx

Post by RoryOF »

I cannot answer the specifics of the case (because I'm doing something else), but in general, changing an extension does not change a file structure. The data for the file must be saved through the specific filters for the file. In some cases (often in linux) applications are written which are smart enough to apply such a filter automatically when a differing file extension is selected, but when programming at the macro level one ought not assume this is the case. In Windows almost always changing a file extension leaves the file format of the data in the file unaltered.
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Post by _savage »

Got it. So we're back to: I'll have to use FilterName and FilterOptions, and pass those as PropertyValues? Where can I find a list of available filter options?
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
RoryOF
Moderator
Posts: 34586
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Store Writer document as doc/docx

Post by RoryOF »

See Andrew Pitonyak's works. Be prepared also to dig into the OpenOffice APIs
Apache OpenOffice 4.1.15 on Xubuntu 22.04.4 LTS
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Post by _savage »

Villeroy wrote:"writer_OOXML" may be a possible filter name (if using LibreOffice).
I am not sure this is a correct filter name:

Code: Select all

document.storeToURL("file:///path/to/file.docx", (PropertyValue("FilterName", -1, "writer_OOXML", 0)))
results in a

Code: Select all

__main__.CannotConvertException: conversion not possible!
exception. I'm having a hard time finding a list of available filter names and their respective options.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
User avatar
Zizi64
Volunteer
Posts: 11353
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Store Writer document as doc/docx

Post by Zizi64 »

The Apache OpenOffice have OOXML input filter only, but have not OOXML output filter. You can not save your document from AOO (nor manually, nor programatically) into OOXML format.

Try the LibreOffice, try to record a "save as..." procedure by the Macro recorder. Then you will see the exact name of the OOXML filter in the recorded code.
 Edit: The Macro recorder is disabled by default in the LO.

Tools - Options - LibreOffice - Advanced - Enable macro recorder (limited) 
Last edited by Zizi64 on Wed Oct 14, 2015 5:59 pm, edited 2 times in total.
Tibor Kovacs, Hungary; LO7.5.8 /Win7-10 x64Prof.
PortableApps/winPenPack: LO3.3.0-7.6.2;AOO4.1.14
Please, edit the initial post in the topic: add the word [Solved] at the beginning of the subject line - if your problem has been solved.
User avatar
Villeroy
Volunteer
Posts: 31269
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Store Writer document as doc/docx

Post by Villeroy »

Try "Office Open XML Text" (LibreOffice only) or better "MS Word 97" for more reliable results.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
_savage
Posts: 187
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Post by _savage »

Zizi64 wrote:Try the LibreOffice, try to record a "save as..." procedure by the Macro recorder. Then you will see the exact name of the OOXML filter in the recorded code.
That's a great tip, thank you! Using the recorder I could look at the filter names that were used, and could produce documents in different formats.

For ODT

Code: Select all

pv_filtername = PropertyValue()                                             
pv_filtername.Name = "FilterName"                                           
pv_filtername.Value = "writer8"                                             
document.storeToURL("file:///path/to/file.odt", (pv_filtername,))
For DOCX

Code: Select all

pv_filtername = PropertyValue()                                             
pv_filtername.Name = "FilterName"                                           
pv_filtername.Value = "MS Word 2007 XML"                                    
document.storeToURL("file:///path/to/file.docx", (pv_filtername,))
For DOC

Code: Select all

pv_filtername = PropertyValue()                                             
pv_filtername.Name = "FilterName"                                           
pv_filtername.Value = "MS Word 97"                                          
document.storeToURL("file:///path/to/file.doc", (pv_filtername,))
For Office Open DOCX

Code: Select all

pv_filtername = PropertyValue()                                             
pv_filtername.Name = "FilterName"                                           
pv_filtername.Value = "Office Open XML Text"                                
document.storeToURL("file:///path/to/file.docx", (pv_filtername,))
Addendum. This thread queries the registry for supported file formats that AOO is able to read. Above filter names can be found in that same registry.
Mac 10.14 using LO 7.2.0.2, Gentoo Linux using LO 7.2.3.2 headless.
Post Reply