基于POI 将POI所需的jar包引入工程
import java.io.FileInputStream; import java.util.ArrayList; import java.util.List; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import model.HospIntroduceModel; public class Main { public static void main(String[] args) throws Exception { List<HospIntroduceModel> retList = new ArrayList<HospIntroduceModel>(); FileInputStream fileIn = new FileInputStream("D://1.xlsx"); // 根据指定的文件输入流导入Excel从而产生Workbook对象 Workbook wb0 = new XSSFWorkbook(fileIn); // 获取Excel文档中的第一个表单 org.apache.poi.ss.usermodel.Sheet sht0 = wb0.getSheetAt(0); // 对Sheet中的每一行进行迭代 for (Row r : sht0) { System.out.println(r.getRowNum()); // 如果当前行的行号(从0开始)未达到2(第三行)则从新循环 // if (r.getRowNum() < 1) { // continue; // } /// System.out.println(r.getCell(0).getNumericCellValue()); HospIntroduceModel hospIntroduceModel = new HospIntroduceModel(); hospIntroduceModel.setYyid(r.getCell(0).getStringCellValue()); hospIntroduceModel.setYyintro(r.getCell(1).getStringCellValue()); hospIntroduceModel.setYymc(r.getCell(2).getStringCellValue()); retList.add(hospIntroduceModel); } fileIn.close(); for (HospIntroduceModel row : retList) { System.out.println(row.getYyid() + row.getYymc() + row.getYyintro()); } } }