Java Apache POI export Excel

Source: Internet
Author: User

Don't talk nonsense, post code

Introduction Rack Pack: Poi-3.12-20150511.jar Poi-ooxml-3.12-20150511.jar

Pipe network can be downloaded

Try{         flogicdataset<fdatainfodevicebrowserunit>  unitlist = _devicebrowserconsole.select (Logiccontext);          //Create a new Excel workbook           HSSFWorkbook  Workbook = new hssfworkbook ();          hssfsheet  sheet = workbook.createsheet ("Sheet1");          / /create a row at index 0 (the topmost row)            string[] headers  = new string[]{"header information",  "Device Information"};          Hssfrow headerrow = sheet.createrow (0);          Hssfcell cell = headerrow.createcell (0);          Cell.setcelltype (Xssfcell.cell_type_string);          cell.setcellvalue (Headers[0]);          hssfcell cell0 = headerrow.createcell (1);          cell0.setcelltype (xssfcell.cell_type_string);          cell0.setcellvalue (headers[1]);          int index = 0;         for ( Fdatainfodevicebrowserunit unit : unitlist) {             index++;             Hssfrow row = sheet.createrow (Index);             hssfcell cell1 = row.createcell (0);             //defines a cell as a string type &Nbsp;             cell1.setcelltype ( xssfcell.cell_type_string);             // Enter some content in the cell                Cell1.setcellvalue (Unit.agentcode ());             Hssfcell cell2 = row.createcell (1);             //defines a cell as a string type                Cell2.setcelltype (xssfcell.cell_type_string);             //enter some content in the cell                Cell2.setcellvalue (Unit.content ());         }          string filepath =  "D:/devicelist_"  + rdatetime.currentdatetime ()  +  ". xls";          //new file output stream             fileoutputstream fout = new fileoutputstream (FilePath);          //writes data to excel            Workbook.write (FOut);          fout.close ();          basepage.ajax (1, filepath);          _logger.debug (this,  "expend",  "expend succeed.  (Path={1})",  filePath);       }catch (exception e) {          e.printstacktrace ();          basepage.ajax (0,  E.getmessage ());    &nbsP;     _logger.debug (this,  "expend",  "expend fail.  (Message={1})" ,  e);       }


Java Apache POI export Excel

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.