文件下载公共类
package com.sw.api.utils;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.HorizontalAlignment;
import org.apache.poi.ss.usermodel.VerticalAlignment;
import org.apache.poi.xssf.usermodel.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
public class ExportUtil {
public void export(HttpServletResponse response) throws IOException {
//根据文件流创建XSSFWorkbook对象
XSSFWorkbook wb = new XSSFWorkbook();
//XSSFSheet sheet = wb.getSheetAt(0);
XSSFSheet sheet = wb.createSheet("Sheet1");
sheet.setDefaultColumnWidth(16);//设置默认列宽
sheet.setDefaultRowHeightInPoints(20);//设置默认行高
//设置样式;
XSSFCellStyle style = wb.createCellStyle();
//设置水平对齐的样式为居中对齐;
style.setAlignment(HorizontalAlignment.CENTER);
//设置垂直对齐的样式为居中对齐;
style.setVerticalAlignment(VerticalAlignment.CENTER);
XSSFRow rowRowName = sheet.createRow(0);
//设置水印
WaterMarkUtil.putWaterMarkToExcel(wb);
// 将列头设置到sheet的单元格中
String[] rowName = new String[] {
"id", "年龄", "名称"};
for(int n=0;n<rowName.length;n++){
XSSFCell cellRowName = rowRowName.<