前台

<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. 【第二篇】Volley的使用之加载图片

    Volley加载图片有两种方式: 1,ImageRequest 来对网络图片进行请求,放入请求队列,获取后现在在控件上面. 2,NetworkImageView 最为自定义控件来自动加载网络图片. 3 ...

  2. wps使用积累

    1.word加批注: 选中文字--插入--批注

  3. AVFoundation--AVPlayer

    // // AVPlayerNetViewController.m // PodsTest // // Created by ZhuYi on 16/4/29. // Copyright © 2016 ...

  4. Java Object 对象创建的方式 [ 转载 ]

    Java Object 对象创建的方式 [ 转载 ] @author http://blog.csdn.net/mhmyqn/article/details/7943411 显式创建 有4种显式地创建 ...

  5. Haskell 函数式编程

    Haskell是纯函数式编程,它强调不函数不改变外部世界状态,即,一个函数的输出只由函数接收的输入决定.那如何与外面沟通呢,比如读取一个文件内容并输出这个文件内容(字符串),显然这种函数非纯函数,因为 ...

  6. Docker安装目录

    操作系统为 # cat /etc/redhat-release CentOS Linux release (Core) docker安装 # yum install -y docker docker安 ...

  7. linux下合并pdf

    使用Gost Script和 PDFtk运行如下命令: #gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Linuxidc.pdf -dBATCH *.p ...

  8. c++的输入和输出流

    C++编译系统提供了用于输入输出的iostream类库.iostream这个单词是由3个部 分组成的,即i-o-stream,意为输入输出流.在iostream类库中包含许多用于输入输出的 类.常用的 ...

  9. Gentoo安装详解(三)-- 配置系统

    配置系统 系统信息: 文件系统信息: 创建/etc/fstab nano -w /etc/fstab 网络信息: Host name, Domainname, etc nano -w /etc/con ...

  10. sublime 3 最新 LICENSE

    http://blog.sina.com.cn/s/blog_68e267e10102v76h.html