Sap Portal NetWeaver 7.4: jxl.read.biff.BiffException: 无法识别



我将Web dynpro java 7.0迁移到7.4。我在上传 excel 文件时遇到问题。jxl.read.biff.BiffException: 无法识别 OLE 流

我参考了一个文档"使用示例 Web Dypro for Java 上传 Excel 文件",但我仍然有一个错误。

(我正在使用 Office 2007 保存 AAAA.xls (97-2003) 并上传

file.getAbsolutePath() =/usr/sap/DEP/J00/j2ee/cluster/server0/AAAA.xls )

我尝试在桌面上的 java 项目中使用 jxl.jar,读取 excel 文件 (*.xls) 时还可以

code: Workbook

wb = Workbook.getWorkbook(new File("C:/Users/pcname/Desktop/AAAA.xls"));

但在门户上,它会引发以下异常"无法识别 OLE 流"

代码如下:

type of Va_Resource = com.sap.ide.webdynpro.uielementdefinitions.Resource
     ....
InputStream inpStr = null;
int temp = 0;
File file = new File(wdContext.currentContextElement()
    .getVa_Resource().getResourceName().toString());
 FileOutputStream opStr = new FileOutputStream(file);
 if(wdContext.currentContextElement().getVa_Resource()!=null){
    inpStr = wdContext.currentContextElement().getVa_Resource().read(false);
    while((temp = inpStr.read())!= -1){
        opStr.write(temp);
    }
}
opStr.flush();
opStr.close();
path = file.getAbsolutePath();
       if(path.substring(path.length()-3,path.length()).trim().equalsIgnoreCase("xls"))
{
    //call method for upload
    Execute_UploadOperation();
}
.....
public void Execute_UploadOperation{
    try{
        //path = /usr/sap/DEP/J00/j2ee/cluster/server0/AAAA.xls
        Workbook wb = Workbook.getWorkbook(new File(path)); error this line, throw exception here
....
    }
    catch (BiffException e) {
        e.getMessage() = jxl.read.biff.Biff  Exception: Unable to recognize OLE stream
    }
}

你的编码似乎很好。
您使用什么 Excel 版本?JExcelApi现在已经过时,仅适用于2003之前的Excel版本,上一次更新是在2009年。
将Apache POI用于MS Office的更高版本。

最新更新