• 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(列,行,内容,样式)
  • 相关阅读:
    DP2_第K优解
    DP1
    算法第一讲_动态规划
    CodeForces 487A Fight the Monster
    HDU 2899 Strange fuction
    lower_bound() 与 upper_bound()
    jQuery qrcode生成二维码
    本地代码上传至git仓库
    图片懒加载
    react-native学习(一)————使用react-native-tab-navigator创建底部导航
  • 原文地址:https://www.cnblogs.com/zzlcome/p/11414302.html
Copyright © 2020-2023  润新知