当前位置: 首页 > 编程笔记 >

实操:使用HSSFWorkbook导出一份Excel版个人信息表

章烨烨
2023-05-05

在前面一篇文章《Java使用Jakarta POI操作Excel》使用HSSFWorkbook导出、操作excel中我们学会了使用HSSFWorkbook导出简单的excel表格,这篇文章分享的是使用POI的HSSFWorkbook导出信息采集表样式的excel。 在项目中,关于一个商品或者是对象的许多属性客户希望能直观地显示并且方便存档,于是便需要导出这种格式的表格,这种表格和我们生活中的申请表格、个人信息、简历都很相似,他的特点是格式不固定,涉及很多单元格合并,包括行的合并单元格,列的合并单元格,最终的导出excel表格效果如下:

 

13079544-f99ceec1aa91e5bb.png  

个人信息采集表

HSSFWorkbook如何合并单元格

方法:

// 合并单元格
CellRangeAddress(int firstRow, int lastRow, int firstCol, int lastCol)


参数说明:

参数分别表示:起始行号,终止行号, 起始列号,终止列号 行号、列号分别从0开始,因此第一行标题合并单元格就是

CellRangeAddress range = new CellRangeAddress(0, 0, 0, 7);
sheet.addMergedRegion(range);


因为每个单元格的内容、格式都不一样,无法用循环解决,所以导出方法比较臃肿,表格里导出的数据在实际开发中一般是从数据库查询出来的信息并通过实体类对象访问,这里为了演示是写死的测试数据,代码如下:

