PyUno - CSV Opening With Writer
Stephan Bergmann
sbergman at redhat.com
Mon Jan 21 03:54:53 PST 2013
On 01/18/2013 04:05 PM, Joel Madero wrote:
> I wanted to get some help trying to get pyuno to behave. Trying to
> automate our stats with pyuno :) The csv file opens with write no matter
> what I do to try to get it to open with spreadsheet. Thanks all.
>
> import uno
>
> # get the uno component context from the PyUNO runtime
> localContext = uno.getComponentContext()
>
> # create the UnoUrlResolver
> resolver = localContext.ServiceManager.createInstanceWithContext(
> "com.sun.star.bridge.UnoUrlResolver",
> localContext)
>
> # connect to the running office
> ctx =
> resolver.resolve("uno:pipe,name=pypipe;urp;StarOffice.ComponentContext")
> smgr = ctx.ServiceManager
>
>
>
> # get the central desktop object
> DESKTOP =smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)
>
> #The calling it's not exactly this way, just to simplify the code
> DESKTOP.loadComponentFromURL('/data/Joel_Documents/Work/Non-Profit/Libre-Office/FDOBugs/PerDay/2013_01_15.csv',"_blank",0,(),FilterName="Text
> - txt - csv
> (StarCalc)",DocumentService="com.sun.star.sheet.SpreadsheetDocument")
The above passes optional additional named arguments FilterName and
DocumentService into the Python loadComponentFromURL function call,
which appear to be silently ignored when "converting" that Python
function call into a call of the UNO method
com.sun.star.frame.XComponentLoader.loadComponentFromURL(
[in] string URL,
[in] string TargetFrameName,
[in] long SearchFlags,
[in] sequence<com::sun::star::beans::PropertyValue> Arguments)
That is, instead of an empty Arguments sequence ("()") you'll want to
pass in a Python sequence consisting of two ProperyValues, something like
> from com.sun.star.beans import PropertyValue
> from com.sun.star.beans.PropertyState import DIRECT_VALUE
>
> ...
>
> DESKTOP.loadComponentFromURL("file:///data/Joel_...", "_blank", 0, (PropertyValue("FilterName", -1, "Text - txt - csv (StarCalc)", DIRECT_VALUE), PropertyValue("DocumentService", -1, "com.sun.star.sheet.SpreadsheetDocument", DIRECT_VALUE)))
(note that the first argument, URL, should also better be an absolute
URL). (That said, the example code keeps opening the document in Calc
with my local master build anyway, regardless of whatever Arguments I pass.)
Stephan
More information about the LibreOffice
mailing list