How do I read this file? RRS feed

  • Question

  • I was given a file with an XLS extension and wanted to read the contents into a Datagridview. But when I opened the file in a text editor it has html and xml:

    <html xmlns:o="urn:schemas-microsoft-com:office:office"

    <meta http-equiv=Content-Type content="text/html; charset=windows-1252">
    <meta name=ProgId content=Excel.Sheet>
    <meta name=Generator content="Microsoft Excel 11">
    <link rel=File-List href="Merc_files/filelist.xml">
    <link rel=Edit-Time-Data href="Merc_files/editdata.mso">
    <link rel=OLE-Object-Data href="Merc_files/oledata.mso">

    How do I read this data and populate a Datagridview?


    Thursday, April 23, 2009 2:20 PM

All replies

  • Hi Nick

    The VSTO forum really only supports the VSTO technology, which runs in-process with an Office application with the purpose of extending the UI. File formats and conversions aren't a topic here...

    From the look of it, what you have is possibly an Excel 2003 file saved to the "round-trip" HTML file format. As far as I know, these Office HTML file formats are more or less undocumented as they were intended for internal use (display/edit the file in the Office app and/or in IE - an attempt at file sharing).

    You can try asking in the Excel programming newsgroup, or some Excel forum, whether anyone has a good enough grasp of the rules used for the HTML files for you to be able to extract the contents to, say, an array - that probably being the most used approach. (I wouldn't complicate the issue mentioning a Datagridview, as there isn't going to be any straightforward way to do it.) If you can get that information, you can probably then figure out how to transform to XML (rather than writing to an array), which should let you dump the data to the control.

    You'll find links to Excel venues in the VSTO forum's Please Read First message.
    Cindy Meister, VSTO/Word MVP
    Thursday, April 23, 2009 4:46 PM