views:

134

answers:

2

I'm looking to generate some C# code based on Excel data. Basically the Excel sheet contains definitions of functions that need to be generated in C#.

My current experience with code generation is mainly with ORM's. But now the "input" is Excel data.

I'm asking this to prevent me from re-inventing the wheel. Reading data from Excel is easy, and generating C# also. But I'm a lazy programmer.

Is there a code generation tool that accepts Excel files as input?

+1  A: 

You can use T4 templates. I know this too common/abstract answer, but this is the way, I think, and I don't think you can find something already exist for that purpose. Visual Studio 2008 has native supports for them. In your T4 template you can read excel file and then use its data to create any code file you want.

Kamarey
+2  A: 

I am guessing you will have to hand roll this solution. This does seem a little wonky, would be curious how you got in a situation where you are needing to do code gen based on Excel?!?

TheHurt
Sometimes it can be useful. As an example, we have an Excel macro that generates domain object classes, data access helpers, data mapping definitions, and test cases for iBATIS.NET for a database schema pasted into to Excel. Saves hand-coding thousands of lines of code. Of course Excel is only one option, but it's handy nonetheless.
Cory Larson
Cory's examples is a good one... And in general Excel is the language of the "business"! They are fluent in Excel, and using information stored in an Excel sheets can be very helpful.
Saab