刷新链接形状的值
Contents
[
Hide
]
有时,您的Excel文件中有一个链接的形状,该形状链接到某个单元格。在Microsoft Excel中,更改链接单元格的值也会更改链接形状的值。如果要以XLS或XLSX格式保存工作簿,则使用Aspose.Cells也起作用。但是,如果要将工作簿保存为PDF或HTML格式,则必须调用Worksheet.Shapes.UpdateSelectedValue()方法刷新链接形状的值。
示例
以下截图显示了下面示例代码中使用的源Excel文件。其有一个链接图片链接到单元格A1到E4。我们将更改单元格B4的值用Aspose.Cells,然后调用Worksheet.Shapes.UpdateSelectedValue()方法刷新图片的值并将其保存为PDF格式。
您可以从以下链接下载源Excel文件和输出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); |