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.