问题描述
我正在尝试使用aspose单元从excel文件中提取ole对象。 尽管在所需位置成功提取了excel文件,但是提取的文件未在excel中打开。 我在打开时收到此味精: Message I am getting when I open the extracted excel file
我也尝试过aspose-cells-20.3和20.8,但存在相同的问题。
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();
}
请帮助。
预先感谢
-Swapnil
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)