1

I have now succeeded in opening a Word 97-2003 (.doc) document and edited it from Python. But how do I save it?

I always get:

Traceback (most recent call last):
  File "office.py", line 55, in <module>
    model.storeToUrl('file:///c:/temp/out.doc', ())
AttributeError: storeToUrl

(Related question.)

What should the attributes be?

And how do I then close the document?

Community
  • 1
  • 1
Prof. Falken
  • 24,226
  • 19
  • 100
  • 173
  • So you had a typo in your function name. It's storeToURL with "URL" capitalized and not as I can see in your traceback "storeToUrl". Saying that would have save a bit of my lifetime! – Emilio Conte Oct 01 '15 at 07:48
  • @BastienRoques, say again? I don't understand what you mean. What traceback? – Prof. Falken Oct 01 '15 at 08:05
  • 1
    Yesterday, I had the same issue as you had and as far as I can see, your issue came from a typo. You typed "storeToUrl" instead of "storeTo**URL**". Anyway, I'm quite glad to have solved the problem... I can't believed I've lost half a day with that ! – Emilio Conte Oct 01 '15 at 09:01

2 Answers2

2

The other answer is all over the net, and is very confusing. In some examples, model is the TEXT object, storeToURL() and dispose() are methods of the document object, here is another implementation.

from com.sun.star.beans import PropertyValue
from unohelper import systemPathToFileURL

# open a writer document object
doc = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, ())

.....

url = systemPathToFileUrl('c:/out.doc')

# NOTE THAT ARGS IS A TUPLE OF PROPERTY VALUES
args = (PropertyValue('FilterName', 0, 'MS Word 97', 0),)

doc.storeToURL(url, args)

# close the document
doc.dispose()
frage
  • 719
  • 7
  • 15
1
model.storeToURL('file:///c:/temp/out.doc', (createPropertyValue("FilterName","MS Word 97"),) 

Note the all caps on "URL", in my original code it was spelled wrong, like "Url".

Prof. Falken
  • 24,226
  • 19
  • 100
  • 173