XLS Document upload parsing

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.