1.引入pom依赖
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>3.9</version>
</dependency>
2.工具类
package com.example.demo.yiran.util;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
import org.apache.poi.ss.usermodel.*;
import org.springframework.web.util.HtmlUtils;
import sun.misc.BASE64Encoder;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.OutputStream;
import java.net.URLEncoder;
public class ExcelUtil {
public static void export(String[] title, String sheetName, String filename, String[][] values, Workbook workbook,
Integer headRowNum, CellStyle headStyle, CellStyle valueStyle, HttpServletRequest request,
HttpServletResponse response) throws Exception {
// 创建头部
Cell cell = null;
Sheet sheet = workbook.createSheet(sheetName);
headStyle.setFillPattern(HSSFCellS