请教使用jxl读取Excel的问题
grenn 2003-08-05 10:08:30 import java.io.*;
import jxl.*;
public class TestExcel {
public static void main(String[] args) {
jxl.Workbook rwb = null;
Cell c = null;
try {
rwb = Workbook.getWorkbook(new File("test.xls"));
} catch (Exception e) {
System.err.println(e.getMessage());
}
try {
Sheet rs = rwb.getSheet(0);
int rsCols = rs.getColumns();
int rsRows = rs.getRows();
for (int x = 0 ; x<rsRows; x++) {
String strc = "";
for (int y = 0; y<rsCols; y++) {
c = rs.getCell(y,x);
strc = strc + c.getContents() + " ";
}
System.out.println(strc);
}
} catch(Exception ex) {
ex.printStackTrace();
}
rwb.close();
}
}
编译通过,运行时异常:
Unable to recognize OLE stream
java.lang.NullPointerException
at TestExcel1.main(TestExcel1.java:15)
Exception in thread "main" java.lang.NullPointe
at TestExcel1.main(TestExcel1.java:30)
请帮忙解决,谢谢