Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

读取单元格为空字符串问题 #102

Open
zkool opened this issue Jan 8, 2024 · 0 comments
Open

读取单元格为空字符串问题 #102

zkool opened this issue Jan 8, 2024 · 0 comments

Comments

@zkool
Copy link

zkool commented Jan 8, 2024

image

image

excel文件在这里获取的 https://udi.nmpa.gov.cn/download.html
下段代码中list里的TestEntity2的属性全是空字符串【注意:下载后的excel我用wps编辑并保存后,又没问题了。但是此处的场景是一个文件夹内好几百个excel,我不可能每个文件都编辑一遍。。。】

public class ImportTest {

    private static final String basePath = "D:\\opt\\upFiles\\temp\\UDID_DAY_20240107PART_1.xlsx";

    public static void main(String[] args) {
        File file = new File(basePath);
        ImportParams params = new ImportParams();
        params.setHeadRows(1);
        params.setStartSheetIndex(0);
        params.setSheetNum(1);
        List<TestEntity2> list = ExcelImportUtil.importExcel(file, TestEntity2.class, params);
        for (TestEntity2 testEntity2 : list) {
            System.out.println(testEntity2.getName());
            System.out.println(testEntity2.getAge());
            System.out.println(testEntity2.getStatus());
        }
    }
}

public class TestEntity2 {
    @Excel(name = "主键编号", width = 15)
    private String name;
    @Excel(name = "公开的版本号", width = 15)
    private String age;
    @Excel(name = "版本的状态", width = 15)
    private String status;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAge() {
        return age;
    }

    public void setAge(String age) {
        this.age = age;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }
}

最后断点也没定位到问题,只好在org.jeecgframework.poi.excel.imports.CellValueServer的getCellValue(String xclass, Cell cell, ExcelImportEntity entity)方法内加一层判断,不去执行setCellType()该方法。希望autopoi团队有更好的解决方案
//设置单元格类型
if(CellType.STRING != cell.getCellTypeEnum()){
cell.setCellType(CellType.STRING);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant