Friday, February 22, 2008

LINQ to Excel Code Generator

I have noticed that there has been some interest in my LINQ to Excel Provider. I thought it might be beneficial and fun to try and build an online code generator to create one’s LINQ to Excel class. This code generator is a pure JavaScript application and it should be pretty straightforward to use.

The purpose of this generator is to build a .Net class than can be used to interact with my LINQ to Excel Provider 2.5 and perform CRUD operations on an Excel sheet.

To run the generator:

1. Determine with language you want to use (C# or VB).
2. Supply the name of your .Net class
3. Set the name of the Excel sheet you want to map your .Net class to.
4. Supply the column names and data types from the Excel sheet that you want to incorporate into your .Net class.
5. Click the Generate Code button.
6. Copy the contents of the bottom textbox into a class file in Visual Studio.
7. Refer to LINQ to Excel Provider 2.5 for an example on how to interact with your class and read data from Excel.

Enjoy and if you have any comments or suggestions let me know.

Check the generator out here

5 comments:

Marc Chouteau said...

Very interesting ! Very good job !

K Jacobson said...

I have updated the generator to now support VB.Net along with C#

Deepesh said...

Hey i am bit lost in what you have presented, Seems like a good solution but how do i use it?

Perhaps some step by step for a novice like me should help a lot

Examples which have truly helped have some like these....
Step 1 create a class file
Step 2 create a webpage
Step 3 add a button and double click and paste the code there...

Thanks for all your help!

Deepesh

K Jacobson said...

I have added some step by step directions here to hopefully clarify how to use the generator.

Remember this just creates a mapping between your Excel sheet and a .Net Class so it can be understood by the LINQ to Excel Provider 2.5. The provider performs the work of reading and saving data between the Excel sheet and the .Net class you created with the generator.

Carsten Berggreen (Denmark) said...

Great job, very interesting possiblities, but I have big difficulties getting it to run.

It states that there is null values in the first of my columns. I have doublechecked and no there isnt. My question is how does the reader loop know which line is the last? and could this be the problem some how?