Access and Modify the Display Label of the Linked Ole Object

Possible Usage Scenarios

Microsoft Excel allows you to change the display label of the Ole Object as shown in the following screenshot. You can also access or modify the display label of the Ole object using Aspose.Cells APIs with the OleObject.Label property.

todo:image_alt_text

Access and Modify the Display Label of the Linked Ole Object

Please see the following sample code, it loads the sample Excel file that contains the Ole Object. The code accesses the Ole Object and changes its Label from Sample APIs to Aspose APIs. Please see the console output given below that shows the effect of the sample code on the sample Excel file for a reference.

Sample Code

// 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());

Console Output

Ole Object Label - Before: Sample APIs

Ole Object Label - After: Aspose APIs