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 List
 loadColumnNames(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
> result = new ArrayList
>();        List
 columnTypes = loadColumnTypes(sheet.getRow(0));        List
 columnNames = loadColumnNames(sheet.getRow(1));        for (int i = 3; i <= rows; i++) {            XSSFRow row = sheet.getRow(i);            int maxCellNum = row.getLastCellNum();            Map
 item = new HashMap
();            for (int cellIndex = 0; cellIndex < maxCellNum; cellIndex++) {                XSSFCell cell = row.getCell(cellIndex);                String columnName = columnNames.get(cellIndex);                String columnType = columnTypes.get(cellIndex);                String value = null;                try {//                    cell.setCellType(CellType.STRING);                    value = getCellValue(cell,columnType);                } catch (Exception e) {                    System.err.println("row:"+i+",column:"+cellIndex);                    System.err.println(e.getMessage());                    break;                }                item.put(columnName, value);            }            result.add(item);        }        System.out.println(JSONUtil.getJSONString(result));    }    public static void main(String[] args) throws Exception {        convertExcelToJSON("shop_sale_type_list.xlsx","shop_sale_type_list");    }}

测试excel文件

输出