一、添加依赖
org.apache.poi
poi
3.8
org.apache.poi
poi-ooxml
3.8
二、工具类
根据文件后缀判断 2003 || 2007 || 2010 格式。
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
import java.io.InputStream;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;
public class ExcelUtils {
private static Workbook wb;
private static Sheet sheet;
private static Row row;
private static final String EXCEL_XLS = “xls”;
private static final String EXCEL_XLSX = “xlsx”;
/**
-
读取表头
-
@param inputStream 文件