@RequestMapping(value = "/outExcel", produces = "application/json;charset=UTF-8", method = { RequestMethod.GET})
    public void outExcel(HttpServletRequest request,HttpServletResponse response) {
        try {
            String fileName = request.getParameter("fileName");
            HSSFWorkbook workbook = new HSSFWorkbook();
            HSSFSheet sheet = workbook.createSheet();
            int columnSize = 8;
            //设置列宽
            for(int i = 0;i< columnSize;i++ ){
                sheet.setColumnWidth(i, 5000);
            }
            // 设置字体
            HSSFFont headfont = workbook.createFont();
            headfont.setFontName("宋体");
            // 字体大小
            headfont.setFontHeightInPoints((short) 22);
            // 加粗
            headfont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            //表格大标题字体样式,居中、加粗
            HSSFCellStyle headstyle = workbook.createCellStyle();
            headstyle.setFont(headfont);
            // 左右居中
            headstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            // 上下居中
            headstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            headstyle.setLocked(true);
            // 自动换行
            headstyle.setWrapText(true);
            headstyle.setBorderLeft((short) 1);
            headstyle.setLeftBorderColor(HSSFColor.BLACK.index);
            headstyle.setRightBorderColor(HSSFColor.BLACK.index);
            headstyle.setBorderRight((short) 1);
            // 加粗字体样式
            HSSFFont columnHeadFont = workbook.createFont();
            columnHeadFont.setFontName("宋体");
            columnHeadFont.setFontHeightInPoints((short) 12);
            columnHeadFont.setBoldweight(HSSFFont.BOLDWEIGHT_BOLD);
            //单元格标题、居中、字体加粗,黑丝边框样式
            HSSFCellStyle columnHeadStyle = workbook.createCellStyle();
            columnHeadStyle.setFont(columnHeadFont);
            columnHeadStyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            columnHeadStyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            columnHeadStyle.setLocked(true);
            columnHeadStyle.setWrapText(true);
            columnHeadStyle.setTopBorderColor(HSSFColor.BLACK.index);
            columnHeadStyle.setBorderTop((short) 1);
            columnHeadStyle.setLeftBorderColor(HSSFColor.BLACK.index);
            columnHeadStyle.setBorderLeft((short) 1);
            columnHeadStyle.setRightBorderColor(HSSFColor.BLACK.index);
            columnHeadStyle.setBorderRight((short) 1);
            columnHeadStyle.setBottomBorderColor(HSSFColor.BLACK.index);
            columnHeadStyle.setBorderBottom((short) 1);
            HSSFFont font = workbook.createFont();
            font.setFontName("宋体");
            font.setFontHeightInPoints((short) 12);
            //单元格字体居中样式
            HSSFCellStyle centerstyle = workbook.createCellStyle();
            centerstyle.setFont(font);
            centerstyle.setAlignment(HSSFCellStyle.ALIGN_CENTER);
            centerstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            centerstyle.setWrapText(true);
            centerstyle.setLeftBorderColor(HSSFColor.BLACK.index);
            centerstyle.setBorderLeft((short) 1);
            centerstyle.setTopBorderColor(HSSFColor.BLACK.index);
            centerstyle.setBorderTop((short) 1);
            centerstyle.setRightBorderColor(HSSFColor.BLACK.index);
            centerstyle.setBorderRight((short) 1);
            centerstyle.setBottomBorderColor(HSSFColor.BLACK.index);
            centerstyle.setBorderBottom((short) 1);
            centerstyle.setFillForegroundColor(HSSFColor.WHITE.index);
            //单元格字体居左样式
            HSSFCellStyle leftstyle = workbook.createCellStyle();
            leftstyle.setFont(font);
            leftstyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
            leftstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            leftstyle.setWrapText(true);
            leftstyle.setLeftBorderColor(HSSFColor.BLACK.index);
            leftstyle.setBorderLeft((short) 1);
            leftstyle.setTopBorderColor(HSSFColor.BLACK.index);
            leftstyle.setBorderTop((short) 1);
            leftstyle.setRightBorderColor(HSSFColor.BLACK.index);
            leftstyle.setBorderRight((short) 1);
            leftstyle.setBottomBorderColor(HSSFColor.BLACK.index);
            leftstyle.setBorderBottom((short) 1);
            leftstyle.setFillForegroundColor(HSSFColor.WHITE.index);
            //单元格标题、居左、字体加粗样式
            HSSFCellStyle leftHeadstyle = workbook.createCellStyle();
            leftHeadstyle.setFont(columnHeadFont);
            leftHeadstyle.setAlignment(HSSFCellStyle.ALIGN_LEFT);
            leftHeadstyle.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER);
            leftHeadstyle.setWrapText(true);
            leftHeadstyle.setLeftBorderColor(HSSFColor.BLACK.index);
            leftHeadstyle.setBorderLeft((short) 1);
            leftHeadstyle.setTopBorderColor(HSSFColor.BLACK.index);
            leftHeadstyle.setBorderTop((short) 1);
            leftHeadstyle.setRightBorderColor(HSSFColor.BLACK.index);
            leftHeadstyle.setBorderRight((short) 1);
            leftHeadstyle.setBottomBorderColor(HSSFColor.BLACK.index);
            leftHeadstyle.setBorderBottom((short) 1);
            leftHeadstyle.setFillForegroundColor(HSSFColor.WHITE.index);
            // 创建第一行
            HSSFRow row0 = sheet.createRow(0);
            // 设置行高
            row0.setHeight((short) 900);
            // 创建第一列
            HSSFCell cell = row0.createCell(0);
            cell.setCellValue(new HSSFRichTextString("个人信息采集表"));
            cell.setCellStyle(headstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row0.createCell(i);
                cell.setCellStyle(headstyle);
            }
            // 合并单元格
            CellRangeAddress range = new CellRangeAddress(0, 0, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第二行
            HSSFRow row1 = sheet.createRow(1);
            cell = row1.createCell(0);
            cell.setCellValue(new HSSFRichTextString("姓名"));
            row1.setHeight((short) 700);
            cell.setCellStyle(columnHeadStyle);
            cell = row1.createCell(1);
            cell.setCellValue("张三");
            cell.setCellStyle(centerstyle);
            cell = row1.createCell(2);
            cell.setCellValue(new HSSFRichTextString("性别"));
            cell.setCellStyle(columnHeadStyle);
            cell = row1.createCell(3);
            cell.setCellValue("女");
            cell.setCellStyle(centerstyle);
            cell = row1.createCell(4);
            cell.setCellValue(new HSSFRichTextString("文/理科"));
            cell.setCellStyle(columnHeadStyle);
            cell = row1.createCell(5);
            cell.setCellValue("理科");
            cell.setCellStyle(centerstyle);
            cell = row1.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row1.createCell(7);
            cell.setCellStyle(centerstyle);
            range = new CellRangeAddress(1, 1, 5, 7);
            sheet.addMergedRegion(range);
            // 第三行
            HSSFRow row2 = sheet.createRow(2);
            row2.setHeight((short) 700);
            cell = row2.createCell(0);
            cell.setCellValue(new HSSFRichTextString("出生日期"));
            cell.setCellStyle(columnHeadStyle);
            cell = row2.createCell(1);
            cell.setCellValue("1998年12月20日");
            cell.setCellStyle(centerstyle);
            cell = row2.createCell(2);
            cell.setCellValue(new HSSFRichTextString("民族"));
            cell.setCellStyle(columnHeadStyle);
            cell = row2.createCell(3);
            cell.setCellValue("汉族");
            cell.setCellStyle(centerstyle);
            cell = row2.createCell(4);
            cell.setCellValue(new HSSFRichTextString("所在省份"));
            cell.setCellStyle(columnHeadStyle);
            cell = row2.createCell(5);
            cell.setCellValue("北京");
            cell.setCellStyle(centerstyle);
            cell = row2.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row2.createCell(7);
            cell.setCellStyle(centerstyle);
            // 合并单元格
            range = new CellRangeAddress(2, 2, 5, 7);
            sheet.addMergedRegion(range);
            // 第四行
            HSSFRow row3 = sheet.createRow(3);
            row3.setHeight((short) 700);
            cell = row3.createCell(0);
            cell.setCellValue(new HSSFRichTextString("所在城市"));
            cell.setCellStyle(columnHeadStyle);
            cell = row3.createCell(1);
            cell.setCellValue("北京市");
            cell.setCellStyle(centerstyle);
            cell = row3.createCell(2);
            cell.setCellValue(new HSSFRichTextString("分数"));
            cell.setCellStyle(columnHeadStyle);
            cell = row3.createCell(3);
            cell.setCellValue(580);
            cell.setCellStyle(centerstyle);
            cell = row3.createCell(4);
            cell.setCellValue(new HSSFRichTextString("年龄"));
            cell.setCellStyle(columnHeadStyle);
            cell = row3.createCell(5);
            cell.setCellValue("16");
            cell.setCellStyle(centerstyle);
            cell = row3.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row3.createCell(7);
            cell.setCellStyle(centerstyle);
            range = new CellRangeAddress(3, 3, 5, 7);
            sheet.addMergedRegion(range);
            // 第5行
            HSSFRow row4 = sheet.createRow(4);
            row4.setHeight((short) 700);
            cell = row4.createCell(0);
            cell.setCellValue(new HSSFRichTextString("是否色盲"));
            cell.setCellStyle(columnHeadStyle);
            cell = row4.createCell(1);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row4.createCell(2);
            cell.setCellValue(new HSSFRichTextString("身高"));
            cell.setCellStyle(columnHeadStyle);
            cell = row4.createCell(3);
            cell.setCellValue(175);
            cell.setCellStyle(centerstyle);
            cell = row4.createCell(4);
            cell.setCellValue(new HSSFRichTextString("体重"));
            cell.setCellStyle(columnHeadStyle);
            cell = row4.createCell(5);
            cell.setCellValue(130);
            cell.setCellStyle(centerstyle);
            cell = row4.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row4.createCell(7);
            cell.setCellStyle(centerstyle);
            range = new CellRangeAddress(4, 4, 5, 7);
            sheet.addMergedRegion(range);
            // 第6行
            HSSFRow row5 = sheet.createRow(5);
            row5.setHeight((short) 700);
            cell = row5.createCell(0);
            cell.setCellValue(new HSSFRichTextString("身份证号"));
            cell.setCellStyle(columnHeadStyle);
            cell = row5.createCell(1);
            cell.setCellValue("***");
            cell.setCellStyle(centerstyle);
            cell = row5.createCell(2);
            cell = row5.createCell(3);
            range = new CellRangeAddress(5, 5, 1, 3);
            sheet.addMergedRegion(range);
            cell.setCellStyle(centerstyle);
            cell = row5.createCell(4);
            cell.setCellValue(new HSSFRichTextString("邮箱"));
            cell.setCellStyle(columnHeadStyle);
            cell = row5.createCell(5);
            cell.setCellValue("***");
            cell.setCellStyle(centerstyle);
            cell = row5.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row5.createCell(7);
            cell.setCellStyle(centerstyle);
            range = new CellRangeAddress(5, 5, 5, 7);
            sheet.addMergedRegion(range);
            // 第7行
            HSSFRow row6 = sheet.createRow(6);
            row6.setHeight((short) 700);
            cell = row6.createCell(0);
            cell.setCellValue(new HSSFRichTextString("个人爱好:"));
            cell.setCellStyle(columnHeadStyle);
            cell = row6.createCell(1);
            cell.setCellValue("***");
            cell.setCellStyle(centerstyle);
            for(int i = 2;i< columnSize;i++ ){
                cell = row6.createCell(i);
                cell.setCellStyle(centerstyle);
            }
            range = new CellRangeAddress(6, 6, 1, 7);
            sheet.addMergedRegion(range);
            // 第8行
            HSSFRow row7 = sheet.createRow(7);
            row7.setHeight((short) 700);
            cell = row7.createCell(0);
            cell.setCellValue(new HSSFRichTextString("父亲联系电话"));
            cell.setCellStyle(columnHeadStyle);
            cell = row7.createCell(1);
            cell.setCellValue("***");
            cell.setCellStyle(centerstyle);
            cell = row7.createCell(2);
            cell.setCellStyle(centerstyle);
            cell = row7.createCell(3);
            range = new CellRangeAddress(7, 7, 1, 3);
            sheet.addMergedRegion(range);
            cell.setCellStyle(centerstyle);
            cell = row7.createCell(4);
            cell.setCellValue(new HSSFRichTextString("职业"));
            cell.setCellStyle(columnHeadStyle);
            cell = row7.createCell(5);
            cell.setCellValue("***");
            cell.setCellStyle(centerstyle);
            cell = row7.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row7.createCell(7);
            range = new CellRangeAddress(7, 7, 5, 7);
            sheet.addMergedRegion(range);
            // 第9行
            HSSFRow row8 = sheet.createRow(8);
            row8.setHeight((short) 700);
            cell = row8.createCell(0);
            cell.setCellValue(new HSSFRichTextString("母亲联系电话"));
            cell.setCellStyle(columnHeadStyle);
            cell = row8.createCell(1);
            cell.setCellValue("***");
            cell.setCellStyle(centerstyle);
            cell = row8.createCell(2);
            cell = row8.createCell(3);
            // 合并单元格
            range = new CellRangeAddress(8, 8, 1, 3);
            sheet.addMergedRegion(range);
            cell.setCellStyle(centerstyle);
            cell = row8.createCell(4);
            cell.setCellValue(new HSSFRichTextString("职业"));
            cell.setCellStyle(columnHeadStyle);
            cell = row8.createCell(5);
            cell.setCellValue("***");
            cell.setCellStyle(centerstyle);
            cell = row8.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row8.createCell(7);
            cell.setCellStyle(centerstyle);
            range = new CellRangeAddress(8, 8, 5, 7);
            sheet.addMergedRegion(range);
            // 创建第10行
            HSSFRow row9 = sheet.createRow(9);
            cell = row9.createCell(0);
            cell.setCellValue(new HSSFRichTextString("是否独生子女"));
            row9.setHeight((short) 850);
            cell.setCellStyle(columnHeadStyle);
            cell = row9.createCell(1);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row9.createCell(2);
            cell.setCellValue(new HSSFRichTextString("是否军人后裔"));
            cell.setCellStyle(columnHeadStyle);
            cell = row9.createCell(3);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row9.createCell(4);
            cell.setCellValue(new HSSFRichTextString("是否低保家庭"));
            cell.setCellStyle(columnHeadStyle);
            cell = row9.createCell(5);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row9.createCell(6);
            cell.setCellValue(new HSSFRichTextString("其他"));
            cell.setCellStyle(columnHeadStyle);
            range = new CellRangeAddress(9, 11, 6, 6);
            sheet.addMergedRegion(range);
            cell = row9.createCell(7);
            cell.setCellValue("暂无");
            cell.setCellStyle(centerstyle);
            range = new CellRangeAddress(9, 11, 7, 7);
            sheet.addMergedRegion(range);
            // 创建第11行
            HSSFRow row10 = sheet.createRow(10);
            cell = row10.createCell(0);
            cell.setCellValue(new HSSFRichTextString("是否打算出国"));
            row10.setHeight((short) 700);
            cell.setCellStyle(columnHeadStyle);
            cell = row10.createCell(1);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row10.createCell(2);
            cell.setCellValue(new HSSFRichTextString("是否艺术生"));
            cell.setCellStyle(columnHeadStyle);
            cell = row10.createCell(3);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row10.createCell(4);
            cell.setCellValue(new HSSFRichTextString("是否打算考研"));
            cell.setCellStyle(columnHeadStyle);
            cell = row10.createCell(5);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row10.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row10.createCell(7);
            cell.setCellStyle(centerstyle);
            // 创建第12行
            HSSFRow row11 = sheet.createRow(11);
            cell = row11.createCell(0);
            cell.setCellValue(new HSSFRichTextString("是否少数民族"));
            row11.setHeight((short) 850);
            cell.setCellStyle(columnHeadStyle);
            cell = row11.createCell(1);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row11.createCell(2);
            cell.setCellValue(new HSSFRichTextString("是否已经报考"));
            cell.setCellStyle(columnHeadStyle);
            cell = row11.createCell(3);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row11.createCell(4);
            cell.setCellValue(new HSSFRichTextString("是否已经入学"));
            cell.setCellStyle(columnHeadStyle);
            cell = row11.createCell(5);
            cell.setCellValue("否");
            cell.setCellStyle(centerstyle);
            cell = row11.createCell(6);
            cell.setCellStyle(centerstyle);
            cell = row11.createCell(7);
            cell.setCellStyle(centerstyle);
            // 创建第13行
            HSSFRow row12 = sheet.createRow(12);
            cell = row12.createCell(0);
            cell.setCellValue(new HSSFRichTextString("个人爱好"));
            row12.setHeight((short) 700);
            cell.setCellStyle(leftHeadstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row12.createCell(i);
                cell.setCellStyle(leftHeadstyle);
            }
            range = new CellRangeAddress(12, 12, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第14行
            HSSFRow row13 = sheet.createRow(13);
            cell = row13.createCell(0);
            cell.setCellValue("***");
            row13.setHeight((short) 700);
            cell.setCellStyle(leftstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row13.createCell(i);
                cell.setCellStyle(leftstyle);
            }
            // 合并单元格
            range = new CellRangeAddress(13, 13, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第15行
            HSSFRow row14 = sheet.createRow(14);
            cell = row14.createCell(0);
            cell.setCellValue(new HSSFRichTextString("学习经历"));
            row14.setHeight((short) 700);
            cell.setCellStyle(leftHeadstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row14.createCell(i);
                cell.setCellStyle(leftHeadstyle);
            }
            // 合并单元格
            range = new CellRangeAddress(14, 14, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第16行
            HSSFRow row15 = sheet.createRow(15);
            cell = row15.createCell(0);
            cell.setCellValue("***");
            row15.setHeight((short) 700);
            cell.setCellStyle(leftstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row15.createCell(i);
                cell.setCellStyle(leftstyle);
            }
            // 合并单元格
            range = new CellRangeAddress(15, 15, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第17行
            HSSFRow row16 = sheet.createRow(16);
            cell = row16.createCell(0);
            cell.setCellValue(new HSSFRichTextString("工作实践经历"));
            row16.setHeight((short) 700);
            cell.setCellStyle(leftHeadstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row16.createCell(i);
                cell.setCellStyle(leftHeadstyle);
            }
            // 合并单元格
            range = new CellRangeAddress(16, 16, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第18行
            HSSFRow row17 = sheet.createRow(17);
            cell = row17.createCell(0);
            cell.setCellValue("***");
            row17.setHeight((short) 700);
            cell.setCellStyle(leftstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row17.createCell(i);
                cell.setCellStyle(leftstyle);
            }
            // 合并单元格
            range = new CellRangeAddress(17, 17, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第19行
            HSSFRow row18 = sheet.createRow(18);
            cell = row18.createCell(0);
            cell.setCellValue(new HSSFRichTextString("职业规划"));
            row18.setHeight((short) 700);
            cell.setCellStyle(leftHeadstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row18.createCell(i);
                cell.setCellStyle(leftHeadstyle);
            }
            // 合并单元格
            range = new CellRangeAddress(18, 18, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第20行
            HSSFRow row19 = sheet.createRow(19);
            cell = row19.createCell(0);
            cell.setCellValue("***");
            row19.setHeight((short) 700);
            cell.setCellStyle(leftstyle);
            for(int i = 1;i< columnSize;i++ ){
                cell = row19.createCell(i);
                cell.setCellStyle(leftstyle);
            }
            // 合并单元格
            range = new CellRangeAddress(19, 19, 0, 7);
            sheet.addMergedRegion(range);
            // 创建第21行
            HSSFRow row20 = sheet.createRow(20);
            cell = row20.createCell(0);
            cell.setCellValue(new HSSFRichTextString("补充说明"));
            row20.setHeight((short) 850);
            cell.setCellStyle(columnHeadStyle);
            cell = row20.createCell(1);
            cell.setCellValue("***");
            cell.setCellStyle(centerstyle);
            for(int i = 2;i< columnSize;i++ ){
                cell = row20.createCell(i);
                cell.setCellStyle(centerstyle);
            }
            // 合并单元格
            range = new CellRangeAddress(20, 20, 1, 7);
            sheet.addMergedRegion(range);
            OutputStream os = response.getOutputStream();
            response.setContentType("application/msexcel");
            response.setHeader("Content-disposition",
                    "attachment; filename=" + new String(fileName.getBytes("GB2312"), "8859_1") + ".xls");
            workbook.write(os);
            os.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


网页页面导出按钮请求方法:

<a href="outExcel?fileName=个人信息表">导出</a>
 类似资料:
  • 一、简介  用于显示和修改用户个人信息。 二、功能演示 写入你的要修改的数据:真实姓名,E-mail,语言。 提交后,如提示成功则可完成修改操作,否则则提示错误消息。如下图所示:

  • 可查看自己及朋友、或在线游戏中曾一起游玩的玩家等等的个人信息。可从朋友列表或(一起游玩的历史记录)轻触想查看个人信息的对象。 A ) 虚拟形象/状态/在线ID 状态的种类 在线 离线 待命状态 正在游玩PlayStation®3规格软件的游戏 正在游玩PS Vita规格软件的游戏 游戏的缩略图 正在游玩目前显示缩略图的游戏 未注册PlayStation®Network的状态下,若轻触(朋友)>[开

  • 本文向大家介绍Oracle 使用TOAD实现导入导出Excel数据,包括了Oracle 使用TOAD实现导入导出Excel数据的使用技巧和注意事项,需要的朋友参考一下 在Oracle应用程序的开发过程中,访问数据库对象和编写SQL程序是一件乏味且耗费时间的工作,对数据库进行日常管理也是需要很多SQL脚本才能完成的。Quest Software为此提供了高效的Oracle应用开发工具-Toad。在T

  • 本文向大家介绍ASP.NET使用GridView导出Excel实现方法,包括了ASP.NET使用GridView导出Excel实现方法的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了ASP.NET使用GridView导出Excel实现方法。分享给大家供大家参考。具体实现方法如下: 希望本文所述对大家的asp.net程序设计有所帮助。

  • 本文向大家介绍使用SAP HANA Studio中的导出系统导出的信息,包括了使用SAP HANA Studio中的导出系统导出的信息的使用技巧和注意事项,需要的朋友参考一下 当您从主菜单使用导出选项时,它还会导出系统列表,其系统属性(名称,描述,主机名,实例等)将作为XML文件导出到指定位置。

  • 每个员工都会有自己的档案,主管可以查看在职员工的档案。使用 Java 创建一个员工实体类,然后通过构造方法创建一个名为“王洁”的员工,最后打印出员工档案信息。示例步骤如下。 (1) 创建 Person 类,在该类中定义个人基本信息属性,并定义一个带有参数的构造方法,代码如下: 在 Person 类中,首先声明了 5 个修饰符为 private 的成员变量(属性),然后定义了 Person 类的构造

  • 本文向大家介绍ajax实现excel报表导出,包括了ajax实现excel报表导出的使用技巧和注意事项,需要的朋友参考一下 利用ajax实现excel报表导出【解决乱码问题】,供大家参考,具体内容如下 背景 项目中遇到一个场景,要导出一个excel报表。由于需要token验证,所以不能用a标签;由于页面复杂,所以不能使用表单提交。初步考虑前端使用ajax,后端返回流,定义指定的header。 第一

  • 本文向大家介绍java实现Excel的导入、导出,包括了java实现Excel的导入、导出的使用技巧和注意事项,需要的朋友参考一下 一、Excel的导入 导入可采用两种方式,一种是JXL,另一种是POI,但前者不能读取高版本的Excel(07以上),后者更具兼容性。由于对两种方式都进行了尝试,就都贴出来分享(若有错误,请给予指正) 方式一、JXL导入  所需jar包 JXL.jar 方式二、POI