博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
后台处理excel下载输出流
阅读量:5766 次
发布时间:2019-06-18

本文共 4065 字,大约阅读时间需要 13 分钟。

前台

 

 

 

后台

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
tripList = tripService.findAll(); for(int i=0;i

 

转载于:https://www.cnblogs.com/wujixing/p/5948740.html

你可能感兴趣的文章
系列文章目录
查看>>
手把手教你如何提高神经网络的性能
查看>>
前端布局原理涉及到的相关概念总结
查看>>
递归调用 VS 循环调用
查看>>
使用sstream读取字符串中的数字(c++)
查看>>
树莓派下实现ngrok自启动
查看>>
javascript静态类型检测工具—Flow
查看>>
MachineLearning-Sklearn——环境搭建
查看>>
node学习之路(二)—— Node.js 连接 MongoDB
查看>>
Goroutine是如何工作的?
查看>>
《深入理解java虚拟机》学习笔记系列——垃圾收集器&内存分配策略
查看>>
TriggerMesh开源用于多云环境的Knative Event Sources
查看>>
GitLab联合DigitalOcean为开源社区提供GitLab CI免费托管
查看>>
通过XAML Islands使Windows桌面应用程序现代化
查看>>
区块链现状:从谨慎和批判性思维看待它(第二部分)
查看>>
苹果公司透露Siri新发音引擎的内部原理
查看>>
GCM 3.0采用类似方式向Android、iOS和Chrome发送消息
查看>>
如何成为一家敏捷银行
查看>>
Oracle在JavaOne上宣布Java EE 8将会延期至2017年底
查看>>
Javascript 深入浅出原型
查看>>