spring apache poi 生成excel报表文件。
我不是专业的做报表的,只是在一次偶然的机会中看到这段代码,最一个备份,以后说不定能提供个思路,如果对大家有帮助,欢迎参考:
前台form表单:
<form method="post" action="**.do"><ul 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 {@Overrideprotected 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);}}