Skip to content

klob/ExcelDeserializer

Repository files navigation

功能介绍:

本库可以将Excel数据反序列化成便于操作的对象。

实现原理:

首先用Poi读取文件,得到文件头,对应类的属性,然后再读取所有表格数据,构建Json字符串,再借助fastjson反序列化为对象。

 

使用方法:

Excel表格数据
namesrore note
黄鹏8
张辉7
汪旭9
黄祚3优秀
李阳6
文凡7
赵伟3
梁琳3
public class TestModel {
public String name;
public String score;
public String note;

@Override
public String toString() {
    return "TestModel{" +
            "name='" + name + '\'' +
            ", score='" + score + '\'' +
            ", note='" + note + '\'' +
            "}\n ";
}

}

 

public class Test {
public static void main(String[] args) {
    File file = new File(System.getProperty("user.dir") + "\\excel" + '\\' + "transcript.xls");
    ExcelDeserializer controller = new ExcelDeserializer();
    List<TestModel> models=controller.read(file, TestModel.class);
}

}

结果

[TestModel{name='黄鹏', score='8', note=''}

, TestModel{name='张辉', score='7', note=''}

, TestModel{name='汪旭', score='9', note='优秀'}

, TestModel{name='黄祚', score='3', note=''}

, TestModel{name='李阳', score='6', note=''}

, TestModel{name='文凡', score='7', note=''}

, TestModel{name='赵伟', score='3', note=''}

, TestModel{name='梁琳', score='3', note=''} ]

About

Java library which can deserialize MS Excel data to java models

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages