zoukankan      html  css  js  c++  java
  • jxl导出excel(2)

        action中:
        private HttpServletResponse response;
        String fileurl = "excle/test.xls";
        String fileName = "fileName";
        
    public void exportExcel(String fileurl, String fileName,
                String title, HttpServletResponse response) 
                        throws BiffException, IOException, WriteException{
            WritableWorkbook book = getExportHead(fileurl, fileName, response);
            WritableSheet sheet = book.getSheet(0);
            // 定义格式 字体 下划线 斜体 粗体 颜色
            WritableFont sheetTitleFont = new WritableFont(WritableFont.createFont("宋体"), 22,WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
            WritableCellFormat sheetTitleCellFormat = new WritableCellFormat(sheetTitleFont); // 单元格定义
            sheetTitleCellFormat.setAlignment(Alignment.CENTRE);
            
            WritableFont cellFont = new WritableFont(WritableFont.createFont("宋体"), 11,WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE,Colour.BLACK);
            WritableCellFormat cellFormat = new WritableCellFormat(cellFont); // 单元格定义
            cellFormat.setWrap(true);
            cellFormat.setAlignment(Alignment.CENTRE);
            sheet.addCell(new Label(0, 0, fileName,sheetTitleCellFormat));//第一行标题
        
            WritableCellFormat writableCellFormat = new WritableCellFormat(cellFormat);
            String[] recordStr = new String[]{"serNo","name","age"};
            
            int row = 2;//从第2行开始
            
            List<Record> list = 查询数据;
            if(list != null && list.size() > 0)
            for(int i = 0;i < list.size() ;i++){
                for(int col = 0;col < recordStr.length;col++){
                    String result = list.get(i).getStr(recordStr[col]);
                    sheet.addCell(new Label(col, row+i, result, cellFormat));
                    }
                }
            }
            
            book.write();
            book.close();
            
        }

     另外:

    //TODO mergeCells(列,行,向左合并第几列,向下合并到第几行)
    sheet.mergeCells(0, 5, 3, 0);//合并第五行前三列
    //TODO Label(列,行,内容,样式)
  • 相关阅读:
    [NOI Online 提高组]序列
    微积分(下)
    微积分(上)
    [FJOI2018]领导集团问题
    [HNOI2015]亚瑟王
    [THUWC2017]随机二分图
    【模板】K级祖先(长链剖分)
    [CF438E]The Child and Binary Tree
    [洛谷P4841][集训队作业2013]城市规划
    [洛谷P4389]付公主的背包
  • 原文地址:https://www.cnblogs.com/zzlcome/p/11414302.html
Copyright © 2011-2022 走看看