リンクされたオブジェクトの表示ラベルへのアクセスと変更
Contents
[
Hide
]
可能な使用シナリオ
Microsoft Excelではスクリーンショットのようにリンクされたオブジェクトの表示ラベルを変更できます。Aspose.Cells APIを使用してリンクされたオブジェクトの表示ラベルにアクセスまたは変更することもできます。OleObject.Labelプロパティを使用してください。
リンクされたオブジェクトの表示ラベルへのアクセスと変更
次のサンプルコードでは、リンクされたオブジェクトを含むsample Excel fileをロードします。このコードでは、Oleオブジェクトにアクセスし、そのラベルを「Sample APIs」から「Aspose APIs」に変更します。以下に示されているコンソール出力を参照してください。これはサンプルエクセルファイルに対するサンプルコードの影響を示しています。
サンプルコード
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