使用HSSFWorkbook导出Excel表格
一、加依赖或者导入jar包
去https://mvnrepository.com下载Apache POI
这里使用的3.9
二、上代码
/**
*
* <li>action控制层</li>
* @param req
* @param resp
* @throws Exception
*/
public void ExcelOut(HttpServletRequest req, HttpServletResponse resp) throws Exception{
// TODO Auto-generated method stub
List<Emp> selectAll = empService.selectAll();//从数据库查询出想要的数据
ExportExcelUtil.exportExcelBook(req, resp, selectAll);//进行EXCEL表格的绘制以及传输
}
这里我把它作为工具类,感觉有点不妥
package com.test.utils;
import java.io.IOException;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.hssf.usermodel.HSSFFont;
import org.apache.poi.hssf.usermodel.HSSF