导出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& ...
随机推荐
- Emoji表情符号录入MySQL数据库失败解决
让MySQL支持Emoji表情,涉及无线相关的 MySQL 数据库建议都提前采用 utf8mb4 字符集. utf8mb4和utf8到底有什么区别呢?原来以往的mysql的utf8一个字符最多3字节, ...
- UVA 11297 线段树套线段树(二维线段树)
题目大意: 就是在二维的空间内进行单个的修改,或者进行整块矩形区域的最大最小值查询 二维线段树树,要注意的是第一维上不是叶子形成的第二维线段树和叶子形成的第二维线段树要 不同的处理方式,非叶子形成的 ...
- oc--UINavigationController控制器
UINavigationController导航控制器 UINavigationController导航控制器,是多个界面间跳转的重要元素,可以理解为它存储着多个viewController,它的存储 ...
- 使用rem缩放网页的javascript代码
<script type="text/javascript"> (function(doc, win) { var docEl = doc.documentElemen ...
- pyinstaller 用法
参考:http://pythonhosted.org/PyInstaller/#installing-pyinstaller 1.下载pyinstaller和PyWin32 目前pyinstalle ...
- C# winform 模拟键盘鼠标操作
1.获取鼠标位置 private void timer1_Tick(object sender, EventArgs e) { // timer1.Stop(); // int x = Control ...
- JS Math.max() 函数
Math.max(a,b,...,x,y) -- 返回数个数字中较大的值 max是maximum的缩写,中文"最大量"的意思 max函数语法Math.max(a,b,...,x,y ...
- 谈谈eclipse使用技巧
俗话说的好啊,“工于利启事,必先善其器”,如果说你的编程功底是一个枪法的话,那么强大的eclipse就是android战士们最好的武器. 这里,我们来总结eclipse的使用技巧,从而使我们的编程达到 ...
- C#实现Excel的导入导出
Excel作为日常使用工具,在开发过程中经常会用到其导入导出功能.经过一个小的练习,学习了下导入导出功能. 导出篇: 从数据库查询到所要导出的数据,以xml的形势保存下来,最后输出excel的格式,保 ...
- 杭电ACM1005
Number Sequence Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)T ...