刷新链接形状的值
Contents
[
Hide
]
有时,您的 Excel 文件中有一个链接形状,该形状链接到某个单元格。在 Microsoft Excel 中,更改链接单元格的值也会更改链接形状的值。如果您想以 XLS 或 XLSX 格式保存工作簿,这也适用于 Aspose.Cells。但是,如果您想以 PDF 或 HTML 格式保存工作簿,则必须调用工作表.Shapes.UpdateSelectedValue()方法刷新链接形状的值。
例子
以下屏幕截图显示了以下示例代码中使用的源 Excel 文件。它具有链接到单元格 A1 到 E4 的链接图片。我们将使用 Aspose.Cells 更改单元格 B4 的值,然后调用工作表.Shapes.UpdateSelectedValue()方法刷新图片的值,保存为PDF格式。
C# 刷新链接形状值的代码
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-.NET | |
//Source directory | |
string sourceDir = RunExamples.Get_SourceDirectory(); | |
//Output directory | |
string outputDir = RunExamples.Get_OutputDirectory(); | |
// Create workbook from source file | |
Workbook workbook = new Workbook(sourceDir + "sampleRefreshValueOfLinkedShapes.xlsx"); | |
// Access first worksheet | |
Worksheet worksheet = workbook.Worksheets[0]; | |
// Change the value of cell B4 | |
Cell cell = worksheet.Cells["B4"]; | |
cell.PutValue(100); | |
// Update the value of the Linked Picture which is linked to cell B4 | |
worksheet.Shapes.UpdateSelectedValue(); | |
// Save the workbook in PDF format | |
workbook.Save(outputDir + "outputRefreshValueOfLinkedShapes.pdf", SaveFormat.Pdf); |