Java uses poi to perform simple _ write _ Operations on Execl, and java uses poiexecl

Source: Internet
Author: User

Java uses poi to perform simple _ write _ Operations on Execl, and java uses poiexecl

1 public class WriteExecl {2 3 @ Test 4 public void writeExeclTest () throws Exception {5 OutputStream OS = new FileOutputStream ("F:/execl/writeTest2.xlsx "); 6 // Workbook wb = new HSSFWorkbook (); // create a 2003 version of Execl 7 Workbook wb = new XSSFWorkbook (); // create an Execl 8 9 CellStyle cellStyle = wb for Versions later than 2007. createCellStyle (); // create a style 10 cellStyle. setBorderLeft (CellStyle. BORDER_THIN); // The cell Border width is 11 cellStyle. setBorderRight (CellStyle. BORDER_THIN); // The cell Border width is 12 cellStyle. setBorderTop (CellStyle. BORDER_THIN); // the false width of the cell border 13 cellStyle. setBorderBottom (CellStyle. BORDER_THIN); // cell Border Width 14 cellStyle. setAlignment (CellStyle. ALIGN_CENTER); // horizontally centered 15 cellStyle. setverticalignment (CellStyle. VERTICAL_CENTER); // center vertically 16 cellStyle. setBottomBorderColor (IndexedColors. RED. getIndex (); // set the bottom border to Red 17 cellStyle. setFillForegroundColor (IndexedColors. DARK_YELLOW.getIndex (); // you can specify 18 cellStyle for the foreground. setFillPattern (CellStyle. SOLID_FOREGROUND); // set the cell fill color to 19 20 Sheet sheet = wb. createSheet ("first sheet"); // create a named sheet21 sheet. setdefacolumcolumnwidth (1000); // sets the default width of 22 sheet in sheet. setDefaultRowHeight (short) 800); // set the default height of 23 24 Row row = sheet in sheet. createRow (0); // create a row with 25 rows. createCell (0, Cell. CELL_TYPE_BLANK); // create a blank cell 26 row. createCell (1, Cell. CELL_TYPE_BOOLEAN ). setCellValue (true); // create a boolean cell 27 row. createCell (2, Cell. CELL_TYPE_FORMULA ). setCellValue (3.141592653); // create a formula Cell 28 row. createCell (3, Cell. CELL_TYPE_NUMERIC ). setCellValue (0); // create a numeric cell 29 row. createCell (4, Cell. CELL_TYPE_STRING ). setCellValue ("String... "); // create a string cell 30 row. setRowStyle (cellStyle); // set the row style 31 wb. write (OS); // write the orkbook workbook 32 OS to Execl in the memory. close (); // remember to close the stream and release the resource 33} 34}

 

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.