This article is a mirror article of machine translation, please click here to jump to the original article.

View: 42167|Reply: 4

[Source] .NET Core uses NPOI to read Excel and returns a generic List collection

[Copy link]
Posted on 9/17/2021 10:32:37 AM | | | |
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)





Previous:maven project \target\classes\META-INF\MANIFEST. MF (system...
Next:.NET Core develops Windows Forms programs
Posted on 9/17/2021 10:37:31 AM |
Thank you, big guy, for researching
Posted on 9/19/2021 7:35:26 PM |
This should be used
Posted on 9/22/2021 3:26:11 PM |
Study hard
Posted on 10/18/2021 8:57:53 PM |

Thank you, big guy, for researching
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com