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.
Unfortunately, activation email could not send to your email. Please try again.

How to add Multiple excel data into single data table

Thread ID:

Created:

Updated:

Platform:

Replies:

132633 Sep 13,2017 07:19 AM Sep 14,2017 07:21 AM Windows Forms 1
loading
Tags: GridControl
sateesh kumar
Asked On September 13, 2017 07:19 AM

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 07:21 AM

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); 
    dt.Merge(copytable); 
} 
 
 
Sample link: GridControl 
 
Regards, 
Mohanraj G 


CONFIRMATION

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.

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.

;