There are many examples of NPOI reading excel tables on the Internet, many of which return a Datatable object, but what I need is a list collection, here I need to convert the Datatable into the List collection I need, so I encapsulated a method, and the class object can return the corresponding list object.
First look at the renderings, as follows:
[{"Name":"Architect","Url":"https://itsvse.com/","Date":"2018-01-01","Remark":"0.1"},{"Name":"Little Scum","url":"https://www.itsvse.com/blog_xzz.html","Date":"2019-05-06","Remark" :"Test Import 1"}] template
There are 4 columns with many rows, and only 2 of them have data, as shown in the figure below:
characteristic
First, define a feature that means which column of the table corresponds to the object's attributes, and the code is as follows:
Object model
Read the table data, convert it into the corresponding object collection, and label the properties defined above in the attributes of the objects, the code is as follows:
Method of encapsulation
Nuget installs the NPOI plugin
The code is as follows:
Calling Code:
(End)
|