String filePath = “C:\Users\Farben\Desktop\地图助残.xlsx”;
ReadExcel readExcel = new ReadExcel();
// System.out.println(readExcel(filePath).toString());
// 存放读取出来的姓名和电话
InputStream iStream = new FileInputStream(filePath);
XSSFWorkbook workbook = new XSSFWorkbook(iStream);
List list = Lists.newArrayList();
// sheet row column 下标都是从0开始的
XSSFSheet sheet = workbook.getSheetAt(0);
int rowNumber = sheet.getPhysicalNumberOfRows();
System.out.println(“共有” + rowNumber + “行数据”);
for (int i = 0; i < rowNumber; i++) {
XSSFRow row = sheet.getRow(i);
MapWritetResp resp = new MapWritetResp();
MapListEntity mapListEntity = new MapListEntity();
mapListEntity.setName(row.getCell(0) + “”);
mapListEntity.setPerson(row.getCell(2) + “”);
mapListEntity.setPhone(row.getCell(3).getRawValue() + “”);
mapListEntity.setAddress(row.getCell(4) + “”);
mapListEntity.setTime(row.getCell(5)+ “”);
mapListEntity.setNoBarrier(row.getCell(6) + “”);
mapListEntity.setBarrier(row.getCell(7)+ “”);
mapListEntity.setLongitude(Double.valueOf(row.getCell(8) + “”));
mapListEntity.setLatitude(Double.valueOf(row.getCell(9) + “”));
// BeanUtils.copyProperties(mapListEntity,resp);
LambdaQueryWrapper trademarkWrapper = new LambdaQueryWrapper<>();
this.save(mapListEntity);
list.add(mapListEntity);
}
// 操作完成时,关闭对象,释放占用的内存空间
if (iStream != null) {
iStream.close();
}
读取excel写入数据库
最新推荐文章于 2024-04-15 10:08:56 发布