Hi Gcobani,
Greetings from Syncfusion.
Syncfusion XlsIO supports importing data from DataTable to Excel. We suggest you to import data from DataBase to DataTable and then import the DataTable to Excel. Please find the code snippet below.
Code Snippet:
using (ExcelEngine excelEngine = new ExcelEngine())
{
IApplication application = excelEngine.Excel;
application.DefaultVersion = ExcelVersion.Excel2013;
IWorkbook workbook = application.Workbooks.Create(1);
IWorksheet worksheet = workbook.Worksheets[0];
DataTable table = new DataTable();
//Import DataBase to DataTable
//Import DataTable to the worksheet.
worksheet.ImportDataTable(table, true, 1, 1);
workbook.SaveAs("Output.xlsx", HttpContext.ApplicationInstance.Response, ExcelDownloadType.Open);
} |
Please go through the below link for creation of MVC application with button click.
Kindly try the suggestion and let us know if this helps.
Regards,
Keerthi.