Poi读取excel数据的问题

lynnlovemin
博客专家认证
2012-03-01 06:40:31

private static void read(InputStream inputStream)throws Exception{
HSSFWorkbook workbook = new HSSFWorkbook(inputStream);
for (int sheetindex = 0; sheetindex < workbook.getNumberOfSheets(); sheetindex++) {
HSSFSheet sheet = workbook.getSheetAt(sheetindex);
for (int rowindex = 0; rowindex < sheet.getLastRowNum(); rowindex++) {
HSSFRow row = sheet.getRow(rowindex);
if(null == row)
continue;
for (int cellindex = 0; cellindex < row.getLastCellNum(); cellindex++) {
HSSFCell cell = row.getCell(cellindex);
System.out.print(cell.getRichStringCellValue().getString()+"\t");
}
System.out.println();
}
}
}

public static void main(String[] args) {
InputStream inputStream = null;
try {
inputStream = new FileInputStream(new File("d:\\test.xlsx"));
POIForExcel.read(inputStream);
} catch (Exception e) {
// TODO: handle exception
}finally{
try {
inputStream.close();
} catch (Exception e2) {
// TODO: handle exception
}
}
}


代码如上,为什么控制台没显示数据也没报错
excel绝对有数据
...全文
133 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
游一游走一走 2012-03-02
  • 打赏
  • 举报
回复
1、如楼上所说,不要吞食异常
2、修改以下哪行代码,poi从0开始计数的所以包含sheet.getLastRowNum()那行,没有数据的原因可能里面就已行数据

for (int rowindex = 0; rowindex <=sheet.getLastRowNum(); rowindex++) {
残忍的刀刀 2012-03-01
  • 打赏
  • 举报
回复
public static void main(String[] args) {
InputStream inputStream = null;
try {
inputStream = new FileInputStream(new File("d:\\test.xlsx"));
POIForExcel.read(inputStream);
} catch (Exception e) {
// TODO: handle exception
这个堆栈信息都没打 你怎么能看到报错!! }finally{
try {
inputStream.close();
} catch (Exception e2) {
// TODO: handle exception
}
}
}

lynnlovemin 2012-03-01
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 soflytanny 的回复:]

哥们,你这么写代码,异常在方法里面消化了,既使报错你也看不到啊,
另外,看你文件 "d:\\test.xlsx" 是07以上版本的, HSSFWorkbook是不是支持的,
[/Quote]
但是我用xls也是一样的效果。。
南老頭 2012-03-01
  • 打赏
  • 举报
回复
哥们,你这么写代码,异常在方法里面消化了,既使报错你也看不到啊,
另外,看你文件 "d:\\test.xlsx" 是07以上版本的, HSSFWorkbook是不是支持的,

81,116

社区成员

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

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