We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. (Last updated on: November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

How to add Multiple excel data into single data table

Thread ID:





132633 Sep 13,2017 11:19 AM UTC Sep 14,2017 11:21 AM UTC WinForms 1
Tags: GridControl
sateesh kumar
Asked On September 13, 2017 11:19 AM UTC

hi, am able to add the excel data to data table vise versa.
now am trying to load multiple excel data into single data table.
this data table want bind data grid.

am trying like this,but not working. 

string[] filesToProcess = Directory.GetFiles(sourcePath);
            foreach(string file in filesToProcess)
                if (!Path.GetExtension(file).ToString().ToLower().Equals(".xls"))
                    Console.WriteLine("Invalid File"+Path.GetFileName(file));
                if (Path.GetFileNameWithoutExtension(file).ToString().ToLower().StartsWith("bills under lc", StringComparison.InvariantCultureIgnoreCase)) ;
                wBook = app.Workbooks.Open(file);
                sheet = wBook.Worksheets[0];
                dt = sheet.ExportDataTable(sheet.UsedRange, ExcelExportDataTableOptions.ColumnNames);
am able to load the excel data, its not concate to previous data.

help me out this.

Thanks for the advance,
J.Sateesh Kumar

Mohanraj Gunasekaran [Syncfusion]
Replied On September 14, 2017 11:21 AM UTC

Hi Sateesh, 
Thanks for using Syncfusion product. 
By default, IWorkSheet.ExportDataTable method can used to generate the DataTable based on the provided range. So, if you want to merge multiple excel files data in a DataTable, you can use the existing DataTable.Merge method. Please refer to the below code example and the sample, 
Code example 
DataTable copytable; 
DataTable dt; 
foreach(string file in filesToProcess) 
    if (!Path.GetExtension(file).ToString().ToLower().Equals(".xlsx")) 
        Console.WriteLine("Invalid File"+Path.GetFileName(file)); 
    if (Path.GetFileNameWithoutExtension(file).ToString().ToLower().StartsWith("data", StringComparison.InvariantCultureIgnoreCase)) ; 
    workbook = application.Workbooks.Open(file); 
    worksheet = workbook.Worksheets[0]; 
    copytable = worksheet.ExportDataTable(worksheet.UsedRange, ExcelExportDataTableOptions.ColumnNames); 
Sample link: GridControl 
Mohanraj G 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

or the page will be automatically redirected to sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon