In this article we will discuss how to import and export excel file using ASP .NET Core 3.1 razor pages. We will discuss the below points
What is NPOI package ?
NPOI is a free tool which supports xls, xlsx and docx extensions. This project is the .NET version of POI Java project at http://poi.apache.org/. POI is an open source project, which can help you read/write XLS, DOC, PPT files. It covers most features of Excel like styling, formatting, data formulas, extract images, etc.. The good thing is, it doesn’t require Microsoft Office to be installed on the server. NPOI is an open source component and you can use it everywhere. This post shows you the basic functionalities of NPOI, but you can do much more with NPOI like styling the individual cell or rows, creating excel formulas and other stuff. The NPOI package supports both “xls” and “xlsx” extensions using HSSFWorkbook and XSSFWorkbook classes. The HSSFWorkbook class is for “xls”, where the other one is for “xlsx”. To know more about NPOI, Refer the official documentation.
>> How to import Excel file in .NET Core and preview the uploaded excel file?
>> How to export the excel file ?
What is NPOI package ?
NPOI is a free tool which supports xls, xlsx and docx extensions. This project is the .NET version of POI Java project at http://poi.apache.org/. POI is an open source project, which can help you read/write XLS, DOC, PPT files. It covers most features of Excel like styling, formatting, data formulas, extract images, etc.. The good thing is, it doesn’t require Microsoft Office to be installed on the server. NPOI is an open source component and you can use it everywhere. This post shows you the basic functionalities of NPOI, but you can do much more with NPOI like styling the individual cell or rows, creating excel formulas and other stuff. The NPOI package supports both “xls” and “xlsx” extensions using HSSFWorkbook and XSSFWorkbook classes. The HSSFWorkbook class is for “xls”, where the other one is for “xlsx”. To know more about NPOI, Refer the official documentation.
Import and Export excel in ASP.NET Core 3.1 razor pages
Let's create a .NET Core web application targeting to .NET Core 3.1 . Open VS 2019 ➠ Select ASP .NET Core web application
Install NPOI package using Nuget. |
The HTML code has file upload control and a button to upload the file. The below jQuery code uploads the excel file using Ajax. The code also performs the client side validation for file selection and extension checking. Once the request is successful, it appends the server response to the HTML. Read this post for handling Ajax request with ASP.NET Core 3.1 razor pages and this post for uploading files in ASP.NET Core 3.1 Razor Pages.
Let's run the application and see the output.
You can see after upload the file it save it into the specified path |
</> Find the Source Code in Github.com/CoreProgramm/
Summary
Post a Comment