Sap Portal NetWeaver 7.4: jxl.read.biff.BiffException: Unable to recognize OLE stream

338 Views Asked by At

I migrated web dynpro java 7.0 to 7.4. I have an issue when I upload an excel file. jxl.read.biff.BiffException: Unable to recognize OLE stream

I have reference to a document "Upload Excel File With Example Web Dypro for Java" but I still have an error.

(I'm using office 2007 to save AAAA.xls (97-2003) and upload

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

I tried using jxl.jar in project java application on my desktop, it's ok when reading excel file (*.xls)

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

But on the portal it throws the following exception "Unable to recognize OLE stream"

The code is below:

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
    }
}
1

There are 1 best solutions below

0
On

Your coding seems to be fine.
What Excel version do you use? TheJExcelApi is obsolete now and works only with Excel versions up to 2003, last time it was updated in 2009.
Use Apache POI for latter versions of MS Office.