请教使用jxl读取Excel的问题

grenn grenn 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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)
请帮忙解决,谢谢
...全文
评论
收藏 已收藏
分享
返回顶部
grenn
Web 开发 81,108 成员 341,721 内容