[Solved] Store Writer document as doc/docx

The Application Programming Interface and the OASIS Open Document Format

[Solved] Store Writer document as doc/docx

Postby _savage » Tue Oct 13, 2015 8:31 pm

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

Code: Select all   Expand viewCollapse view
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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 143
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Postby Villeroy » Tue Oct 13, 2015 9:20 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24664
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Store Writer document as doc/docx

Postby _savage » Tue Oct 13, 2015 10:01 pm

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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 143
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Postby Villeroy » Tue Oct 13, 2015 10:49 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24664
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Store Writer document as doc/docx

Postby _savage » Wed Oct 14, 2015 7:03 am

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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 143
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Postby Zizi64 » Wed Oct 14, 2015 8:09 am

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; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.3 and AOO4.1.4
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6083
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Store Writer document as doc/docx

Postby _savage » Wed Oct 14, 2015 8:11 am

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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 143
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Postby Zizi64 » Wed Oct 14, 2015 8:48 am

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; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.3 and AOO4.1.4
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6083
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Store Writer document as doc/docx

Postby RoryOF » Wed Oct 14, 2015 10:24 am

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.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25518
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Store Writer document as doc/docx

Postby _savage » Wed Oct 14, 2015 2:29 pm

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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 143
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Postby RoryOF » Wed Oct 14, 2015 2:42 pm

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.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25518
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Store Writer document as doc/docx

Postby _savage » Wed Oct 14, 2015 2:50 pm

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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 143
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Postby RoryOF » Wed Oct 14, 2015 2:52 pm

See Andrew Pitonyak's works. Be prepared also to dig into the OpenOffice APIs
Apache OpenOffice 4.1.4 on Xubuntu 16.04.03 (mostly 64 bit version) and infrequently on Win2K/XP
14 October 2016 was Pooh's 90th birthday
User avatar
RoryOF
Moderator
 
Posts: 25518
Joined: Sat Jan 31, 2009 9:30 pm
Location: Ireland

Re: Store Writer document as doc/docx

Postby _savage » Wed Oct 14, 2015 3:52 pm

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   Expand viewCollapse view
document.storeToURL("file:///path/to/file.docx", (PropertyValue("FilterName", -1, "writer_OOXML", 0)))

results in a

Code: Select all   Expand viewCollapse view
__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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 143
Joined: Sun Apr 21, 2013 12:55 am

Re: Store Writer document as doc/docx

Postby Zizi64 » Wed Oct 14, 2015 5:27 pm

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; LO4.4.7, LO5.3.7 on Win7x64Prof.
PortableApps, WinPenPack: LO3.3.0-LO5.4.3 and AOO4.1.4
Please, edit the topic's initial post, and add the word "[Solved]" at the beginning of the subject line - if your problem has been solved.
User avatar
Zizi64
Volunteer
 
Posts: 6083
Joined: Wed May 26, 2010 7:55 am
Location: Budapest, Hungary

Re: Store Writer document as doc/docx

Postby Villeroy » Wed Oct 14, 2015 5:47 pm

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 16.04, OpenOffice 4.x & LibreOffice 5.x
User avatar
Villeroy
Volunteer
 
Posts: 24664
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: Store Writer document as doc/docx

Postby _savage » Wed Oct 14, 2015 6:18 pm

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   Expand viewCollapse view
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   Expand viewCollapse view
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   Expand viewCollapse view
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   Expand viewCollapse view
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.11 using LO 5.3.6.1, Gentoo Linux using LO 5.3.4.2 headless.
_savage
 
Posts: 143
Joined: Sun Apr 21, 2013 12:55 am


Return to UNO API and ODF

Who is online

Users browsing this forum: No registered users and 3 guests