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: