-1

I have a problem in uploading excel file, my Java code below

File newFile = new File("C:/sample.xls");
int firstColNo = 0;
int row = 0;
Cell cell;
Workbook wb = Workbook.getWorkbook(newFile);
Sheet sheet = wb.getSheet(0);
    for (row = 1; row < 1005; row++) {
        LabelCell labelCell1 = sheet.findLabelCell("COMPOUND_ID");
            if (labelCell1 != null) {
                firstColNo = labelCell1.getColumn();
                cell = sheet.getCell(firstColNo, row);
                    if (cell.getContents() != null && cell.getContents().length() > 0) {                                            System.out.println(cell.getContents());
                } else {
                                        System.out.println("-");
                                    }
                                }
                            }

When I debug it I'm getting this exception

jxl.read.biff.BiffException: Unable to recognize OLE stream
    at jxl.read.biff.CompoundFile.<init>(CompoundFile.java:116)
    at jxl.read.biff.File.<init>(File.java:127)
    at jxl.Workbook.getWorkbook(Workbook.java:221)
    at jxl.Workbook.getWorkbook(Workbook.java:198)
    at hello.FileUploadExample.doPost(FileUploadExample.java:63)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:225)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:927)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1001)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:579)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:312)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
    at java.lang.Thread.run(Thread.java:722)

I'm using jxl.jar file for file upload.

Can anyone help me to solve it?

Dave
  • 8,163
  • 11
  • 67
  • 103
user2405204
  • 1
  • 1
  • 2

1 Answers1

0

On the stacktrace it is the

at jxl.Workbook.getWorkbook(Workbook.java:198)

which is called in your code at

Workbook wb = Workbook.getWorkbook(newFile);

I have used POI and other excel library, not this , but it seems at that point can be a FileNotFoundException converted to a jxl.read.biff.BiffException or the library doesn't recognize the input file format.- because you gave a plain.txt renamed to .xls

Pls do a verification at least the Java level

if(!newFile.isFile()){
    return;
}

also you can check the length to not be 0 and so on.

Maybe this can be your solution.

I hope it helps you to find a direction.

Community
  • 1
  • 1