For anyone coming here looking for how to do this in C#, I have tried the following method and had success in First create your model class.
Then install EPPlus Nuget package. (I used version 4.0.5, probably will work for other versions as well.)
The create
Now add this method where you want to generate the excel file, probably for a method in the controller. You can pass parameters for your stored procedure as well. Note that the return type of the method is
More details can be found here Can you run a SQL query in Excel?Open an SQL connection to an Excel file
Before running an SQL query, you have to open a connection with the Excel file you want to access. To establish the connection, create a new variable named %Excel_File_Path% and initialize it with the Excel file path.
How do I embed a SQL query in Excel?How to Create an Excel Connection. Click on Get Data. Select “From Database”. Select From SQL Server database.. Enter the SQL Server Name. Optionally, you can enter the database name here if you know it. Otherwise, you will be able to select the database in a future step.. |