zoukankan      html  css  js  c++  java
  • JXL生成Excel,并提供下载(1:生成Excel)

    public String exportExcel(long id) {
        String preeReviewName = "文件名";
        
        String filePath = 路径名;
        WritableWorkbook wwb =null;
        try {
            wwb = Workbook.createWorkbook(new File(filePath + preeReviewName +".xls"));
            writeReviewGeneral(wwb, id);
            //一个Excel表若有多个sheet页,可以加多个
            wwb.write();
            wwb.close();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } 
        return preeReviewName;
    }
    
    private void writeReviewGeneral(WritableWorkbook wwb,long id){
        //获取数据库的数据
        PreeReviewInfo result = preeReviewInfoDS.getPreeReviewInfo(id).getT();
        //数据库各个字段的值放进List
        List<String> list = new ArrayList<String>();
        list.add(result.getPreeReviewName());//项目名称
        list.add(result.getPreeReviewTarget());//评审对象
        list.add(ReviewTypes.getDescription(result.getPreeReviewType()));//评审方式
        list.add(result.getPreeReviewScale());//评审规模
        list.add(result.getProcessName(););//项目当前阶段:所处过程
        list.add(result.getPreeCompere());//主持人
        list.add(result.getDocumentCreator());//作者
        list.add(result.getPreeRegistrar());//记录员
        list.add(result.getPreeActor());//评审员
        list.add(result.getExpert());//关键资源:专家
        try {
            WritableSheet sheet = wwb.createSheet("评审概况",0);
            //设置头部格式
            WritableCellFormat headerFormat = getExcelHeadStyle();
            //设置内容格式
            WritableCellFormat contentFormat = getExcelContentStyle();
            for(int i =0; i < list.size(); i++){
                sheet.setColumnView(0, 25);//列宽
                sheet.setColumnView(1, 25);//列宽
                
                sheet.setRowView(i, 300);    //行高
                sheet.addCell(new Label(0,i,ExportSummary.reviewGeneral[i],headerFormat));
                sheet.addCell(new Label(1,i,list.get(i),contentFormat));
            }
    
        } catch (RowsExceededException e) {
            e.printStackTrace();
        } catch (WriteException e) {
            e.printStackTrace();
        } 
    }
    
    
    private WritableCellFormat getExcelHeadStyle(){
        WritableFont font = new WritableFont(WritableFont.createFont("宋体"), 
                11, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.RED);
        WritableCellFormat headerFormat = new WritableCellFormat(NumberFormats.TEXT); 
        headerFormat.setFont(font);
        try {
            //内容水平居中显示
            headerFormat.setAlignment(jxl.format.Alignment.CENTRE);
        } catch (WriteException e) {
            e.printStackTrace();
        } 
        
        return headerFormat;
    }
    
    private WritableCellFormat getExcelContentStyle(){
        WritableFont font = new WritableFont(WritableFont.createFont("宋体"), 
                11, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, jxl.format.Colour.BLACK);
        WritableCellFormat contentFormat = new WritableCellFormat(NumberFormats.TEXT); 
        contentFormat.setFont(font);
        try {
            //允许换行
            contentFormat.setWrap(true);
        } catch (WriteException e) {
            e.printStackTrace();
        }
        return contentFormat;
    }
  • 相关阅读:
    unity 编辑器 对比两次节点信息 查看新增节点和消失节点。
    根据模型的Height进行颜色的渐变 (Shader相关)
    TimeLine一些思考
    (unity小工具)C# 获取选择的Gameobject对象被引用的类名和字段名
    copy节点相对prefab的路径 (unity小工具)
    使用LineRender绘制网格线
    龙书11_chapter_6 二:HillsDemo解析
    龙书11_chapter_6 一:一般绘制流程
    龙书11_chapter_4 三:每一小节关键点
    龙书11_chapter_4 二:习题中的Adapter
  • 原文地址:https://www.cnblogs.com/Donnnnnn/p/8444555.html
Copyright © 2011-2022 走看看