JXL Excel模版下载[列合并](2)

来源:互联网 发布:ansys15.0软件 编辑:程序博客网 时间:2024/06/07 16:47

效果图:
这里写图片描述

代码:

public void exportTemplateProceeds(HttpServletResponse response) {        // TODO Auto-generated method stub        WritableWorkbook workbook = null;        try {            try{                OutputStream outPutS = response.getOutputStream();                response.resetBuffer();                String outFileName=new String("合同收款明细补录模版".getBytes("gb2312"),"ISO8859-1") + ".xls";                response.setHeader("Content-disposition","attachment;filename="+outFileName);                response.setContentType("application/excel");                workbook = Workbook.createWorkbook(outPutS);                WritableSheet sheet = workbook.createSheet("sheet1", 0);                String title[] = {                          "还款日期|15",                        "设备成本|15",                        "租赁费|15",                        "应收租金|15",                        "实收租金|15",                        "支付日期|15",                        "逾期天数|15",                        "利息|15",                        "罚金|15",                        "调息差|14",                        "支付日期|14",                        "备注|20",                        "收款合计|15"                            };                Label label = null;                /** 字体设置 */                WritableFont headerFont = new WritableFont(WritableFont.ARIAL, 12,                        WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,                        Colour.BLACK);                WritableFont headerFont1 = new WritableFont(WritableFont.ARIAL, 12,                        WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,                        Colour.RED);                WritableCellFormat headerFormat1 = new WritableCellFormat(headerFont);                headerFormat1.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.BLACK);                headerFormat1.setAlignment(Alignment.LEFT);                headerFormat1.setBackground(Colour.YELLOW);                WritableCellFormat headerFormat = new WritableCellFormat(headerFont1);                headerFormat.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.BLACK);                headerFormat.setAlignment(Alignment.RIGHT);                headerFormat.setBackground(Colour.YELLOW);                /** 格式 */                WritableCellFormat colFormat = new WritableCellFormat(headerFont);                colFormat.setAlignment(Alignment.LEFT);                colFormat.setWrap(true);                WritableFont titleFont = new WritableFont(WritableFont.ARIAL, 12,                        WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,                        Colour.BLACK);                WritableCellFormat titleFormat = new WritableCellFormat(titleFont);                titleFormat.setAlignment(Alignment.CENTRE);                label = new Label(0,0,"注意:表中是最新数据",headerFormat1);                sheet.addCell(label);                sheet.mergeCells(0,0, title.length-1,0);                //合并单元格                WritableCellFormat wc = new WritableCellFormat(headerFont);                // 设置居中                wc.setAlignment(Alignment.CENTRE);                // 设置边框线                wc.setBorder(Border.ALL, BorderLineStyle.THIN);                // 设置单元格的背景颜色                wc.setBackground(jxl.format.Colour.GRAY_25);             //(列1,行,从列1到?,第几行)              sheet.mergeCells(1, 1, 3, 1);                label = new Label(1, 1, "租金",wc);                sheet.addCell(label);                sheet.mergeCells(4, 1, 6, 1);                label = new Label(4, 1, "租金项目收款",wc);                sheet.addCell(label);                sheet.mergeCells(7, 1, title.length-2, 1);                label = new Label(7, 1, "其他应收项目",wc);                sheet.addCell(label);                int col = 0;                for (int i = 0; i < title.length; i++) {                    String[] arrayTitle = title[i].split("\\|");                    label = new Label(col, 2, arrayTitle[0],titleFormat);                    sheet.addCell(label);                    // 设置列宽                    sheet.setColumnView(col, Integer.parseInt(arrayTitle[1]));                    col++;                }                workbook.write();                workbook.close();            }catch(Exception e1){                if(workbook!=null){                    workbook.close();                }            }        } catch (Exception e) {            e.printStackTrace();        }    }
0 0
原创粉丝点击