导出也做了很多遍了,还是发现好记性不如烂笔头,还是记下来。

     public void exportLog(HttpServletRequest request,HttpServletResponse response,
@ModelAttribute(CommonUtils.SESSION_USER) UserContext uc,ModelMap model,String logId
) {
//获得信息列表
List<GTL> lgtgl = logManagerImpl.findLogByKspcAndDwbhAndAreaIdAndLogId(batchId, code, areaId,Id);//id是为了能够在导出以下选项时候用的,导出全部可以穿  //  一个空参数 areaid是为了权限验证用的
//将结果集保存到excel
//取文件存放路径并新建文件
String path = this.getClass().getClassLoader().getResource("").getPath();
PropertieFile cf = new PropertieFile(path + "/spf.properties");
String filePath=cf.getValue("global.export.student");
String tempName=GetRandomName.ConfirmId(32)+".xls";
File file = new File(filePath);//导出文件存放的位置
if(!file.exists()) {
file.mkdirs();
}
WritableWorkbook wwb;
try {
wwb = Workbook.createWorkbook(new File(filePath+tempName));
WritableFont wf = new WritableFont(WritableFont.TIMES, 18, WritableFont.BOLD , false); //对文字style设置
WritableCellFormat wff = new WritableCellFormat(wf);
Color color = Color.decode("#87CEFF"); // 自定义的颜色
wwb.setColourRGB(Colour.ORANGE, color.getRed(),color.getGreen(), color.getBlue());
wff.setBackground(Colour.ORANGE);//设置单元格颜色
wff.setAlignment(Alignment.CENTRE); // 设置对齐方式
wff.setVerticalAlignment(VerticalAlignment.CENTRE);
WritableSheet ws = wwb.createSheet("导出信息", 0);// 建立工作簿
ws.setColumnView(0, 20); // 设置列的宽度
ws.setRowView(0, 600); // 设置行的高度
ws.setColumnView(1, 20); // 设置列的宽度
ws.setRowView(1, 600); // 设置行的高度 Label label1 = new Label(0, 0, "第一列表头",wff);
         Label label1 = new Label(0, 0, "第二列表头",wff);
 ws.addCell(label1);// 放入工作簿  for(int k=0;k<lgtgl.size();k++){  WritableFont wf_1 = new WritableFont(WritableFont.TIMES, 12, WritableFont.NO_BOLD , false); //对文字style设置  WritableCellFormat wff_1 = new WritableCellFormat(wf_1);  wff_1.setAlignment(Alignment.CENTRE); // 设置对齐方式   wff_1.setVerticalAlignment(VerticalAlignment.CENTRE);   wff_1.setBorder(Border.ALL, BorderLineStyle.THIN,Colour.BLACK);  label1 = new Label(0, k + 1, lgtgl.get(k).getd1l()().toString().trim(),wff_1);// 建立第一列              
            	 String type=lgtgl.get(k).getd2l().toString().trim();
if(("0").equals(type)){
type="采集";
}
if(("1").equals(type)){
type="认证";
}
if(("2").equals(type)){
type="考务";
}
if(("3").equals(type)){
type="押运";
}
label2 = new Label(1, k + 1, type,wff_1);// 建立第二列
                  ws.addCell(label1);// 放入工作簿
}
// 写入Exel工作表
wwb.write();
// 关闭Excel工作薄对象
wwb.close();
} catch (IOException e) {
e.printStackTrace();
} catch (RowsExceededException e) {
e.printStackTrace();
} catch (WriteException e) {
e.printStackTrace();
}
//返回文件流
response.setCharacterEncoding("UTF-8");
try {
response.setHeader("Content-Disposition", "attachment;filename=\""
+ new String("信息导出.xls".getBytes("gb2312"), "ISO8859-1")
+ "\"");
OutputStream out = response.getOutputStream();
response.setContentType("xls");
FileOperation fileOperation=new FileOperation();
IOUtils.copy(fileOperation.readFile(filePath+tempName), out);
out.flush();
out.close();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}

