maven 依赖
com.fasterxml.jackson.core jackson-core 2.0.0 org.apache.poi poi 3.15 org.apache.poi poi-ooxml 3.15 org.apache.poi poi-ooxml-schemas 3.15 org.apache.xmlbeans xmlbeans 2.6.0 com.fasterxml.jackson.dataformat jackson-dataformat-xml 2.0.0
package excel;import org.apache.poi.ss.usermodel.CellType;import org.apache.poi.xssf.usermodel.XSSFCell;import org.apache.poi.xssf.usermodel.XSSFRow;import org.apache.poi.xssf.usermodel.XSSFSheet;import org.apache.poi.xssf.usermodel.XSSFWorkbook;import java.io.InputStream;import java.text.SimpleDateFormat;import java.util.ArrayList;import java.util.HashMap;import java.util.List;import java.util.Map;/** * Created by xiaominzh on 2016/11/14. */public class ExcelExportNew { private static String getCellValue(XSSFCell cell,String columnType)throws Exception{ if("i".equals(columnType)){ return String.valueOf(cell.getNumericCellValue()); } if("d".equals(columnType)){ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); return sdf.format(cell.getDateCellValue()); } cell.setCellType(CellType.STRING); return cell.getRichStringCellValue().toString(); } private static ListloadColumnNames(XSSFRow row){ List array = new ArrayList (); int maxCellNum = row.getLastCellNum(); for(int i=0;i loadColumnTypes(XSSFRow row){ List array = new ArrayList (); int maxCellNum = row.getLastCellNum(); for(int i=0;i
测试excel文件
输出