Private File xls;
public void Setxls (File xls) {
This.xls = xls;
}
@Action ("Areaaction_upload")
Public String upload () throws Exception {
List<area> list=new arraylist<> ();
Create parse XLS tool class
Hssfworkbook workbook = new Hssfworkbook (new FileInputStream (XLS));
Specify Parse Sheet1 table
Hssfsheet sheet = workbook.getsheet ("Sheet1");
Get total number of rows
int rowCount = Sheet.getlastrownum ();
Traversal gets each Row object
for (int i=1;i<=rowcount;i++) {
Get Row objects
Hssfrow row = Sheet.getrow (i);
Get each cell in a row
String id = Row.getcell (0). Getstringcellvalue ();//region number
String province = Row.getcell (1). Getstringcellvalue ();//Province
String City = Row.getcell (2). Getstringcellvalue ();//Municipality
String district = Row.getcell (3). Getstringcellvalue ();//Area
String postcode = Row.getcell (4). Getstringcellvalue ();//ZIP code
Encapsulates each row of data from a table into each area object
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);
City full spell
Area2.setcitycode (Pinyin4jutils.hanzitopinyin (City, ""));
Jane Code
Area2.setshortcode (Stringutils.join (pinyin4jutils.getheadbystring (province+city+district), ""));
List.add (AREA2);
}
Areaservice.save (list);
return "ToList";
}
XLS Document upload parsing