OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Creating Charts With CellRangeAddress Structure

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
JonBL
General User
General User


Joined: 04 Mar 2008
Posts: 39

PostPosted: Thu Sep 11, 2008 8:45 pm    Post subject: Creating Charts With CellRangeAddress Structure Reply with quote

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
View user's profile Send private message
hanya
Super User
Super User


Joined: 04 May 2005
Posts: 543
Location: Japan

PostPosted: Thu Sep 11, 2008 9:22 pm    Post subject: Reply with quote

Code:
ra = (RangeAddress(),)
Back to top
View user's profile Send private message
JonBL
General User
General User


Joined: 04 Mar 2008
Posts: 39

PostPosted: Thu Sep 11, 2008 10:37 pm    Post subject: Reply with quote

Thanks, Hanya - I'd forgotten the special syntax for creating a singleton tuple. Your reminder fixes my problem.

Regards,
Jon
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group