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("评审概况",);
//设置头部格式
WritableCellFormat headerFormat = getExcelHeadStyle();
//设置内容格式
WritableCellFormat contentFormat = getExcelContentStyle();
for(int i =; i < list.size(); i++){
sheet.setColumnView(, );//列宽
sheet.setColumnView(, );//列宽 sheet.setRowView(i, ); //行高
sheet.addCell(new Label(,i,ExportSummary.reviewGeneral[i],headerFormat));
sheet.addCell(new Label(,i,list.get(i),contentFormat));
} } catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
} private WritableCellFormat getExcelHeadStyle(){
WritableFont font = new WritableFont(WritableFont.createFont("宋体"),
, 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("宋体"),
, 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;
}

JXL生成Excel,并提供下载(1:生成Excel)的更多相关文章

  1. JXL生成Excel,并提供下载(2:提供下载)

    实现效果: 项目中使用JXL生成Excel,使生成的Excel可以让用户下载,如下图 一.生成Excel 二.提供下载 实现思路: 1.页面使用form表单提交方式(Ajax提交方式,我这里不行) 2 ...

  2. .net生成Excel,并下载

    生成Excel的方式有很多种,这里记录两个最简单的: 1.将数据保存为html,然后输出到客户端,保存为Excel文件: 2.通过\t\n生成字符串,然后输出到客户端,保存为Excel. 以上两者的原 ...

  3. php生成csv文件并提供下载及相关注意事项

    1.生成文件过程略,只要逗号分割就可以了 2.提供下载加上如下代码: header("Content-type: application/octet-stream"); heade ...

  4. java利用poi生成excel文件后下载本地

    1.该功能需要poi的jar包,链接: http://pan.baidu.com/s/1migAtNq 密码: 38fx. 2.首先新建一个实体类,用以存放单个数据 public class Test ...

  5. java实现点击查询数据生成excel文件并下载

    须先导入关键maven包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi& ...

  6. ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案 try.dot.net 的正确使用姿势 .Net NPOI 根据excel模板导出excel、直接生成excel .Net NPOI 上传excel文件、提交后台获取excel里的数据

    ASP.NET Core 2.2 : 十六.扒一扒新的Endpoint路由方案   ASP.NET Core 从2.2版本开始,采用了一个新的名为Endpoint的路由方案,与原来的方案在使用上差别不 ...

  7. 杂项收集,包括-发邮件、二维码生成、文件下载、压缩、导出excel

    本篇就最近工作解决的问题做个代码收集.包括以下几个方面:发邮件.二维码生成.文件下载.压缩.导出excel.有一种可用的解决方法就好,不求全面,不求原理. 1.发邮件: 命名空间:System.Net ...

  8. 使用Aspose.Cell控件实现Excel高难度报表的生成(三)

    在之前几篇文章中,介绍了关于Apsose.cell这个强大的Excel操作控件的使用,相关文章如下: 使用Aspose.Cell控件实现Excel高难度报表的生成(一) 使用Aspose.Cell控件 ...

  9. 懒人小工具:自动生成Model,Insert,Select,Delete以及导出Excel的方法

    在开发的过程中,我们为了节约时间,往往会将大量重复机械的代码封装,考虑代码的复用性,这样我们可以节约很多时间来做别的事情.最近跳槽到一节webform开发的公司,主要是开发自己公司用的ERP.开始因为 ...

  10. 懒人小工具1:winform自动生成Model,Insert,Select,Delete以及导出Excel的方法

       懒人小工具2:T4自动生成Model,Insert,Select,Delete以及导出Excel的方法    github地址:https://github.com/Jimmey-Jiang/J ...

随机推荐

  1. 手机网页唤醒app,

    1.在系统系统自带的浏览器中 首先做成HTML的页面,页面内容格式如下: <a href="[scheme]://[host]/[path]?[query]">启动应用 ...

  2. 图片路径转base64字节码

    package product; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOE ...

  3. python hashable

    判断一个对象是否hashable: hash(obj) 或 obj.__hash__() ,返回 hash 值 hashable 的有: int / float / tuple / str/  obj ...

  4. G.711是一种由国际电信联盟(ITU-T)制定的音频编码方式

    http://zh.wikipedia.org/zh-cn/G.711 ITU-T G.711 page ITU-T G.191 software tools for speech and audio ...

  5. mat 使用 分析 oom 使用 Eclipse Memory Analyzer 进行堆转储文件分析

    概述 对于大型 JAVA 应用程序来说,再精细的测试也难以堵住所有的漏洞,即便我们在测试阶段进行了大量卓有成效的工作,很多问题还是会在生产环境下暴露出来,并且很难在测试环境中进行重现.JVM 能够记录 ...

  6. webpack添加热更新

    之前的wbepack一直没有加上热更新,这是一种遗憾,今天终于加上去了,看不懂我博客的可以看这篇文章:http://blog.csdn.net/hyy1115/article/details/5302 ...

  7. android--------自定义控件 之 基本实现篇

    前面简单的讲述了Android中自定义控件中的几个方法,今天通过代码来实现一个简单的案例 自定义一个扇形图 自定义控件示例: 这里先介绍继承View的方式为例 public class Circula ...

  8. 进程锁,队列,JoinableQueue

    内容梗概: 1.进程同步(锁) 2.队列(重点) 3.生产者消费者模式 4.JoinableQueue([maxsize]) 5.信号量(了解) 6.事件 1.进程同步(锁) 并发编程让我们能更加充分 ...

  9. 【Java】【5】List随机取值

    //shuffle 打乱顺序 Collections.shuffle(list); //随机抽取1个值 System.out.println(list.get(0)); //随机抽取N个值 Syste ...

  10. 7. 反转整数(Reverse Integer) C++

    知识点: 内置变量 INT_MAX   INT_MIN 运算结果是否溢出的判断 判断pop>7即pop>INT_MAX%10 判断pop<-8即pop<INT_MIN%10 c ...