使用Aspose.Cells自动刷新OLE对象通过Microsoft Excel
Contents
[
Hide
]
Aspose.Cells提供了OleObject.AutoLoad属性,用于在Microsoft Excel中打开excel文件时刷新OLE对象。由于此属性,OLE对象将显示由Microsoft Excel生成的正确的OLE图像。
使用Aspose.Cells自动刷新OLE对象通过Microsoft Excel
以下示例代码加载了包含非真实OLE图像的样本excel文件。OLE对象实际上是Microsoft Word文档,但示例excel文件显示动物图像而不是Microsoft Word图像。但如果您打开输出excel文件,您将看到Microsoft Excel显示正确的OLE图像。
下面的截图显示了在Microsoft Excel中打开时的示例excel文件的样子。
下面的截图显示了在Microsoft Excel中打开时的输出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); |