请教使用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)
请帮忙解决,谢谢
...全文
31 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