Java poi export excel and poiexcel

Source: Internet
Author: User

Java poi export excel and poiexcel

Jar of poi: http://poi.apache.org/

There will be a lot of jar after the download, but if it is just a simple excel report, you can import a poi-version-date. jar.

Export Code:

Private void outputExcel (String queryDate, String [] headers, List <String> diaochas, HttpServletRequest request, HttpServletResponse response) throws IOException {HSSFWorkbook workbook = new HSSFWorkbook (); // createSheet (excel worksheet name) HSSFSheet sheet = workbook. createSheet (queryDate); // The following is the style HSSFCellStyle title_style = workbook. createCellStyle (); title_style.setFillForegroundColor (H SSFColor. SKY_BLUE.index); title_style.setFillPattern (HSSFCellStyle. SOLID_FOREGROUND); title_style.setBorderBottom (HSSFCellStyle. BORDER_THIN); title_style.setBorderLeft (HSSFCellStyle. BORDER_THIN); title_style.setBorderRight (HSSFCellStyle. BORDER_THIN); title_style.setBorderTop (HSSFCellStyle. BORDER_THIN); title_style.setAlignment (HSSFCellStyle. ALIGN_CENTER); HSSFFont title_font = workbook. createFont (); Title_font.setColor (HSSFColor. VIOLET. index); title_font.setFontHeightInPoints (short) 12); title_font.setBoldweight (HSSFFont. BOLDWEIGHT_BOLD); title_style.setFont (title_font); // The style HSSFCellStyle content_style = workbook. createCellStyle (); content_style.setFillForegroundColor (HSSFColor. LIGHT_YELLOW.index); content_style.setFillPattern (HSSFCellStyle. SOLID_FOREGROUND); content_style.setBorderBo Ttom (HSSFCellStyle. BORDER_THIN); content_style.setBorderLeft (HSSFCellStyle. BORDER_THIN); content_style.setBorderRight (HSSFCellStyle. BORDER_THIN); content_style.setBorderTop (HSSFCellStyle. BORDER_THIN); content_style.setAlignment (HSSFCellStyle. ALIGN_CENTER); content_style.setVerticalAlignment (HSSFCellStyle. VERTICAL_CENTER); HSSFFont content_font = workbook. createFont (); content_font.setBoldweight (HS SFFont. BOLDWEIGHT_NORMAL); content_style.setFont (content_font); // fill in the title content HSSFRow row = sheet. createRow (0); for (int I = 0; I 

Well, append a mysql function to get the year and month.

date_format(formatdate,'%Y-%m')

The last note is that ajax requests cannot be used when the request is exported, which is not reflected.

Related Article

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.