| View previous topic :: View next topic |
| Author |
Message |
JonBL General User

Joined: 04 Mar 2008 Posts: 39
|
Posted: Thu Sep 11, 2008 8:45 pm Post subject: Creating Charts With CellRangeAddress Structure |
|
|
DannyB has published some Python code (http://www.oooforum.org/forum/viewtopic.phtml?p=56037#56037) which illustrates creating a calc chart based upon a named cell range ("A1:B13" in the example). This code adopted for my project works fine.
I've also found some VB code (http://wiki.services.openoffice.org/wiki/Documentation/BASIC_Guide/Structure_of_Charts) which better suites my project, because it employs a CellRangeAddress table structure. My attempt at converting this to Python (as a method declared in a class object) is:
| Code: | def AppendChart(self, _sName):
# Append a chart to the current sheet.
def Rectangle():
oRectangle = self.Doc.createUnoStruct("com.sun.star.awt.Rectangle")
oRectangle.X = 1000
oRectangle.Y = 1000
oRectangle.Width = 50000
oRectangle.Height = 7000
return oRectangle
def RangeAddress():
oRangeAddress = self.Doc.createUnoStruct("com.sun.star.table.CellRangeAddress")
oRangeAddress.Sheet = 0
oRangeAddress.StartColumn = 14
oRangeAddress.StartRow = 1
oRangeAddress.EndColumn = 15
oRangeAddress.EndRow = 20
return oRangeAddress
oCharts = self.oSheet.getCharts()
ra = (RangeAddress())
oCharts.addNewByName(_sName, Rectangle(), ra, True, True)
|
Method createUnoStruct is based upon Python code included in DannyB's OOoLib.py module. The API doco says that the third parameter to method addNewByName is | Quote: | | sequence< CellRangeAddress > | , which I have attempted to implement as tuple ra containing one object created by local procedure RangeAddress.
When I run this, Python responds with a "CannotConvertException" error at the call to method addNewByName. This exception is caused by the third arg ra. I'm missing how to properly specify this arg as a Python object. Can anyone assist? |
|
| Back to top |
|
 |
hanya Super User

Joined: 04 May 2005 Posts: 543 Location: Japan
|
Posted: Thu Sep 11, 2008 9:22 pm Post subject: |
|
|
| Code: | | ra = (RangeAddress(),) |
|
|
| Back to top |
|
 |
JonBL General User

Joined: 04 Mar 2008 Posts: 39
|
Posted: Thu Sep 11, 2008 10:37 pm Post subject: |
|
|
Thanks, Hanya - I'd forgotten the special syntax for creating a singleton tuple. Your reminder fixes my problem.
Regards,
Jon |
|
| Back to top |
|
 |
|