springmvc下载excel大体步骤
来源:互联网 发布:携程移动端日历js插件 编辑:程序博客网 时间:2024/06/07 00:01
package com.tvs.controller;import java.io.IOException;import java.io.OutputStream;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.poi.hssf.usermodel.HSSFWorkbook;import org.apache.poi.ss.usermodel.Cell;import org.apache.poi.ss.usermodel.CellStyle;import org.apache.poi.ss.usermodel.Font;import org.apache.poi.ss.usermodel.IndexedColors;import org.apache.poi.ss.usermodel.Row;import org.apache.poi.ss.usermodel.Sheet;import org.apache.poi.ss.usermodel.Workbook;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.RequestMapping;@Controller@RequestMapping({"/excel"})public class ExcelController{ @RequestMapping(method={org.springframework.web.bind.annotation.RequestMethod.GET}) public void dewnExcel(HttpServletRequest request, HttpServletResponse response) { HSSFWorkbook wb = (HSSFWorkbook)createExcel(); try { response.setHeader("Content-Disposition", "attachment; filename=appointmentUser.xls"); response.setContentType("application/vnd.ms-excel; charset=utf-8"); OutputStream out = response.getOutputStream(); wb.write(out); out.flush(); out.close(); } catch (IOException e) { e.printStackTrace(); } } public Workbook createExcel() { Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("第一页"); for (int i = 0; i < 2; i++) { sheet.setColumnWidth((short)i, 5355); } Row row = sheet.createRow(0); CellStyle cs = wb.createCellStyle(); CellStyle cs2 = wb.createCellStyle(); Font f = wb.createFont(); Font f2 = wb.createFont(); f.setFontHeightInPoints((short)10); f.setColor(IndexedColors.BLACK.getIndex()); f.setBoldweight((short)700); f2.setFontHeightInPoints((short)10); f2.setColor(IndexedColors.BLACK.getIndex()); cs.setFont(f); cs.setBorderLeft((short)1); cs.setBorderRight((short)1); cs.setBorderTop((short)1); cs.setBorderBottom((short)1); cs.setAlignment((short)2); cs2.setFont(f2); cs2.setBorderLeft((short)1); cs2.setBorderRight((short)1); cs2.setBorderTop((short)1); cs2.setBorderBottom((short)1); cs2.setAlignment((short)2); for (int i = 0; i < 2; i++) { Cell cell = row.createCell(i); cell.setCellValue("张三" + i); cell.setCellStyle(cs); } for (short i = 1; i < 2; i = (short)(i + 1)) { Row row1 = sheet.createRow(i); for (short j = 0; j < 2; j = (short)(j + 1)) { Cell cell = row1.createCell(j); cell.setCellValue("李四" + j); cell.setCellStyle(cs2); } } return wb; }}
阅读全文
0 0
- springmvc下载excel大体步骤
- Java导出excel大体步骤
- SpringMvc下载excel文件
- SpringMvc下载excel文件
- SpringMvc下载excel文件
- 下载、安装springmvc框架步骤
- springmvc 利用模板 下载excel
- Springmvc下载Excel案例(一)
- Springmvc下载Excel案例(二)
- Springmvc下载Excel案例(三)
- Java Web 面试大体步骤
- java 关于excel下载 struts2 servlet springmvc
- springmvc导出excel并弹出下载框
- springMVC实现Excel文件下载功能
- springmvc+excel多表头模板下载功能
- springmvc导出excel并弹出下载框
- SpringMVC 下载Excel模板和导入数据
- UNIX下安装oracle大体步骤
- 数据录入->数据采集->数据清洗(优化策略)
- java泛型的实现原理
- Javascript获取select下拉框选中的的值
- 【计网】应用层概述
- Linux学习第二十篇--大爱vim之高级操作
- springmvc下载excel大体步骤
- 查准率-查全率
- MySQL DATE_FORMAT() 函数
- PHP用支付宝沙箱账号测试支付功能
- [AOSP]编译Android6.0源码过程中出现AssertionError错误
- windows 安装cudnn
- Source Insight 4.0 编码设置
- Java中Static Class及静态内部类和非静态内部类的不同
- android button 选中点击效果