Java利用Apace POI读取Excel中数据,解析数据
@Test
public void readExcel() throws IOException
{
FileSystemView fsv
= FileSystemView
.getFileSystemView();
String desktop
= fsv
.getHomeDirectory().getPath();
String filePath
= desktop
+ "/template.xls";
FileInputStream fileInputStream
= new FileInputStream(filePath
);
BufferedInputStream bufferedInputStream
= new BufferedInputStream(fileInputStream
);
POIFSFileSystem fileSystem
= new POIFSFileSystem(bufferedInputStream
);
HSSFWorkbook workbook
= new HSSFWorkbook(fileSystem
);
HSSFSheet sheet
= workbook
.getSheet("Sheet1");
int lastRowIndex
= sheet
.getLastRowNum();
System
.out
.println(lastRowIndex
);
for (int i
= 0; i
<= lastRowIndex
; i
++) {
HSSFRow row
= sheet
.getRow(i
);
if (row
== null
) { break; }
short lastCellNum
= row
.getLastCellNum();
for (int j
= 0; j
< lastCellNum
; j
++) {
String cellValue
= row
.getCell(j
).getStringCellValue();
System
.out
.println(cellValue
);
}
}
bufferedInputStream
.close();
}
想要查看如何将数据导入到Excel中----------->Apace POI 将数据导入到Excel
作者:T,Joker.田总 微信公众号:田爸爸服务号 有事Q我:1728569609 后期我会将交流群分享出来 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。