Creating Excel with C# and dealing with various Excel versions - COM interop methogd

I need to create a C# windows application that will read and write and also creates Excel work books.

I like the COM interop method for its simplicity.

I am planning to create simple Excel sheets , but need some minor formatting to columns.
I am happy to create my files with xls extension as opposed to xlsx, so it can be opened in Excel 2007 etc.

But when I use COM interop , do I need to have the same version of MS Office  as the end user ? such as office 2010 ?

Can I not use office 2010 on my development PC and then deploy the necessary dlls along with my application so that the app will work on any office version.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jacques Bourgeois (James Burger)PresidentCommented:
No. That would mean distributing Excel 2010 itself... and Microsoft would stop making money.

The solution, although not interesting at all, is to let go early binding (using specific objects such as Microsoft.Office.Interop.Excel.Workbook), and work in late binding, which means using Object variables. This is discussed by Microsoft at And lucky you, the sample code is with Excel.

This is very bad for a programmer however, because you lose a lot of features, such as IntelliSense and compile time checking.

What I do when I need to work like that, is usually to code and test with Early Binding, so that I have all my usual tools to work with. I then go back and replace the type by Object in all my Excel variables declarations, as well as replace the New for those variable by CreateObject. A pain in a big application, but it is usually worth it in debugging time during development.

One trick, when possible, is to delegate as much work as possible to macros in the Workbook, using templates to create new workbooks if necessary. This not only simplifies your work, but is also usually faster. Your .NET code simply calls the Run method of the Application object, passing parameters as needed, and let the macro do the job.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
indikadAuthor Commented:
Thanks - I will try this.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.