1
我跟隨mkyong Jexcel with Spring教程,一切看起來都很好。它可以創建excel文件和寫入表格,除了一件事是我無法更改我的excel文件名嗎?它將顯示與我的控制器鏈接相同的文件名。如何在Spring mvc中設置Jexcel的名字?
這裏是例子
<li><h3><a href="report.html">Jexcel Showcase</a></h3></li>
它始終創建一個excel文件名 「report.html.xls」。任何人都知道如何更改文件名?
這是我的控制器
@RequestMapping(method=RequestMethod.POST)
protected ModelAndView handleRequestInternal(HttpServletRequest request,
HttpServletResponse response) throws Exception {
//dummy data
revenueData.put("Jan-2010", "$100,000,000");
revenueData.put("Feb-2010", "$110,000,000");
revenueData.put("Mar-2010", "$130,000,000");
revenueData.put("Apr-2010", "$140,000,000");
revenueData.put("May-2010", "$200,000,000");
return new ModelAndView("jexcelSuccess","revenueData",revenueData);
}
和buildExcelDocument方法方法
protected void buildExcelDocument(Map model, WritableWorkbook workbook,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
Map<String,String> revenueData = (Map<String,String>) model.get("revenueData");
WritableSheet sheet = workbook.createSheet("Revenue Report", 0);
WritableSheet sheet2 = workbook.createSheet("Test Report", 1);
WritableSheet sheet3 = workbook.createSheet("Hello Report", 2);
sheet.addCell(new Label(0, 0, "Month"));
sheet.addCell(new Label(1, 0, "Revenue"));
int rowNum = 1;
for (Map.Entry<String, String> entry : revenueData.entrySet()) {
//create the row data
sheet.addCell(new Label(0, rowNum, entry.getKey()));
sheet.addCell(new Label(1, rowNum, entry.getValue()));
rowNum++;
}
}
預先感謝, 沃爾瑪
謝謝你,拉爾夫。 你再次幫助我。 :) – Vtanathip