日期:2014-05-16 浏览次数:20907 次
<form method="post" action="**.do"> <ul class="**"> <li><input type="submit" value="导出Excel文件"></input></li> </ul> </form>
package com.mark.test; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFRow; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; import org.springframework.web.servlet.view.document.AbstractExcelView; public class ExcelView extends AbstractExcelView { @Override protected void buildExcelDocument(Map arg0, HSSFWorkbook arg1, HttpServletRequest arg2, HttpServletResponse arg3) throws Exception { arg3.setContentType("application/octet-stream"); arg3.setHeader("Content-Disposition", "attchment;fileneame=test.xls"); HSSFSheet sheet = arg1.createSheet(); int index = 0; for (int i = 0; i < 10; i++) { HSSFRow row = sheet.createRow(index); } } public void buildCell(HSSFRow row, int index, double value) { HSSFCell cell = row.createCell((short) index, HSSFCell.CELL_TYPE_NUMERIC); cell.setCellValue(value); } }