tags:

views:

10453

answers:

6

I have a few hundred Excel files, where each file has some data on the first sheet. I've been asked to write a console application in C# which merges all of the Excel files together into a single document while retaining the formatting.

The consolidated file is a single workbook containing a sheet for each file merged into the document. Unfortunately, the Excel files are in binary rather than XML format, so I can't perform an XSL transformation.

Is there are free library or sample code which demonstrates how to combine a sheets from multiple Excel documents into a single file?

A: 

You'll need to use the Microsoft Excel Interop library. http://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.aspx

You should be able to add a reference, in the com tab, to Microsoft Excel 11 Object Library.

http://msdn.microsoft.com/en-us/library/ms173186(VS.80).aspx

Joshua Belden
Hopefully all of your excel files are the same version.
Joshua Belden
Thank you, this is exactly what I was looking for :)
Juliet
A: 

It's not free (a developer license is $ 425) but GemBox has a very good library that is way faster than using the office objects. We use it in my current project since a year and a half, and it has consistently performed very well for us.

Fredrik Mörk
A: 

Look into Visual Studio Tools for Office (VSTO).
You can open workbooks in code and use a lot of the excel functionality, as well as copying worksheets like you've said you need to do.

For resources, this MSDN forum post demonstrates opening excel files and copying worksheets. Hopefully this will get you on the right direction.

Drew McGhie
+1  A: 

Of course you can do Tool->Compare->Merge Workbooks. And within Excel as Joshua mentioned there is the merge method in the COM Interop libraries. If you need some help let me know I work heavily in Excel and may be able to help you out on a small fee basis.

Roger
+1  A: 

This is an easy task for a neat little program called Bulk File Merger (they have a Mac version called Excel File Merger). I managed to merge over 300 files in a matter of minutes. You can also merge csv files, which takes even less time. We banged out over 1300 csv files in seconds. Scary.

Vem234
+1  A: 

I come across this problem when one of my client came to me looking for solution to merge their stock lists that are saved in more than 200 separate files. If you found yourself to be in the same position like my client; don’t worry, I wrote a simple program that do the work. :) Check the link below:

JMC Excel - Join, Merge, Combine multiple Excel sheets or Excel workbooks

Regards, JeeShen Lee www.jeeshenlee.wordpress.com

JeeShen Lee