Rename the excel sheet name with Actual file name of Excel

Hi,

I want to merge 4 excel files into 1 file .All files having different name so I want that After it merged into 1 file all files have there own sheet in file with there orignal names of it.So we can determine every sheet with there orignal names.

Thanks

If all 4 files are in 1 folder

Get all the file paths in array using Directory.GetFiles(strPath), loop through it

Then read the content of the first Excel using Read Range and Store it in a datatable variable.

Then use write range to paste the datatable in the new Excel (output Excel) and in sheet name simply pass the file name without extension

Path.GetFileNameWithoutExtension(item)

item is the loop variable of for loop that will have the current file path in Loop

@rahulsharma Thanks for reply , Please can you share a demo of it.

@mnk

Find attached code for your reference

Combining Excel Files.zip (2.8 KB)
Input_OutputFiles.zip (31.2 KB)

Hope this will help you

Mark as solution, so that it will help for other also

Thanks

@mnk

Can you try as below then

path.GetFileNameWithoutExtension(File).ToString

Hope this works for you

Thanks

Try
System.IO.Path.GetFileNameWithoutExtension(File).ToString
Instead of
Path.GetFileNameWithoutExtension(File).ToString

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.