標籤: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";
}
xls文檔上傳解析