访问和修改链接 Ole 对象的显示标签
Contents
[
Hide
]
可能的使用场景
Microsoft Excel 允许您更改 Ole 对象的显示标签,如以下屏幕截图所示。您还可以使用 Aspose.Cells API 访问或修改 Ole 对象的显示标签OleObject.标签财产。
访问和修改链接 Ole 对象的显示标签
请看下面的示例代码,它加载了示例 Excel 文件包含 Ole 对象。该代码访问 Ole 对象并将其标签从示例 API 更改为 Aspose API。请查看下面给出的控制台输出,其中显示了示例代码对示例 Excel 文件的影响,以供参考。
示例代码
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 | |
//Load the sample Excel file | |
Workbook wb = new Workbook("sampleAccessAndModifyLabelOfOleObject.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.Worksheets[0]; | |
//Access first Ole Object | |
Aspose.Cells.Drawing.OleObject oleObject = ws.OleObjects[0]; | |
//Display the Label of the Ole Object | |
Console.WriteLine("Ole Object Label - Before: " + oleObject.Label); | |
//Modify the Label of the Ole Object | |
oleObject.Label = "Aspose APIs"; | |
//Save workbook to memory stream | |
MemoryStream ms = new MemoryStream(); | |
wb.Save(ms, SaveFormat.Xlsx); | |
//Set the workbook reference to null | |
wb = null; | |
//Load workbook from memory stream | |
wb = new Workbook(ms); | |
//Access first worksheet | |
ws = wb.Worksheets[0]; | |
//Access first Ole Object | |
oleObject = ws.OleObjects[0]; | |
//Display the Label of the Ole Object that has been modified earlier | |
Console.WriteLine("Ole Object Label - After: " + oleObject.Label); |
控制台输出
Ole Object Label - Before: Sample APIs
Ole Object Label - After: Aspose APIs