python and loadComponentFromURL()

View: New views
2 Messages — Rating Filter:   Alert me  

python and loadComponentFromURL()

by John Gleeson-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Open Office Support:

I am developing a python program that will allow a cell
to be filled in with arbitrary text for a specified spreadsheet
file and cell.

I am developing on Solaris 10 x86. I plan on deploying
on Solaris 10 SPARC. I downloaded OO about 2 weeks
ago. I downloaded the OO SDK this week.

I have attached the program. It is as simple as I could make
it for demonstration purposes.

I use this command line to test it:
/opt/openoffice.org3/program/python z.py /tmp/T2.ods A1 johnny

This should put "johnny" into the cell at A1 in the spreadsheet (file)
/tmp/T2.ods.

I am getting this output:
after localContext
after localResolver
after context
after desktop
url = file:///tmp/T2.ods
failed to load spreadsheet. error is <type 'exceptions.NameError'>

I do not understand why I am getting this error. My code is based
on example code that is doing the same things.

If I switch the "Doc " assignment to the one that is commented out
in the attached version, I get "Abort(coredump)".

Am I doing something wrong? Are there known issues with what
I am trying to use?


Any pointers you might be able to provide are greatly appreciated.


Regards,
John Gleeson
Software Technologies Group, Inc.
+1.708.547.0110








#!/opt/openoffice.org3/program/python

import uno
from com.sun.star.beans import PropertyValue


import sys

if (len(sys.argv) < 4) :
        print >> sys.stderr, "usage: command spreadsheet cell text"
        sys.exit(1)

OO_PORT = 8100

docName = sys.argv[1]
cellId = sys.argv[2]
cellText = sys.argv[3]


try :
        localContext = uno.getComponentContext()
        localContext
except :
        print >> sys.stderr, "failed to get local context"
        sys.exit(1)

localServiceManager = localContext.ServiceManager
print "after localContext"

try :
        localResolver = localContext.ServiceManager.createInstanceWithContext("com.sun.star.bridge.UnoUrlResolver", localContext)
except :
        print >> sys.stderr, "failed to get local resolver"
        sys.exit(1)

print "after localResolver"

try :
        context = localResolver.resolve("uno:socket,host=localhost,port=%d;urp;StarOffice.ComponentContext" % OO_PORT)
except :
        print >> sys.stderr, "failed to connect to OpenOffice on port %d" % OO_PORT
        sys.exit(1)

serviceManager = context.ServiceManager
print "after context"

try :
        desktop = serviceManager.createInstance("com.sun.star.frame.Desktop")
except :
        print >> sys.stderr, "failed to create desktop context"
        sys.exit(1)

print "after desktop"

url = uno.systemPathToFileUrl(docName)
print "url = " + url
hidden = PropertyValue()
hidden.Name = "Hidden"
hidden.Value = True
Properties = [hidden]

try :
        Doc = desktop.loadComponentFromURL(url, "_blank", 0, Properties)
        #Doc = desktop.loadComponentFromURL(url, "_blank", 0, (createPropertyValue("Hidden", True),))
except :
        print >> sys.stderr, "failed to load spreadsheet. error is", sys.exc_info()[0]
        sys.exit(1)

print "after Doc"


Sheet = Doc.Sheets.getByName(form)
print "after Sheet"

Cell = Sheet.getCellRangeByName(cellId)
Cell.String = cellText
print "after cell assignment"

Doc.close(True)
print "after close"

sys.exit(0)



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...

Re: python and loadComponentFromURL()

by Joerg Budischewski :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

python lists are not supported, use tuples instead. Try to change the line

Properties = [hidden]

to

Properties = hidden,

and try again.

Bye,

Joerg

John Gleeson schrieb:

>
> Open Office Support:
>
> I am developing a python program that will allow a cell
> to be filled in with arbitrary text for a specified spreadsheet
> file and cell.
>
> I am developing on Solaris 10 x86. I plan on deploying
> on Solaris 10 SPARC. I downloaded OO about 2 weeks
> ago. I downloaded the OO SDK this week.
>
> I have attached the program. It is as simple as I could make
> it for demonstration purposes.
>
> I use this command line to test it:
> /opt/openoffice.org3/program/python z.py /tmp/T2.ods A1 johnny
>
> This should put "johnny" into the cell at A1 in the spreadsheet (file)
> /tmp/T2.ods.
>
> I am getting this output:
> after localContext
> after localResolver
> after context
> after desktop
> url = file:///tmp/T2.ods
> failed to load spreadsheet. error is <type 'exceptions.NameError'>
>
> I do not understand why I am getting this error. My code is based
> on example code that is doing the same things.
>
> If I switch the "Doc " assignment to the one that is commented out
> in the attached version, I get "Abort(coredump)".
>
> Am I doing something wrong? Are there known issues with what
> I am trying to use?
>
>
> Any pointers you might be able to provide are greatly appreciated.
>
>
> Regards,
> John Gleeson
> Software Technologies Group, Inc.
> +1.708.547.0110
>
>
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@...
> For additional commands, e-mail: dev-help@...


---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@...
For additional commands, e-mail: dev-help@...