Copy Excel Graph from One Workbook To Another Workbook

Hi,

I want to copy my pivot graph from one workbook to another workbook. In the target workbook there should no reference of source workbook data.

So I need only graph in my final workbook, and also it should be graph not as Image.

Is this possible with aspose.cells??? If yes the how.

I tried to use given example but it copied all source data and source graph also with destination graph.

Regards

Sanjay Kumar Mishra

Hi Sanjay,


I am afraid, it is not possible to copy only the chart without it’s data source to another workbook.
You have to copy the whole workbook and then hide the data source or copy the chart as image.

Anyway, please provide the spreadsheet containing the chart and your current code for further investigation.

Hi Raza,

Thank you for your quick response. I think manually you can do with excel. You can copy the graph and paste in other workbook or other way also. But we don’t want it manually.

Suppose, if we can do this task in same workbook, after paste the graph can we remove the reference or can we delete the data source sheet.

Regards
Sanjay Kumar Mishra


Hi Sanjay,


You can accomplish the task by creating a copy of the source spreadsheet and then removing the worksheet with data source from the copy. Please check the following piece of code and it’s associated spreadsheets as attached. Please note that you will not be able to refresh the Chart without the data source attached.

Java

//Load source spreadsheet
Workbook srcworkbook = new Workbook(“D:/book1.xlsx”);
//Create a new spreadsheet
Workbook desworkbook = new Workbook();
//Copy the contents of the source into destination Workbook
desworkbook.copy(srcworkbook);
//Set the Active Worksheet for destination Workbook to the one containing Chart
desworkbook.getWorksheets().setActiveSheetIndex(1);
//Remove the first Worksheet that contains the data source for the Chart
desworkbook.getWorksheets().removeAt(0);
//Save result
desworkbook.save(“D:/output.xlsx”);