POI get Excel Data Import Database

Source: Internet
Author: User
Tags import database

Multiparthttpservletrequest multipartrequest = (multiparthttpservletrequest) request; map<string, multipartfile> filemap = Multipartrequest.getfilemap (); for (map.entry<string, MultipartFile> Entity:fileMap.entrySet ()) {Multipartfile file = Entity.getvalue ();//Get Upload file object importparams params = new Importparams (); Params.setheadrows (1);p Arams.setneedsave (false); try {/*system.out.println (File.getinputstream ()); list<cashistorydateentity> Listcashistorydateentitys = Excelimportutil.importexcel (File.getInputStream (), Cashistorydateentity.class,params); listcashistorydateentitys.remove (0); for (cashistorydateentity casHistoryDate: Listcashistorydateentitys) {*///cashistorydateservice.save (cashistorydate);//Constructs Workbook object, Execelfile is the incoming file path ( Get Excel Workspace) multipartfile file1 = file; Commonsmultipartfile CF = (commonsmultipartfile) File1;diskfileitem fi = (Diskfileitem) cf.getfileitem (); File file2 = Fi.getstorelocation (); Workbook book = Null;//book = new Xssfworkbook (New FileinputstreaM (file2)); try {//Excel 2007 Get Method book = new Xssfworkbook (new FileInputStream (File2));} catch (Exception ex) {///Excel 2003 wins Fetch method book = new Hssfworkbook (new FileInputStream (File2));} Read the first sheet page of a table sheet sheet = book.getsheetat (0);//define row, Cellrow row; String cell;//The total number of rows, starting from 0 int totalrows = sheet.getlastrownum ();//Looping through the contents of the table, first looping out the rows, and then the row loop to remove the column for (int i = 1; I <= tot Alrows; i++) {cashistorydateentity cashistorydateentity = new cashistorydateentity (); map<string, object> map = new Hashedmap (); row = Sheet.getrow (i);//Handle Empty line if (row = = null) {continue;}  Total number of columns, starting with 0 int totalcells = row.getlastcellnum (); for (int f = Row.getfirstcellnum (); f < totalcells; f++) {//Handling empty columns if (Row.getcell (f) = = null) {continue;} Get the cell contents by Row.getcell (j). ToString () SimpleDateFormat formatter = new SimpleDateFormat ("Yyyy-mm-dd"); cell = Row.getcell (f). ToString (), if (Row.getrownum () > 1) {if (1 = = f) {CASHISTORYDATEENTITY.SETXMMC (cell);} if (2 = = f) {cashistorydateentity.setqtys (cell);} if (3 = = f) {CAsHISTORYDATEENTITY.SETZZDW (cell);} if (4 = = f) {Cashistorydateentity.setfzcs (cell);} if (5 = = f) {CASHISTORYDATEENTITY.SETLXSJJ (cell);} if (6 = = f) {CASHISTORYDATEENTITY.SETLXSHC (cell);} if (7 = = f) {CASHISTORYDATEENTITY.SETLXSJN (cell);} if (8 = = f) {cashistorydateentity.setwyh (cell);} if (9 = = f) {Cashistorydateentity.setxmbh (cell);} if (ten = = f) {CASHISTORYDATEENTITY.SETJF (cell);} if (= = f) {CASHISTORYDATEENTITY.SETJTSJJ (cell);} if (n = f) {CASHISTORYDATEENTITY.SETJTSJC (cell);} if (= = f) {CASHISTORYDATEENTITY.SETJTSJN (cell);} if (+ = f) {cashistorydateentity.setmqzt (cell);} if (= = f) {cashistorydateentity.setzxbg (cell);} if (+ = f) {CASHISTORYDATEENTITY.SETXMLXR (cell);} if (+ = f) {cashistorydateentity.setlxfs (cell);} if (= = f) {CASHISTORYDATEENTITY.SETFZR (cell);} if (+ = f) {cashistorydateentity.setbz (cell);} Systemservice.save (cashistorydateentity);} System.out.print (cell + "\ t");} Cashistorydateservice.save (cashistorydate);//cashistorydateservice.save (cashistorydate); System.ouT.println ("");} J.setmsg ("File Import succeeded! ");/*}*/} catch (Exception e) {j.setmsg (" File Import failed! "); Logger.error (Exceptionutil.getexceptionmessage (e));} Finally {try {File.getinputstream (). Close ();} catch (IOException e) {e.printstacktrace ();}}}

  

POI get Excel Data Import Database

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.