读取excel写入数据库
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();
}
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!