刷新链接形状的值
Contents
[
Hide
]
有时,您的 Excel 文件中有一个链接形状,该形状链接到某个单元格。在 Microsoft Excel 中,更改链接单元格的值也会更改链接形状的值。如果您想以 XLS 或 XLSX 格式保存工作簿,这也适用于 Aspose.Cells。但是,如果您想以 PDF 或 HTML 格式保存工作簿,则必须调用工作表.getShapes().updateSelectedValue() 方法刷新链接形状的值。
例子
以下屏幕截图显示了以下示例代码中使用的源 Excel 文件。它有一个链接图片1链接到单元格 A1。我们将使用 Aspose.Cells 更改单元格 A1 的值,然后调用[工作表.getShapes().updateSelectedValue()](https://reference.aspose.com/cells/java/com.aspose.cells/shapecollection#updateSelectedValue() 方法刷新值图片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); |