Hello,
I am using Aspose cells for java 17.8.
Can you please help in achieving the following :
- There is excel document say “a.xlsx” containing some data.
- There is another excel document “b.xlsx” which contains external data from the file “a.xlsx”.
- Using the external linked data there is chart inserted in “b.xlsx”.
- While rendering the chart in “b.xlsx” I want to ensure that chart is always rendered using the latest data in “a.xlsx” file.So if there is any change in the source data in the file “a.xlsx” chart should be rendered using the latest data from the file “a.xlsx”. Currently, in such scenario chart.toPdf() is rendered using the stale data.
Can you please let me know how can I achieve this?
Attached excel files and pdf output for your reference.
documents.zip (31.8 KB)
Thanks,
Neeraj
@neergupta
Thanks for using Aspose APIs.
Please download the source Excel files and the output Pdf file generated by the following code. Please modify this code as per your needs and it should help you resolve this issue.
Download Links:
source Excel files.zip (16.1 KB)
output.pdf (10.2 KB)
Java
//Load workbook that contains your Data
//and change some data inside it
Workbook wbData = new Workbook(dirPath + "Data.xlsx");
Worksheet wsData = wbData.getWorksheets().get(0);
wsData.getCells().get("A3").putValue(44);
//Load workbook that contains your Chart
Workbook wbChart = new Workbook(dirPath + "Chart.xlsx");
//Link your Chart workbook with Data workbook
wbChart.updateLinkedDataSource(new Workbook[] { wbData});
//Calculate the formula
wbChart.calculateFormula();
//Take the image of the chart
//Chart will be updated with new data
Worksheet wsChart = wbChart.getWorksheets().get(0);
Chart ch = wsChart.getCharts().get(0);
ch.toPdf(dirPath + "output.pdf");
C#
//Load workbook that contains your Data
//and change some data inside it
Workbook wbData = new Workbook("Data.xlsx");
Worksheet wsData = wbData.Worksheets[0];
wsData.Cells["A3"].PutValue(44);
//Load workbook that contains your Chart
Workbook wbChart = new Workbook("Chart.xlsx");
//Link your Chart workbook with Data workbook
wbChart.UpdateLinkedDataSource(new Workbook[] { wbData});
//Calculate the formula
wbChart.CalculateFormula();
//Take the image of the chart
//Chart will be updated with new data
Worksheet wsChart = wbChart.Worksheets[0];
Chart ch = wsChart.Charts[0];
ch.ToPdf("out.pdf");