views:

25

answers:

1

Hello,

(finally) I was able to read a Excel file located in the App_Data folder and display it on a view. Now I'd like to push the logical further. Instead of writing the following header tags on my page by hand,

<tr>
    <th>ID</th>
    <th>First Name</th>
    <th>Last Name</th>
</tr>

I'd like to be able to read the first row on my Excel Sheet and, through a foreach loop, recreate the header on the page. Or, if there's a different way of getting the header differently, I'm open.

How do I do that?

EDIT

Here's the connection string

<add name="xls"
     connectionString="Provider=Microsoft.ACE.OLEDB.12.0;
                       Data Source=|DataDirectory|Book1.xlsx;
                       Extended Properties='Excel 12.0 Xml;HDR=YES';" 
/>

Thanks for helping

+1  A: 

We do this using the Open XML SDK http://www.microsoft.com/downloads/en/details.aspx?FamilyId=C6E744E5-36E9-45F5-8D8C-331DF206E0D0&amp;displaylang=en

It allows you to read an excel sheet as an xml document.

Shiraz Bhaiji
Thanks for the link. I'll explore that. However, I don't know yet how to use xml. So, for a quick tip, is there anyway to show me how to read the first row? Check the edit above for more info on the issue I'm experiencing.
Richard77
@Shiraz Bhaiji: I've just install 'Open XML SDK'. Can u point me to some documentation on how it works?
Richard77