mnk
(mnk)
December 1, 2021, 4:16am
1
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
mnk
(mnk)
December 1, 2021, 5:00am
3
@rahulsharma Thanks for reply , Please can you share a demo of it.
Srini84
(Srinivas Kadamati)
December 1, 2021, 7:21am
4
@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
Srini84
(Srinivas Kadamati)
December 1, 2021, 8:30am
6
@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
system
(system)
Closed
December 4, 2021, 9:19am
9
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.