标签:set except itop 一个 int upload for pos getc
private File xls;
public void setXls(File xls) {
this.xls = xls;
}
@Action("AreaAction_upload")
public String upload() throws Exception {
List<Area> list=new ArrayList<>();
//创建解析xls工具类
HSSFWorkbook workbook = new HSSFWorkbook(new FileInputStream(xls));
//指定解析sheet1表格
HSSFSheet sheet = workbook.getSheet("Sheet1");
//获得总行数
int rowCount = sheet.getLastRowNum();
//遍历取得每一个行对象
for(int i=1;i<=rowCount;i++){
//获得行对象
HSSFRow row = sheet.getRow(i);
//获得行中的每一个单元格
String id = row.getCell(0).getStringCellValue();//地区编号
String province = row.getCell(1).getStringCellValue();//省
String city = row.getCell(2).getStringCellValue();//市
String district = row.getCell(3).getStringCellValue();//区
String postcode = row.getCell(4).getStringCellValue();//邮编
//把从表格的每一行数据封装到每个area对象中
Area area2=new Area(id, province, city, district, postcode);
province=province.substring(0, province.length()-1);
city=city.substring(0, city.length()-1);
district=district.substring(0, district.length()-1);
//城市全拼
area2.setCitycode(PinYin4jUtils.hanziToPinyin(city, ""));
//简码
area2.setShortcode(StringUtils.join(PinYin4jUtils.getHeadByString(province+city+district), ""));
list.add(area2);
}
areaService.save(list);
return "toList";
}
标签:set except itop 一个 int upload for pos getc
原文地址:http://www.cnblogs.com/zjqblog/p/7467991.html