标头值不匹配,因此无效的Excel文件

时间:2019-06-09 22:46:38

标签: java excel apache-poi xssf excel-reader

我正在尝试读取一个很大的excel文件,这是我拥有的代码的片段:

    File file = new File(dir);
    InputStream inputStream = new FileInputStream(file);

    // Excel Cell Mapping
    Map<String, String> cellMapping = new HashMap<>();
    cellMapping.put("HEADER", "Environment, MDL, Carrier ID, Account ID, Group ID, CAG Type");
    cellMapping.put("A", "environment");
    cellMapping.put("B", "mdl");
    cellMapping.put("C", "carrierId");
    cellMapping.put("D", "accountId");
    cellMapping.put("E", "groupId");
    cellMapping.put("F", "cagType");

    // The package open is instantaneous, as it should be.
    OPCPackage pkg = null;
    try {

        ExcelWorkSheetHandler<CAG> workSheetHandler = new ExcelWorkSheetHandler<>(CAG.class,
                cellMapping);

        pkg = OPCPackage.open(inputStream);

        ExcelSheetCallback sheetCallback = new ExcelSheetCallback() {
            private int sheetNumber = 0;

            @Override
            public void startSheet(int sheetNum, String sheetName) {
                this.sheetNumber = sheetNum;
                System.out.println("Started processing sheet number=" + sheetNumber
                        + " and Sheet Name is '"
                        + sheetName + "'");
            }

            @Override
            public void endSheet() {
                System.out.println("Processing completed for sheet number=" + sheetNumber);
            }
        };

        System.out.println("Constructor: pkg, workSheetHandler, sheetCallback");
        ExcelReader example1 = new ExcelReader(pkg, workSheetHandler, sheetCallback);
        example1.process();

问题在于此行:     example1.process(); 我收到以下错误:“标题值不匹配,因此无效的Excel文件!”。我不确定这是什么问题。我的excel文件上传到这里:https://github.com/vkyereme/ExcelFileLoad,列名与cellMapping中的内容匹配。该文件是xlsx excel文件。

0 个答案:

没有答案