OFBiz upload Excel files. xls and. xlsx

Source: Internet
Author: User

A few days ago in the project, there are imported Excel files, before there is a written ready-made import method, but the customer's request is able to import. xlsx files, but our method can only import. xls files. On the Internet to find some methods, no error in eclipse, but compile the error is not found files, and then download the latest jar from the POI website (3.13), import projects, again compiled without error,

But in the import of the file will be an error, the two look at the log when the discovery is a jar package conflict, because I am using the ofbiz to do the project, ofbiz in the self-contained POI jar package is 3.10, may be

Incompatible. xlsx import method, so when I import the latest POI jar, compile without error, but in the call method, two jar package conflict, decisive 3.10 of the purge, recompile, start, sure enough, both format files can be imported. The previous code is commented out:

1   Public StaticList<map>Importexcel (httpservletrequest request, List Filednames)2         throwsIOException3     {4List<map> resultlist =fastlist.newinstance ();5     Try6     {7Fileitemfactory factory =Newdiskfileitemfactory ();8Servletfileupload upload =Newservletfileupload (factory);9list<fileitem> LST =upload.parserequest (request);TenFileitem fi =NULL; One          for(inti = 0; I < lst.size (); i++) A         { -  -fi =Lst.get (i); theString FilePath =fi.getname (); -String FileType = filepath.substring (Filepath.lastindexof (".") + 1, Filepath.length ()); -         if(!Fi.isformfield ()) -         { +InputStream InputStream =NewBufferedinputstream (Fi.getinputstream ()); -Workbook Workbook =NULL; +             if(Filetype.equals ("xls")) { AWorkbook =NewHssfworkbook (inputstream); at}Else if(Filetype.equals ("xlsx")) { -                   //workbook = new Xssfworkbook (inputstream); -Workbook =workbookfactory.create (inputstream); -} -             //Workbook Workbook = Workbook.getworkbook (InputStream); to             //Workbook.getsheetat (arg0) +Sheet Sheet1 = workbook.getsheetat (0); -             //workbook.getsheetname (arg0) the             intR = 1; *              for(Row row:sheet1) { $                 if(r!=1){Panax NotoginsengMap map =fastmap.newinstance (); -                      for(intf = 0; F < filednames.size (); f++) the                     { + Map.put (Filednames.get (f), Row.getcell (f)); A                     } the                 } +r++; -             } $              $              -            /*While (R < sheet1.get) -             { the if (utilvalidate.isnotempty (Sheet1.getcell (0, R). getcontents ())) { - map map = Fastmap.newinstance ();Wuyi for (int f = 0; F < filednames.size (); f++) the                     { - Map.put (Filednames.get (f), Sheet1.getcell (F, R). getcontents ()); Wu                     } - resultlist.add (map); About                 } $ r++; -             }*/ -         } -         } A  +}Catch(Exception e) the     { - e.printstacktrace (); $ Debug.logerror (E, module); the     } the     returnresultlist; the}

OFBiz upload Excel files. xls and. xlsx

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.