码迷,mamicode.com
首页 > 其他好文 > 详细

jxl导出excel(2)

时间:2019-08-26 19:36:34      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:close   nbsp   cells   except   导出   cell   单元   ring   todo   

    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(列,行,内容,样式)

 

jxl导出excel(2)

标签:close   nbsp   cells   except   导出   cell   单元   ring   todo   

原文地址:https://www.cnblogs.com/zzlcome/p/11414302.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!