ASP. NET MVC5 use NPOI to export Exceld and return to the browser for download. npoiexceld
I. What is NPOI?This project is the. NET version of the poi Java project located at http://poi.apache.org. POI is an open-source project that helps you read/write xls, doc, and pptfiles. It is widely used.2. NPOI advantagesOne. It is free to use most of the Excel functions (cell style, data format, formula, etc.) C. Supports xls, xlsx, and docx. D. Designed to be interface-oriented (look at the NPOI. SS namespace), it not only supports export, but also supports import of F .. Net 2.0 is based on xlsx and docx (although we also support. NET 4.0) G. Success stories from around the world H. A large number of basic examples. Independent from isolated storage3. How to reference NPOI in a projectYou can choose NuGet management in the project-manage the NuGet package of the solution to be introduced to the project.
Or go to the official website: http://npoi.codeplex.com/download dll (you can select. net2.0 or. net4.0 dll) and add references to the website.
Let's talk a little bit about code.
Here I wrote an Excel help class.
Namespace to be used
Using NPOI. HSSF. UserModel;
Using NPOI. XSSF. UserModel;
Using NPOI. SS. UserModel;
In the red frame, the DisPlayName attribute of the view object is obtained through reflection and then the value is bound.
Then the Controller calls and returns the File to the browser for download and preview.
View is directly exported by clicking a label
NOPI is separated from the Excel version. The version cannot be imported without any effort
The first time I wrote a blog. Write is rough and simple. Click Submit at any time. I hope this article will help you get started with NOPI.
Thank you for your support. Just give me a compliment!