In a 'demo.cshtml' page of my C# MVC project, I'm displaying a list of users. I would like to export this data to an Excel file. Could someone assist me with this?
Loading
In a 'demo.cshtml' page of my C# MVC project, I'm displaying a list of users. I would like to export this data to an Excel file. Could someone assist me with this?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh KumarPosted May 9, 2024, 4:24 PM
Hello Rinki,
Please refer to this article,
https://www.c-sharpcorner.com/article/export-data-in-excel-pdf-csv-word-json-xml-and-text-file-in-mvc-application/
https://www.c-sharpcorner.com/article/export-data-excel-in-asp-net-mvc/
https://www.c-sharpcorner.com/article/excel-export-in-mvc-net2/
Darshan AdakanePosted May 9, 2024, 2:34 PM
You can achieve this in two parts :
Part 1 :
Part 2:
Hope this works. Thanks.
Ishika TiwariPosted May 9, 2024, 1:41 PM
Hello Rinky,
Please go through this. I hope you will get your answer.
https://www.c-sharpcorner.com/article/how-to-export-html-table-in-excel-using-jquery/
Jaimin ShethiyaPosted May 9, 2024, 1:11 PM
Hello Rinki,
Please refer below link.
https://docs.closedxml.io/en/latest/
https://github.com/ClosedXML/ClosedXML
https://www.c-sharpcorner.com/article/excel-sheet-closed-xml-mvc5/
Thanks
Jayraj ChhayaPosted May 9, 2024, 12:07 PM
Hi Rinki,
To export data to an Excel file in a C# MVC project, you can use the EPPlus library, which simplifies Excel generation. First, install the EPPlus NuGet package in your project. Then, you can create an Excel package, add a worksheet, and populate it with your data.
ExportToExcelmethod takes a list of users and generates an Excel file named "Users.xlsx" with the user data. You can call this method from your controller to export the data.Amit MohantyPosted May 9, 2024, 12:01 PM
You can use the EPPlus library to easily export data to an Excel file. In your controller, create a method to generate the Excel file. This method will take the list of users as input and create an Excel file containing the user data.
Now add a button or link to trigger the export action. For example: