package com.reus; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; import java.util.TimeZone; import org.apache.poi.xssf.usermodel.XSSFRow; import org.apache.poi.xssf.usermodel.XSSFSheet; import org.apache.poi.xssf.usermodel.XSSFWorkbook; public class ExcelOperate { public static void main(String[] args) { SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss:SS"); TimeZone t = sdf.getTimeZone(); t.setRawOffset(0); sdf.setTimeZone(t); Long startTime = System.currentTimeMillis(); String fileName = "E:\\b.xlsx"; // 检测代码 try { // PoiReadExcel er = new PoiReadExcel(); // 读取excel2007 testPoiExcel2007(fileName); } catch (Exception ex) { // Logger.getLogger(FastexcelReadExcel.class.getName()).log(Level.SEVERE, null, ex); } Long endTime = System.currentTimeMillis(); System.out.println("用时:" + sdf.format(new Date(endTime - startTime))); } @SuppressWarnings("resource") public static void testPoiExcel2007(String strPath) throws IOException{ // 构造 XSSFWorkbook 对象,strPath 传入文件路径 XSSFWorkbook xwb = new XSSFWorkbook(strPath); // 读取第一章表格内容 XSSFSheet sheet = xwb.getSheetAt(0); // 定义 row、cell XSSFRow row; String cell; // 循环输出表格中的内容 for (int i = sheet.getFirstRowNum(); i < sheet.getPhysicalNumberOfRows(); i++) { row = sheet.getRow(i); for (int j = row.getFirstCellNum(); j < row.getPhysicalNumberOfCells(); j++) { // 通过 row.getCell(j).toString() 获取单元格内容, cell = row.getCell(j).toString(); System.out.print(cell + "\t"); } System.out.println(""); } } }