导出excel表格。的更多相关文章

  1. PHP导入导出excel表格图片(转)

    写excel的时候,我用过pear的库,也用过pack压包的头,同样那些利用smarty等作的简单替换xml的也用过,csv的就更不用谈了.呵呵.(COM方式不讲了,这种可读的太多了,我也写过利用wp ...

  2. java中使用jxl导出Excel表格详细通用步骤

    该方法一般接收两个参数,response和要导出的表格内容的list. 一般我们将数据库的数据查询出来在页面进行展示,根据用户需求,可能需要对页面数据进行导出. 此时只要将展示之前查询所得的数据放入s ...

  3. .NET环境下导出Excel表格的两种方式和导入两种类型的Excel表格

    一.导出Excel表格的两种方式,其中两种方式指的是导出XML数据类型的Excel(即保存的时候可以只需要修改扩展名为.xls)和真正的Excel这两种. using System; using Sy ...

  4. java导出excel表格

    java导出excel表格: 1.导入jar包 <dependency> <groupId>org.apache.poi</groupId> <artifac ...

  5. 使用NPOI将数据库里信息导出Excel表格并提示用户下载

    使用NPOI进行导出Excel表格大家基本都会,我在网上却很少找到导出Excel表格并提示下载的 简单的代码如下 //mvc项目可以传多个id以逗号相隔的字符串 public ActionResult ...

  6. VB.NET版机房收费系统---导出Excel表格

    datagridview,翻译成中文的意思是数据表格显示,使用DataGridView控件,能够显示和编辑来自不同类型的数据源的表格,将数据绑定到DataGridView控件很easy和直观,大多数情 ...

  7. C#导出Excel表格方法

    using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using NPOI.SS.Formula.Functions; using System.Re ...

  8. Java代码导入导出 Excel 表格最简单的方法

    import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStrea ...

  9. js导出Excel表格

    js导出Excel表格 直接上代码: 红色部分:如果表格数据中有“1/1”这样的值,会在导出的Excel中转化为日期“1月1日”,所以才加上了红色那两句.如果返回值中没有这样的格式,红色部分可以不写. ...

  10. Spring Boot 导出Excel表格

    Spring Boot 导出Excel表格 添加支持 <!--添加导入/出表格依赖--> <dependency> <groupId>org.apache.poi& ...

随机推荐

  1. dede日期时间标签调用大全

    dedecms最强大的功能就是调用标签,可以变换出各种样式的文章形式出来,本节将DEDECMS调用时间的样式做一个总结,基本所有的时间调用样式都有了,日期时间格式 (利用strftime()函数格式化 ...

  2. Haskell Platform (windows)

    一.下载地址:https://www.haskell.org/platform/windows.html Haskell Platform 整合了 Glasgow Haskell Compiler,W ...

  3. ICEM(2)—机翼翼稍网格绘制

    有时我们需要观察翼尖涡,这就需要将机翼全部被网格包围.但是网上比较多的教程都是机翼边缘即为网格边缘,机翼位于网格内部的不多.若是直接将网格拉伸,则会产生结构和非结构网格交错的情况.下面是绘制步骤 1. ...

  4. iOS权限问题

    判断相机权限: NSString *mediaType = AVMediaTypeVideo; AVAuthorizationStatus authStatus = [AVCaptureDevice ...

  5. TPCH Benchmark with Impala

    1. 生成测试数据在TPC-H的官网http://www.tpc.org/tpch/上下载dbgen工具,生成数据http://www.tpc.org/tpch/spec/tpch_2_17_0.zi ...

  6. myeclipse激活法,可以试一试

    我的myeclipse2014也是这样激活: 第一步:输入任意用户名 第二步:点击Systemid... 按钮,自动生成本机器的systemid. 第三步: 点菜单Tools->RebuildK ...

  7. Basic linux command-with detailed sample

    Here I will list some parameters which people use very ofen, I will attach the output of the command ...

  8. VisualSVN5.0.1补丁原创发布

    VisualSVN5.0.1补丁原创发布

  9. 导出Excel

    一.asp.net中导出Execl的方法:在asp.net中导出Execl有两种方法,一种是将导出的文件存放在服务器某个文件夹下面,然后将文件地址输出在浏览器上:一种是将文件直接将文件输出流写给浏览器 ...

  10. cookie 保存上次访问url方法

    if (Session[Enums.UserInfoSeesion] == null) { HttpCookie cookie = Request.Cookies[Enums.UserLastAcce ...