1.pom.xml配置依赖包
org.apache.poi
poi
3.9
org.apache.poi
poi-ooxml
3.9
2.excel导出工具类
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.apache.poi.ss.usermodel.BorderStyle;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Font;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.IndexedColors;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.xssf.streaming.SXSSFWorkbook;
import org.apache.poi.xssf.usermodel.XSSFCellStyle;
import org.apache.poi.xssf.usermodel.XSSFDataFormat;
public class ExportExcel {
/**
* 导出excel
*
* @param response
* HttpServletResponse
* @param list
* 导出数据集合
* @param lables
* 表头数组
* @param fields
* key数组
* @param title
* 文件名
*/
public static void export(HttpServletResponse response,List
3.业务层调用
//导出
@RequestMapping("/export")
public String export(Model model,HttpServletRequest request,HttpServletResponse response) {
SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println("导出开始时间:"+format.format(new Date()));
List> list = jkconfigDao.exportByRksj();//查询业务数据
String[] lables = new String[]{"号码","入库时间"};//表头数组
String[] fields = new String[]{"HM","RKSJ"};//查询数据对应的属性数组
String title = "测试.xlsx";
ExportExcel.export(response, list, lables, fields, title);
System.out.println("导出结束时间:"+format.format(new Date()));
return null;
}