Aspose.Cellsを使用してMicrosoft ExcelでOLEオブジェクトを自動的に更新する
Contents
[
Hide
]
Aspose.Cellsは、Microsoft Excelでワークブックを開いたときにOLEオブジェクトを更新するためのOleObject.AutoLoadプロパティを提供します。このプロパティにより、OLEオブジェクトはMicrosoft Excelによって生成された正しいOLEイメージが表示されます。
Aspose.Cellsを使用してMicrosoft ExcelでOLEオブジェクトを自動的に更新する
次のサンプルコードは、非実在のOLEイメージを含むサンプルエクセルファイルをロードします。OLEオブジェクトは実際にはMicrosoft Wordドキュメントですが、サンプルエクセルファイルではMicrosoft Wordのイメージの代わりに動物のイメージが表示されます。ただし、出力エクセルファイルを開くと、Microsoft Excelが正しいOLEイメージを表示します。
次のスクリーンショットは、Microsoft Excelで開いたサンプルエクセルファイルの外観を示しています。
次のスクリーンショットは、Microsoft 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 | |
// The path to the documents directory. | |
String dataDir = Utils.getDataDir(AutomaticallyrefreshOLEobject.class); | |
// Create workbook object from your sample excel file | |
Workbook wb = new Workbook(dataDir + "sample.xlsx"); | |
// Access first worksheet | |
Worksheet sheet = wb.getWorksheets().get(0); | |
// Set auto load property of first ole object to true | |
sheet.getOleObjects().get(0).setAutoLoad(true); | |
// Save the worbook in xlsx format | |
wb.save(dataDir + "output.xlsx", SaveFormat.XLSX); |