[Solved] Chart - Modify referenced sheet

Creating a macro - Writing a Script - Using the API (OpenOffice Basic, Python, BeanShell, JavaScript)
Post Reply
kebab4you
Posts: 7
Joined: Thu Jul 09, 2015 4:40 pm

[Solved] Chart - Modify referenced sheet

Post by kebab4you »

Did some reading and there doesn't seem to be any way that I can get a chart to reference the current sheet it's located on through the normal interface. What I would like to do is after I copied a sheet with the copyByName() function to loop through all charts on the copied sheet and tell them to reference the copied sheet instead of the original. Looping through all the charts I know how to do but I can't figure out how to modify what sheet the chart reads from.
Last edited by kebab4you on Thu Aug 06, 2015 7:39 pm, edited 2 times in total.
OpenOffice 4.1.1
Windows 7
User avatar
MTP
Volunteer
Posts: 1620
Joined: Mon Sep 10, 2012 7:31 pm
Location: Midwest USA

Re: [Calc] Chart - Modify referenced sheet

Post by MTP »

You'll probably need to poke around inside the chart object with Xray or MRI ([Tutorial] Introduction into object inspection with MRI) to figure out what property to change.

Graphs are actually really complicated objects. You might get some ideas from the few examples of creating or editing them with macros on these forums:
Code example for XY chart (original)
Code example for bar chart (modified from XY code)
OpenOffice 4.1.1 on Windows 10, HSQLDB 1.8 split database
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Chart - Modify referenced sheet

Post by Villeroy »

Do you know scenarios? http://forum.openoffice.org/en/forum/do ... hp?id=3004 (One chart with exchangable source ranges)
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
kebab4you
Posts: 7
Joined: Thu Jul 09, 2015 4:40 pm

Re: [Calc] Chart - Modify referenced sheet

Post by kebab4you »

MTP wrote:You'll probably need to poke around inside the chart object with Xray or MRI ([Tutorial] Introduction into object inspection with MRI) to figure out what property to change.

Graphs are actually really complicated objects. You might get some ideas from the few examples of creating or editing them with macros on these forums:
Code example for XY chart (original)
Code example for bar chart (modified from XY code)
Thank you, will take a look at it.
Villeroy wrote:Do you know scenarios? http://forum.openoffice.org/en/forum/do ... hp?id=3004 (One chart with exchangable source ranges)
Yeah read about it from another topic that you had commented on. From the sounds of it it's something the user have to activate for each sheet which won't work for me because I'm dealing with another end-user.
OpenOffice 4.1.1
Windows 7
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Calc] Chart - Modify referenced sheet

Post by Villeroy »

kebab4you wrote:Yeah read about it from another topic that you had commented on. From the sounds of it it's something the user have to activate for each sheet which won't work for me because I'm dealing with another end-user.
There is only one visible sheet with one chart and one source range reflecting different data sets you can choose from a list box or from the navigator tool.
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
kebab4you
Posts: 7
Joined: Thu Jul 09, 2015 4:40 pm

Re: [Calc] Chart - Modify referenced sheet

Post by kebab4you »

Solved it in quite an easy matter with the following:

Code: Select all

Do While I < 2
		oChart = oCopy.Charts.getByIndex(I)
		Ranges = oChart.Ranges
		Ranges(0).Sheet = oCopy.RangeAddress.Sheet
		oChart.Ranges = Ranges
		I = I+1
	Loop
Haven't found a way to get a count on all charts that are on the page yet so I'm using the hardcoded value of 2. Since I only have two charts at the moment.
OpenOffice 4.1.1
Windows 7
User avatar
Villeroy
Volunteer
Posts: 31279
Joined: Mon Oct 08, 2007 1:35 am
Location: Germany

Re: [Solved] Chart - Modify referenced sheet

Post by Villeroy »

Well yes, that's what scenarios do without a single line of Basic code
or if you want to:

Code: Select all

objSheet.Scenarios.getByName("Plan_B").apply()
Please, edit this topic's initial post and add "[Solved]" to the subject line if your problem has been solved.
Ubuntu 18.04 with LibreOffice 6.0, latest OpenOffice and LibreOffice
Post Reply