前台

<ul class="navtop-right">
<li >
        <a href="/portal/trip/importExec" title="Data Download">
<img src="${pageContext.request.contextPath}/style/images/excel6.jpg" width=20px height=20px style="padding-top:15px"/>
</a>
</li>
</ul>

后台

HSSFRow row = sheet.createRow(0);: 创建第0行

HSSFCell c2 = row.createCell(2); 创建0行2列

HSSFCell c3 = row.createCell(4); 说明2列占了2列

sheet.addMergedRegion(new CellRangeAddress(0, 1,(short)0, (short)0)); 说明 合并单元格, 0行,1行合并成一行

@RequestMapping(value = "importExec", method = RequestMethod.GET)
@ResponseBody
public void importExec(HttpServletRequest request, HttpServletResponse response) throws UnsupportedEncodingException {
String fname = "Biztrip list";
response.reset();// 清空输出流
response.setHeader("Content-disposition","attachment; filename=" + fname + ".xls");// 设定输出文件头
response.setContentType("application/msexcel");//EXCEL格式 Microsoft excel
//创建workbook
HSSFWorkbook workbook = new HSSFWorkbook();
HSSFCellStyle style = workbook.createCellStyle();
style.setAlignment(HSSFCellStyle.ALIGN_CENTER); // 创建一个居中格式
HSSFFont f = workbook.createFont();
// f.setColor(HSSFColor.RED.index);
f.setBoldweight(HSSFFont.BOLDWEIGHT_NORMAL);//加粗
style.setFont(f);
style.setFillForegroundColor(HSSFColor.LIME.index);
style.setVerticalAlignment(HSSFCellStyle.VERTICAL_CENTER); //创建sheet页
HSSFSheet sheet = workbook.createSheet("Business Trip Info.");
//创建单元格
HSSFRow row = sheet.createRow(0);
HSSFCell c0 = row.createCell(0);
c0.setCellValue(new HSSFRichTextString("No"));
c0.setCellStyle(style); HSSFCell c1 = row.createCell(1);
c1.setCellValue(new HSSFRichTextString("Name"));
c1.setCellStyle(style); HSSFCell c2 = row.createCell(2);
c2.setCellValue(new HSSFRichTextString("Part"));
c2.setCellStyle(style); HSSFCell c3 = row.createCell(4);
c3.setCellValue(new HSSFRichTextString("Purpose"));
c3.setCellStyle(style); HSSFCell c4 = row.createCell(5);
c4.setCellValue(new HSSFRichTextString("Schedule"));
c4.setCellStyle(style); HSSFCell c5 = row.createCell(8);
c5.setCellValue(new HSSFRichTextString("Destination"));
c5.setCellStyle(style); HSSFCell c6 = row.createCell(11);
c6.setCellValue(new HSSFRichTextString("Report"));
c6.setCellStyle(style);
HSSFCell c7 = row.createCell(12);
c7.setCellValue(new HSSFRichTextString("Ref."));
c7.setCellStyle(style); HSSFRow row1 = sheet.createRow(1); HSSFCell c8 = row1.createCell(5);
c8.setCellValue(new HSSFRichTextString("Start"));
c8.setCellStyle(style);
HSSFCell c9 = row1.createCell(6);
c9.setCellValue(new HSSFRichTextString("End"));
c9.setCellStyle(style);
HSSFCell c10 = row1.createCell(7);
c10.setCellValue(new HSSFRichTextString("Days"));
c10.setCellStyle(style);
HSSFCell c11 = row1.createCell(8);
c11.setCellValue(new HSSFRichTextString("Country"));
c11.setCellStyle(style);
HSSFCell c12 = row1.createCell(9);
c12.setCellValue(new HSSFRichTextString("Region"));
c12.setCellStyle(style);
HSSFCell c13 = row1.createCell(10);
c13.setCellValue(new HSSFRichTextString("Dept."));
c13.setCellStyle(style); sheet.addMergedRegion(new CellRangeAddress(0, 1,(short)0, (short)0));
sheet.addMergedRegion(new CellRangeAddress(0, 1,(short)1, (short)1));
sheet.addMergedRegion(new CellRangeAddress(0, 1,(short)2, (short)3));
sheet.addMergedRegion(new CellRangeAddress(0, 1,(short)4, (short)4));
sheet.addMergedRegion(new CellRangeAddress(0, 0,(short)5, (short)7));
sheet.addMergedRegion(new CellRangeAddress(0, 0,(short)8, (short)10));
sheet.addMergedRegion(new CellRangeAddress(0, 1,(short)11, (short)11));
sheet.addMergedRegion(new CellRangeAddress(0, 1,(short)12, (short)12)); List<Trip> tripList = tripService.findAll();
for(int i=0;i<tripList.size();i++){
row=sheet.createRow((int)i+2);
Trip trip = (Trip)tripList.get(i);
row.createCell((short)0).setCellValue(new HSSFRichTextString(i+1+""));
row.createCell((short)1).setCellValue(new HSSFRichTextString(trip.getName()));
row.createCell((short)2).setCellValue(new HSSFRichTextString(trip.getPart()));
row.createCell((short)3).setCellValue(new HSSFRichTextString(trip.getSubPart()));
row.createCell((short)4).setCellValue(new HSSFRichTextString(trip.getPurpose()));
row.createCell((short)5).setCellValue(new HSSFRichTextString(trip.getScheduleStart()));
row.createCell((short)6).setCellValue(new HSSFRichTextString(trip.getScheduleEnd()));
row.createCell((short)7).setCellValue(new HSSFRichTextString(trip.getDuration()));
row.createCell((short)8).setCellValue(new HSSFRichTextString(trip.getDestination()));
row.createCell((short)9).setCellValue(new HSSFRichTextString(trip.getRegion()));
row.createCell((short)10).setCellValue(new HSSFRichTextString(trip.getDepartment()));
row.createCell((short)11).setCellValue(new HSSFRichTextString(trip.getReport()));
row.createCell((short)12).setCellValue(new HSSFRichTextString(trip.getReferrence()));
} try{
workbook.write(response.getOutputStream());
}
catch (Exception e){
e.printStackTrace();
}
}

