Saturday, August 15, 2009

LINQ’ing to Word and Excel – Deborah shares the magic of Cast (in C# & VB)

Deborah's Developer MindScape - Using Linq with Microsoft Word and Excel

“Some of the collections in the Microsoft Office object models implement IEnumerable. The IEnumerable interface provides the ability to perform a for/each against the collection. With .NET 3.5, a Cast extension method of IEnumerable allows you to work with these collections using Linq.

Microsoft Word

For example, say you want to bind the set of open Word document names in a ComboBox.

image

I like the idea of using LINQ with Word/Excel (and by example other Office applications). I my day life I sometimes feel I live in a Office app collection loop, so using LINQ to streamline that is very appealing.

This is one of those things where I could see myself banging my head against the keyboard, trying to figure it out and just get it to work. I don’t know if I’d have figured out the magic of Cast and instead given up and gone back to a collection loop approach…

No comments:

Post a Comment

NOTE: Anonymous Commenting has been turned off for a while... The comment spammers are just killing me...

ALL comments are moderated. I will review every comment before it will appear on the blog.

Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...

I reserve, and will use, the right to not approve ANY comment for ANY reason. I will not usually, but if it's off topic, spam (or even close to spam-like), inflammatory, mean, etc, etc, well... then...

Please see my comment policy for more information if you are interested.

Thanks,
Greg

PS. I am proactively moderating comments. Your comment WILL NOT APPEAR UNTIL I approve it. This may take some hours...