Load files into Writer only?

Jens Tröger schreef op 15/03/2015 om 14:02:

Thank you, Fernand!

    document = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, ())
    here you do not use any property value for opening "()"

Correct in this line, and the next few lines of code are:

    >>> from com.sun.star.beans import PropertyValue
    >>> propVal = PropertyValue()
    >>> propVal.Name = "URL" # or "FileName"?
    >>> propVal.Value = "file:///path/to/document.odt"
    >>> document.load( (propVal,) )
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    __main__.DoubleInitializationException

I have also tried to pass a property list directly to the call above,
but that just opened an empty Writer document:

    >>> document = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, (propVal,))

Perhaps "URL" or "FileName" are not the correct properties to open a
file?

    your solution to open a writer doc is the "filter" property
    there are other available like "Hiden" ect..

Yes, all documented here:

   https://wiki.openoffice.org/wiki/Documentation/DevGuide/OfficeDev/Handling_Documents#MediaDescriptor

        dim oProps(0) as new com.sun.star.beans.PropertyValue
            oProps2(1).Name = "FilterName"
            oProps2(1).Value = "HTML (StarWriter)"
    document = desktop.loadComponentFromURL("private:factory/swriter", "_blank", 0, oProps())
        Hope it helps
    Fernand

In this your example, how do you pass the actual document file name?

just replace

"private:factory/swriter" with the URL of your document , be sure its a URL bij converting it

using a OO native function: example converttoURL("c:\myfile.odt")

hope it helps

Fernand