欢迎使用CSDN-markdown编辑器

来源:互联网 发布:it认证培训班 编辑:程序博客网 时间:2024/05/18 01:26

POI导出EXCEL
try{
HSSFWorkbook wb = new HSSFWorkbook();
//设置表头样式
HSSFCellStyle style = wb.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER);//居中格式

    //字体样式    HSSFFont font = wb.createFont();    font.setFontName("宋体");    font.setFontHeightInPoints((short)12);    font.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);    style.setFont(font);    String dlData = getUsedExamineStyle();    String[] heads = {"考核人编号","考核人","被考核人编号","被考核人","考核类型" + dlData};    HSSFSheet sheet = wb.createSheet("Sheet1");    HSSFRow headRow = sheet.createRow(0);    for(int i=0; i < heads.length; i++){        HSSFCell cell = headRow.createCell((short)i);        cell.setEncoding(HSSFCell.ENCODING_UTF_16);        cell.setCellStyle(style);        cell.setCellValue(heads[i]);    }    sheet.setColumnWidth((short)0, (short)5120);    sheet.setColumnWidth((short)1, (short)6120);    sheet.setColumnWidth((short)2, (short)5120);    sheet.setColumnWidth((short)3, (short)6120);    sheet.setColumnWidth((short)4, (short)15120);    ByteArrayOutputStream baos = new ByteArrayOutputStream();    wb.write(baos);    byte[] bytes = baos.toByteArray();    InputStream is = new ByteArrayInputStream(bytes);    response.reset();    response.setHeader("Content-Disposition", "attachment;filename="+new String("考核计划导入模板.xls".getBytes("UTF-8"), "ISO-8859-1"));      response.setContentType("application/x-download;charset=UTF-8");      response.setCharacterEncoding("UTF-8");     OutputStream sos = response.getOutputStream();    wb.write(sos);    sos.close();}catch(Exception ex){    ex.printStackTrace();}