<%@ page contentType="text/html;charset=UTF-8" language="java" %>
Title
很久不玩,都不记得jsp怎么配得了。
@RequestMapping("testjsp")
public ModelAndView test(){
ModelAndView modelAndView = new ModelAndView();
modelAndView.setViewName("status");
return modelAndView;
}
这是一个下载的Controller
@RequestMapping("testDownload")
public String testDownload(HttpServletRequest request, HttpServletResponse response/*, @RequestBody PieceCostParam pieceCostParam*/) throws Exception{
PieceCostParam pieceCostParam = new PieceCostParam();
PieceCostQuery pieceCostQuery = new PieceCostQuery();
pieceCostQuery.setCompanyName("杭州电子放假大学");
pieceCostParam.setPieceCostQuery(pieceCostQuery);
return excelExportService.testDownload(request, response, pieceCostParam);
}
@Override
public String testDownload(HttpServletRequest request, HttpServletResponse response, PieceCostParam pieceCostParam) throws Exception{
String fileName="excel文件";
//填充projects数据
List projects=costRelatedService.getAllPieceCost(pieceCostParam);
List
/**
* 导出Excel文档工具类
* [@author](http://my.oschina.net/arthor) 那位先生
* [@date](http://my.oschina.net/u/2504391) 2014-8-6
* */
public class ExcelUtil {
/**
* 创建excel文档,
* [@param](http://my.oschina.net/u/2303379) list 数据
* @param keys list中map的key数组集合
* @param columnNames excel的列名
* */
public static Workbook createWorkBook(List> list, String []keys, String columnNames[]) {
// 创建excel工作簿
Workbook wb = new HSSFWorkbook();
// 创建第一个sheet(页),并命名
Sheet sheet = wb.createSheet(list.get(0).get("sheetName").toString());
// 手动设置列宽。第一个参数表示要为第几列设;,第二个参数表示列的宽度,n为列高的像素数。
for(int i=0;i
差不多就是这样啦,你要是直接把代码拷过去肯定会报错啦,因为你没有我的实体类,在你找到我的代码之前肯定知道excel的操作啦,那这些你应该也能看懂,要是不知道,建议还是先看看excel的操作吧。