import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import org.apache.poi.ss.usermodel.DateUtil;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ReadExcel2007 {
public static void main(String[] args) {
FileInputStream is = null;
String srcFile = "e:/2007.xlsx";
try {
is = new FileInputStream(new File(srcFile));
XSSFWorkbook wb = new XSSFWorkbook(new BufferedInputStream(is));
for (int i = 0; i < wb.getNumberOfSheets(); i++) {// 循环sheet
XSSFSheet childSheet = wb.getSheetAt(i);
for (int j = 0; j <= childSheet.getLastRowNum(); j++) {// 循环该子sheet row
XSSFRow row = childSheet.getRow(j);
if (row != null) {
for (int k = 0; k <= row.getLastCellNum(); k++) {// 循环该子sheet行对应的单元格项
XSSFCell cell = row.getCell(k);// 单元格
if (cell != null) {
switch (cell.getCellType()) {
case XSSFCell.CELL_TYPE_BLANK:
break;
case XSSFCell.CELL_TYPE_ERROR:
break;
case XSSFCell.CELL_TYPE_BOOLEAN:
System.out.print(cell.getBooleanCellValue());
break;
case XSSFCell.CELL_TYPE_FORMULA:// 公式
System.out.print(cell.getNumericCellValue());
break;
case XSSFCell.CELL_TYPE_NUMERIC:
if(DateUtil.isCellDateFormatted(cell)){
System.out.print(cell.getDateCellValue());
}else{
System.out.print(Double.valueOf(cell.getNumericCellValue()).longValue());
}
break;
case XSSFCell.CELL_TYPE_STRING:
System.out.print(cell.getRichStringCellValue());
break;
default:
System.out.print(cell);
}
}
System.out.print(',');
}
System.out.println();
}
}
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
try {
if (is != null) {
is.close();
}
} catch (Exception e) {
}
}
}
}
分享到:
相关推荐
poi读取excel2007和2003兼容工具例子.利用简单工厂方法
解决poi读取excel2007出现内存溢出问题代码参
java poi读取excel 2007 存贮在list中
Java使用apache POI读取xlsx代码以及相关jar包
利用POI读取excel写入到word 利用POI读取excel写入到word 利用POI读取excel写入到word,压缩包里包含了jar包
NULL 博文链接:https://jumpman.iteye.com/blog/1094537
JAVA IO操作 POI读取excel的内容
NULL 博文链接:https://hongqishi.iteye.com/blog/910426
NULL 博文链接:https://tntxia.iteye.com/blog/2017108
NULL 博文链接:https://yxhcquedu.iteye.com/blog/828707
POI读取excel的例子
之前用jxl发现不支持excel2007,不得以就去用poi实现excel的读取了!本人亲测的一个实例,支持excel2007!
apache poi 读取 Excel 的 jar 包 博文链接:https://wxinpeng.iteye.com/blog/231895
实现了JAVA 窗口,读取EXCEL文件,用poi读取EXCEL内容只是一个小例子
poi读取excel并输出到jsp页面
POI生成Excel POI读取Excel java操作Excel Servlet生成Excel web项目,包含含读取Excel与生成Excel方法
poi读取excel所需jar包,可用来使用poi读写word excel。
使用poi读取excel内容 所需jar包
android5使用poi读取excel,android5使用poi读取excel,android5使用poi读取excel,android5使用poi读取excel