Refresh Values of Linked Shapes
Contents
[
Hide
]
Sometimes, you have a linked shape in your Excel file which is linked to some cell. In Microsoft Excel, changing the value of the linked cell also changes the value of linked shape. This also works fine with Aspose.Cells if you want to save your workbook in XLS or XLSX format. However, if you want to save your workbook in PDF or HTML format, then you will have to call Worksheet.getShapes().updateSelectedValue() method to refresh the value of the linked shape.
Example
The following screenshot shows the source Excel file used in the sample code below. It has a linked Picture 1 linked to cell A1. We will change the value of cell A1 with Aspose.Cells and then call Worksheet.getShapes().updateSelectedValue() method to refresh the value of Picture 1 and save it in PDF format.
You can download the source Excel file and the output PDF from the given links.
Java code to refresh the values of linked shapes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-Java | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(RefreshValuesOfLinkedShapes.class); | |
// Create workbook from source file | |
Workbook workbook = new Workbook(dataDir + "LinkedShape.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.getWorksheets().get(0); | |
// Change the value of cell A1 | |
Cell cell = worksheet.getCells().get("A1"); | |
cell.putValue(100); | |
// Update the value of the Linked Picture which is linked to cell A1 | |
worksheet.getShapes().updateSelectedValue(); | |
// Save the workbook in pdf format | |
workbook.save(dataDir + "output.pdf", SaveFormat.PDF); |