Paul showed off some VB 9.0 features today. He showed a lot of Linq demos, both DLinq and XLinq. One of his XLinq demos was tremendously cool. First he showed that VB now natively understands XML literals. You can write code like this
Dim xmlFrag = _
<Customers>
<Customer>
<CompanyName>Big Corp</CompanyName>
<City>BiggeTowne</City>
</Customer>
</Customers>
Then Paul opened an Excel spreadsheet that had a table with sample data as a placeholder. He saved the Excel as XML and then copied and pasted the XML into VB. He then created the following dLinq code
Dim rows = _
Select
<row>
<cell><%= r.Page :></cell>
</row>
From r in results
Now for the coup de grace. He replaced the sample data in the Excel XML with the following:
<%= rows>
Then he wrote out a new spreadsheet
Dim doc = New XDocument(body) ' body contains the pasted XML from the spreadsheet
doc.Save("Report.xls")
When he opened Report.xls, he had his Excel spreadsheet populated with the data returned by the query.
This is so cool!!! Don't automate Excel and put the data in by hand. Don't programmatically have Excel import XML after mapping schemas and all that. Just put the data into the spreadsheet's XML from within VB and then save the XML as a new spreadsheet. I am blown away by this.