刷新链接形状的值
Contents
[
Hide
]
有时,在您的Excel文件中有一个链接的形状,该形状链接到某个单元格。在Microsoft Excel中,更改链接单元格的值也会更改链接形状的值。如果您想以XLS或XLSX格式保存工作簿,使用Aspose.Cells也可以正常工作。但是,如果您想将工作簿保存为PDF或HTML格式,那么您将需要调用 Worksheet.getShapes().updateSelectedValue() 方法来刷新链接形状的值。
示例
以下屏幕截图显示了下面的示例代码中使用的源Excel文件。它有一个链接的Picture 1与单元格A1相连。我们将使用Aspose.Cells更改单元格A1的值,然后调用Worksheet.getShapes().updateSelectedValue() 方法来刷新Picture 1的值,并以PDF格式保存。
刷新工作表中链接形状的值的Java代码
This file contains 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); |