@Action(value = "region_importData",results = {@Result(name = "success",type = "json")})
public String importData(){
Map map = new HashMap<String,Object>();
try {
HSSFWorkbook hssfWorkbook = new HSSFWorkbook(new FileInputStream(upload));
HSSFSheet sheetAt = hssfWorkbook.getSheetAt(0);
ArrayList<Region> list = new ArrayList<>();
for (Row row :
sheetAt) {
if (row.getRowNum() == 0){
continue;
}
if (StringUtils.isNotBlank(row.getCell(0).getStringCellValue())){
Region region = new Region();
String province = row.getCell(1).getStringCellValue();
String city = row.getCell(2).getStringCellValue();
String distrinct = row.getCell(3).getStringCellValue();
String[] headByString = PinYin4jUtils.getHeadByString(province + city + distrinct);
String shortCode = StringUtils.join(headByString);
region.setProvince(province);
region.setCity(city);
region.setDistrict(distrinct);
region.setPostcode(row.getCell(4).getStringCellValue());
region.setShortcode(shortCode);
region.setCitycode(PinYin4jUtils.hanziToPinyin(city));
list.add(region);
}
}
regionService.saveRegions(list);
map.put("resultss",true);
}catch (Exception e){
e.printStackTrace();
map.put("resultss",false);
}
pushToValueStackRoot(map);
return SUCCESS;
}
ApachePOI解析excel
最新推荐文章于 2023-12-01 14:18:16 发布