in

MCW Technologies' Community Server

Downloads, blogs, forums, and more

Adventures in Visual Studio Development

Making Visual Studio easier to use, one blog entry at a time

The coolest thing I have seen in a long long time

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.

Published Sep 15 2005, 06:26 PM by RGreen
Filed under:

Comments

No Comments

Leave a Comment

(required)  
(optional)
(required)  
Add
© Copyright MCW Technologies, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems