导出excel表格。
导出也做了很多遍了,还是发现好记性不如烂笔头,还是记下来。
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表格。的更多相关文章
- PHP导入导出excel表格图片(转)
写excel的时候,我用过pear的库,也用过pack压包的头,同样那些利用smarty等作的简单替换xml的也用过,csv的就更不用谈了.呵呵.(COM方式不讲了,这种可读的太多了,我也写过利用wp ...
- java中使用jxl导出Excel表格详细通用步骤
该方法一般接收两个参数,response和要导出的表格内容的list. 一般我们将数据库的数据查询出来在页面进行展示,根据用户需求,可能需要对页面数据进行导出. 此时只要将展示之前查询所得的数据放入s ...
- .NET环境下导出Excel表格的两种方式和导入两种类型的Excel表格
一.导出Excel表格的两种方式,其中两种方式指的是导出XML数据类型的Excel(即保存的时候可以只需要修改扩展名为.xls)和真正的Excel这两种. using System; using Sy ...
- java导出excel表格
java导出excel表格: 1.导入jar包 <dependency> <groupId>org.apache.poi</groupId> <artifac ...
- 使用NPOI将数据库里信息导出Excel表格并提示用户下载
使用NPOI进行导出Excel表格大家基本都会,我在网上却很少找到导出Excel表格并提示下载的 简单的代码如下 //mvc项目可以传多个id以逗号相隔的字符串 public ActionResult ...
- VB.NET版机房收费系统---导出Excel表格
datagridview,翻译成中文的意思是数据表格显示,使用DataGridView控件,能够显示和编辑来自不同类型的数据源的表格,将数据绑定到DataGridView控件很easy和直观,大多数情 ...
- C#导出Excel表格方法
using NPOI.SS.UserModel; using NPOI.XSSF.UserModel; using NPOI.SS.Formula.Functions; using System.Re ...
- Java代码导入导出 Excel 表格最简单的方法
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStrea ...
- js导出Excel表格
js导出Excel表格 直接上代码: 红色部分:如果表格数据中有“1/1”这样的值,会在导出的Excel中转化为日期“1月1日”,所以才加上了红色那两句.如果返回值中没有这样的格式,红色部分可以不写. ...
- Spring Boot 导出Excel表格
Spring Boot 导出Excel表格 添加支持 <!--添加导入/出表格依赖--> <dependency> <groupId>org.apache.poi& ...
随机推荐
- 1526. Martian Plates
http://acm.timus.ru/problem.aspx?space=1&num=1526 题目大意: 可以从n个碟子中任选一个放在桌子上(不断往上放),也可以把桌子上最顶端的盘子拿走 ...
- http Content-type对照表
http://tools.jb51.net/table/http_content_type Content-Type,内容类型,一般是指网页中存在的Content-Type,用于定 义网络文件的类型和 ...
- 为bootstrap添加更多自定义图标
From: http://blog.csdn.net/mengxiangfeiyang/article/details/45224731 Twitter Bootstrap 真是前端开发的瑞士军刀,作 ...
- imx6 gpio irq
/***************************************************************** * gpio irq * * 一直以来都没了解过gpio的irq, ...
- android-oldman之TitleBar
随着大众口味的不断提高,对app要的开发的要求也不断提高,开发人员们要在app上展示的东西安也越来越多,android早期的一些控件慢慢的不不能满足开发的要求了,比如TitleBar的应用的就没有原来 ...
- as3 代码优化之pmd
首先下载com.abobe,ac.pmd.eclipse_...jar 和 flex-pmd-all-in-one...zip俩文件 前面一个装在xx\adobe flash builder xx\e ...
- Windows 10 RTM 官方正式版
Windows 10 各版本区别: Windows 10 家庭版:供家庭用户使用Windows 10 专业版:供小型企业使用 在家庭版基础上增加了域账号加入.bitlocker.企业商店等功能Wind ...
- js⑤
##返回在制定位置的的字符 var result = str.charAt(1); console.log(result); console.log(str[1]); ##返回在指定的位置的字符 ...
- 史上最简单的socket
1. client import java.io.IOException; import java.io.OutputStream; import java.net.Socket; import ja ...
- 关于XML文档
很多人觉得XML很简单,但我想说其实一点也不简单,特别是在当今被各种web文档充斥的世界里有必要对XML进行一定程度的研究.下面的几篇博客将对XML技术进行简短的说明.