Bug 54470

Summary: [PATCH] Solution to support Graph in XSSFWorkbook.cloneSheet method
Product: POI Reporter: Guillaume de GENTILE <gdegentile>
Component: XSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: enhancement CC: bartdt, charleswc, gdegentile, palmerr_2002
Priority: P1 Keywords: PatchAvailable
Version: 3.12-FINAL   
Target Milestone: ---   
Hardware: PC   
OS: All   
Bug Depends on:    
Bug Blocks: 60509    
Attachments: Zip file with updated class and Excel sample template
New patch for POI 3.12

Description Guillaume de GENTILE 2013-01-22 22:24:11 UTC
Created attachment 29885 [details]
Zip file with updated class and Excel sample template

Hi all,

With version 3.9 (and older versions) it is not possible to rename a sheet which contains some graphs, and it is also not possible to copy graphs while cloning a sheet.

I have amended the POI api to support Graph while cloning sheet and also while renaming sheet.

Below the solution I have implemented (note that I am not experienced with the POI api, so it might be possible to perform the same operation in a more official way).

I hope it will be usefull...

Regards,
Guillaume
Comment 1 Dominik Stadler 2015-03-18 20:20:36 UTC
*** Bug 47352 has been marked as a duplicate of this bug. ***
Comment 2 Dominik Stadler 2015-03-18 20:26:42 UTC
*** Bug 57712 has been marked as a duplicate of this bug. ***
Comment 3 sebastian.novak 2015-03-19 10:49:34 UTC
(In reply to Guillaume de GENTILE from comment #0)
> Created attachment 29885 [details]
> Zip file with updated class and Excel sample template
> 
> Hi all,
> 
> With version 3.9 (and older versions) it is not possible to rename a sheet
> which contains some graphs, and it is also not possible to copy graphs while
> cloning a sheet.
> 
> I have amended the POI api to support Graph while cloning sheet and also
> while renaming sheet.
> 
> Below the solution I have implemented (note that I am not experienced with
> the POI api, so it might be possible to perform the same operation in a more
> official way).
> 
> I hope it will be usefull...
> 
> Regards,
> Guillaume

Awesome code~!

I'm attempting to copy chart objects from one workbook to another.
If I manage to clone both the CTChart and the CTChartSpace objects?

Best regards,
Novak
Comment 4 sebastian.novak 2015-03-19 10:51:10 UTC
(In reply to sebastian.novak from comment #3)
> (In reply to Guillaume de GENTILE from comment #0)
> > Created attachment 29885 [details]
> > Zip file with updated class and Excel sample template
> > 
> > Hi all,
> > 
> > With version 3.9 (and older versions) it is not possible to rename a sheet
> > which contains some graphs, and it is also not possible to copy graphs while
> > cloning a sheet.
> > 
> > I have amended the POI api to support Graph while cloning sheet and also
> > while renaming sheet.
> > 
> > Below the solution I have implemented (note that I am not experienced with
> > the POI api, so it might be possible to perform the same operation in a more
> > official way).
> > 
> > I hope it will be usefull...
> > 
> > Regards,
> > Guillaume
> 
> Awesome code~!
> 
> I'm attempting to copy chart objects from one workbook to another.
> If I manage to clone both the CTChart and the CTChartSpace objects?
> 
> Best regards,
> Novak

Would it be possible if I manage to clone both the CTChart and the CTChartSpace objects? *
Comment 5 palmerr_2002 2015-05-23 20:02:55 UTC
Hi there,

I have run the sample code of "Guillaume de GENTILE", and I get new sheet create with the data-table at the top but no chart object.
I get an Exception:
from Method:
updateRelationsSheetName
In class: class XmlNodeUtils
------------------------------------
while(it.hasNext()) {
                	XSSFChart chart = it.next();
                	//System.out.println("chart = " + chart);
                	CTChart c = chart.getCTChart();
                	
             ERROR HERE:  Node node1 = chart.getCTChart().getDomNode();
                	updateDomDocSheetReference(node1, frwb, oldSheetName);

                	Node node2 = chart.getCTChartSpace().getDomNode();
                	updateDomDocSheetReference(node2, frwb, oldSheetName);

                }
                continue;

------------------------------------
Note that the variable/object : c , is not used in the code:
"CTChart c = chart.getCTChart();"

Hope Guillaume can debug this.

Regards,

P
Comment 6 palmerr_2002 2015-05-23 20:08:17 UTC
Hi there,

I have run the sample code of "Guillaume de GENTILE", and I get new sheet create with the data-table at the top but no chart object.
I get an Exception:
from Method:
updateRelationsSheetName
In class: class XmlNodeUtils
------------------------------------
while(it.hasNext()) {
                	XSSFChart chart = it.next();
                	//System.out.println("chart = " + chart);
                	CTChart c = chart.getCTChart();
                	
             ERROR HERE:  Node node1 = chart.getCTChart().getDomNode();
                	updateDomDocSheetReference(node1, frwb, oldSheetName);

                	Node node2 = chart.getCTChartSpace().getDomNode();
                	updateDomDocSheetReference(node2, frwb, oldSheetName);

                }
                continue;

------------------------------------
Note that the variable/object : c , is not used in the code:
"CTChart c = chart.getCTChart();"

Hope Guillaume can debug this.

Regards,

P
Comment 7 Guillaume de GENTILE 2015-05-24 16:24:18 UTC
Hi all,

I have adapted the code to make it compatible with POI 3.12. (consider New ZIP)

With the enclosed path it is possible to rename a Sheet containing a Chart (the Chart  referencees will be correctly refreshed).

Also it is possible to duplicate a Sheet containing charts.

Note that due to a bug in the Apache POI, it is not possible to Clone and rename a Sheet in the same context. The workbook must be closed and reopenned.

See testcase "TestCloneSheet.java" for more details.

Regards,
Guillaume de GENTILE
Comment 8 Guillaume de GENTILE 2015-05-24 16:27:30 UTC
Created attachment 32753 [details]
New patch for POI 3.12

New patch for POI 3.12:

 * Rename Sheet with Chart works fine :)
 * Clone Sheet with Chart works fine :)

Regards,
Guillaume de GENTILE
Comment 9 Javen O'Neal 2016-06-15 09:45:50 UTC
*** Bug 49319 has been marked as a duplicate of this bug. ***
Comment 10 Alain Fagot Bearez 2021-02-25 20:55:39 UTC
The provided patch has been integrated into version 4.1.1 with a correction to be released in version 5.0.1 in response to bug https://bz.apache.org/bugzilla/show_bug.cgi?id=63902