How to export report data using Xlsio in excel?

Hi team


There is a functionality want to implement using this control, e.g export to excel similar to button from the forum or create a thread. I have local records from the database and need some help to use in mvc asp.net. I want to able to extract records from my local sql server database especially if i am using controller(method that call connection to the database than native or manually data from the controller) Please share some examples, thanks.


1 Reply

KK Konduru Keerthi Konduru Ravichandra Raju Syncfusion Team September 23, 2021 12:11 PM UTC

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. 


Loader.
Up arrow icon