我正在尝试使用aspose单元格从excel文件中提取ole对象。在所需位置成功提取excel文件时,提取的文件不会在excel中打开。我在打开时收到这个消息:打开提取的excel文件时收到的消息
我也试过aspose-cells-20.3和20.8,但问题是一样的。
提取excel文件的代码是:
private static void extractEmbeddedImages(Workbook workbook) throws Exception {
// Get the OleObject Collection in the first worksheet.
OleObjectCollection oles = workbook.getWorksheets().get(0).getOleObjects();
PrintWriter ws=new PrintWriter(new File(sDataDir + "/" + sFileNameWithoutExt + "_EmbeddedFiles.txt"));
//PrintWriter ws=new PrintWriter(new File(sDataDir + "/EmbeddedFiles.txt"));
// Loop through all the ole objects and extract each object. in the worksheet.
for (int i = 0; i < oles.getCount(); i++) {
if(oles.get(i).getUpperLeftColumn() < excludeColFrom) {
if (oles.get(i).getMsoDrawingType() == MsoDrawingType.OLE_OBJECT) {
OleObject ole = (OleObject) oles.get(i);
String sRow=""+ole.getActualLowerRightRow();
com.aspose.cells.Cell cell = workbook.getWorksheets().get(0).getCells().getCell(Integer.parseInt(sRow), ole.getLowerRightColumn());
String sOrgFile=ole.getSourceFullName();
if(sOrgFile == null) //This code is only skipping those file with null resourceFullNme.
{
if(ole.getProgID().equalsIgnoreCase("Bitmap Image"))
sOrgFile = ole.getLowerRightColumn()+ ".jpg";
}
else if(ole.getProgID().equalsIgnoreCase("Acrobat Document"))
sOrgFile = sOrgFile+".pdf";
String sFnamme= new File(sOrgFile).getName();
sFnamme = sFnamme.substring(sFnamme.lastIndexOf("\\")+1);
boolean isExits=isAlreadyExits((Integer.valueOf(sRow)-1)+"_"+sFnamme);
if(isExits)
sFnamme=(Integer.valueOf(sRow)-4)+"_Temp_"+sFnamme;
else
sFnamme=(Integer.valueOf(sRow)-4)+"_"+sFnamme;
FileOutputStream fos;
try {
byte[] data = ole.getObjectData();
if(data != null) {
fos = new FileOutputStream(sDownloadDir + "/" +sFnamme);
try {
fos.write(data);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
fos.close();
ws.println(sFnamme);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}
ws.close();
}
请帮忙。
提前谢谢
-斯瓦普尼尔
暂无答案!
目前还没有任何答案,快来回答吧!