import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONObject; import com.gdunis.infra.repo.db1.cheliangdangan.entity.T_JiChuDangAn_CheLiangDangAn_JiChuXinXiPb; import com.gdunis.interfaces.facade.anquanguanli.vo.T_WeiXianCheLiangYunXingBaoBeiVO; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.Row; import org.apache.poi.ss.usermodel.Sheet; import org.apache.poi.ss.usermodel.Workbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.*;
public static List<T_WeiXianCheLiangYunXingBaoBeiVO> importExcel(String filePath) throws IOException { List<T_WeiXianCheLiangYunXingBaoBeiVO> objects = new ArrayList<>(); FileInputStream fileInputStream = new FileInputStream(filePath); //该为.xls文件 Workbook workbook = new HSSFWorkbook(fileInputStream); Sheet sheet = workbook.getSheetAt(0); Iterator<Row> rowIterator = sheet.iterator(); while (rowIterator.hasNext()) { Row row = rowIterator.next(); T_WeiXianCheLiangYunXingBaoBeiVO object = new T_WeiXianCheLiangYunXingBaoBeiVO(); Iterator<Cell> cellIterator = row.cellIterator(); while (cellIterator.hasNext()) { Cell cell = cellIterator.next(); int columnIndex = cell.getColumnIndex(); switch (columnIndex) { case 1: object.setXuQiuDanWeiMingCheng(cell.getStringCellValue()); break; case 2: object.setXuQiuDanWeiXiaQuSheng(cell.getStringCellValue()); break; // 添加更多属性的处理 default: // 忽略其他列 break; } } objects.add(object); } workbook.close(); fileInputStream.close(); return objects; }