后台处理excel下载输出流的更多相关文章

  1. 后台生成excel前端下载

    后台生成Excel时前端获取下载 Controller控制器: package com.example.test.controller; import com.example.test.common. ...

  2. ASP.NET Excel下载方法一览

    方法一 通过GridView(简评:方法比较简单,但是只适合生成格式简单的Excel,且无法保留VBA代码),页面无刷新 aspx.cs部分 using System; using System.Co ...

  3. Flex Excel下载

    最近做Flex里的Excel下载,用as3xls进行Excel导出后,Excel修改编辑后老出现:不能以当前格式保存...若要保存所做的更改,请单击“确定”,然后将其另存为最新的格式. 最后通过JAV ...

  4. 后台生成EXCEL文档,自定义列

    后台生成EXCEL文档,自定义列 //response输出流处理 //设置编码.类型.文件名 getResponse().reset(); getResponse().setCharacterEnco ...

  5. 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的路由方案,与原来的方案在使用上差别不 ...

  6. 一步步实现ABAP后台导入EXCEL到数据库【3】

    在一步步实现ABAP后台导入EXCEL到数据库[2]里,我们已经实现计划后台作业将数据导入数据库的功能.但是,这只是针对一个简单的自定义结构的导入程序.在实践应用中,面对不同的表.不同的导入文件,我们 ...

  7. 一步步实现ABAP后台导入EXCEL到数据库【1】

    在SAP的应用当中,导入.导出EXCEL文件的情况是一个常见的需求,有时候用户需要将大量数据定期导入到SAP的数据库中.这种情况下,使用导入程序在前台导入可能要花费不少的时间,如果能安排导入程序为后台 ...

  8. DevExpress中GridView Excel下载

    DevExpress中GridView提供了许多Excel下载的方法,如gridView.ExportToExcelOld(sfdExcelDown.FileName); 在修改Bug时,遇到这样问题 ...

  9. [转]50个极好的bootstrap 后台框架主题下载

    50个极好的bootstrap 后台框架主题下载 http://sudasuta.com/bootstrap-admin-templates.html 越来越多的设计师和前端工程师开始用bootstr ...

随机推荐

  1. 关于linux修改max user processes limits的问题

    我们都知道,ulimit -u 可以设置max user processes limits,但是往往在设置的过程中,这样直接修改,不仅只能临时生效,重启之后又无效了,而且老是会失败. 而一般来说,修改 ...

  2. 打开新世界的第一步:学习servlet

    什么是servlet? 是用Java编写的服务器端程序.其主要功能在于交互式地浏览和修改数据,生成动态Web内容. 创建servlet 一.创建一个web project 1)流程:eclipse-F ...

  3. javascript 判断是否使用的是ipad

    //判断是否使用的是ipad function isIpad(){ var ua = navigator.userAgent.toLowerCase(); if(/ipad/i.test(ua)) { ...

  4. 触发器实现对插入数据的字段更改 Oracle+SQL Server

    最近有个使用触发器实现对插入数据的某个列做更改的需求,因此整理了Oracle和SQL Server对于此类需求的触发器写法,本文仅提到了Insert触发器. 首先我们创建一张表: --创建Test表 ...

  5. MySQL字段自增自减的SQL语句

    MySQL的自增语句大家应该都很熟悉 也很简单 update `info` set `comments` = `comments`+1 WHERE `id` = 32 这样就可以了,但是有时候我们会涉 ...

  6. Linux服务器rsync自动备份

    一.在 server 端配置 1. 编辑配置文件 #vi /etc/rsyncd.conf 添加下面的配置参数: uid = nobody # 该选项指定当该模块传输文件时守护进程应该具有的uid.默 ...

  7. Struts2权威指南笔记

    Struts2权威指南笔记 1.mvc特点包括: ① 多个视图可以对应一个模型 ② 模型返回的数据与显示逻辑分离 ③ 应用层被分隔为三层,降低了各层之间的耦合,提供了应用的可扩展性 ④ 控制层的概念也 ...

  8. CSS3秘笈复习:第九章&第十章

    第九章 1.和链接有关的伪类: (1):link,未访问过的链接 (2):visited,已访问过的链接 (3):hover,鼠标悬停链接 (4):active,单击链接时 这四种方式一定要严格按上面 ...

  9. 图的两种遍历:DFS&BFS

    DFS和BFS在图中的应用: 图连通性判定:路径的存在性:图中是否存在环:求图的最小生成树:求图的关键路径:求图的拓扑排序. DFS:简单的说,先一直往深处走,直到不能再深了,再从另一条路开始往深处走 ...

  10. jquey(判断文本框输入的网址链接是否符合规则)

    今天遇到一个问题,我要在文本框中输入一个网址链接,使其跳转.但是如何验证,我首先想到了正则表达式.对的,就是你想的那样,我对正则一知半解,但在我哥哥帮助下,最终是 实现 了效果.在此,来一发,分享一下 ...