访问和修改链接的OLE对象的显示标签
Contents
[
Hide
]
可能的使用场景
Microsoft Excel允许您更改OLE对象的显示标签,如下截图所示。您还可以使用Aspose.Cells API访问或修改OLE对象的显示标签,OleObject.Label属性。
访问和修改链接的OLE对象的显示标签
请参阅以下示例代码,它加载包含OLE对象的sample Excel文件。该代码访问OLE对象并将其标签从Sample APIs更改为Aspose APIs。请参阅下面给出的控制台输出,显示示例代码对示例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-Java | |
//Load the sample Excel file | |
Workbook wb = new Workbook("sampleAccessAndModifyLabelOfOleObject.xlsx"); | |
//Access first worksheet | |
Worksheet ws = wb.getWorksheets().get(0); | |
//Access first Ole Object | |
OleObject oleObject = ws.getOleObjects().get(0); | |
//Display the Label of the Ole Object | |
System.out.println("Ole Object Label - Before: " + oleObject.getLabel()); | |
//Modify the Label of the Ole Object | |
oleObject.setLabel("Aspose APIs"); | |
//Save workbook to byte array output stream | |
ByteArrayOutputStream baos = new ByteArrayOutputStream(); | |
wb.save(baos, SaveFormat.XLSX); | |
//Convert output to input stream | |
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); | |
//Set the workbook reference to null | |
wb = null; | |
//Load workbook from byte array input stream | |
wb = new Workbook(bais); | |
//Access first worksheet | |
ws = wb.getWorksheets().get(0); | |
//Access first Ole Object | |
oleObject = ws.getOleObjects().get(0); | |
//Display the Label of the Ole Object that has been modified earlier | |
System.out.println("Ole Object Label - After: " + oleObject.getLabel()); |
控制台输出
Ole Object Label - Before: Sample APIs
Ole Object Label - After: Aspose APIs