export Html Table to Excel sheet asp.net

Hi Expert,

I have a label show a report using Html table.

str = "<table>"
        str = str + "<tr>"
        str = str + "<td>ParcelId"
        str = str + "</td>"
        str = str + "</tr>"
        str = str + "<tr>"
        str = str + "<td>43011070008000."
        str = str + "</td>"
        str = str + "</tr>"
        str = str + "</table>"

        lbReport.Text = str

How user click on Export Button, html table can export to excel sheet.


Thanks in advance.
LVL 1
dshi15Asked:
Who is Participating?
 
Faheem ShaikhConnect With a Mentor Commented:
You can use the custom control ExportPanel for this purpose:
http://steveorr.net/articles/ExportPanel.aspx
 
Here is another methos to achieve this:
http://steveorr.net/articles/ExcelExport.aspx
 
0
 
CognizeCommented:
Hi,

The easiest way I've found is to write XML in a format that excel can read (as below ) and then just save the file with a .xls extension - this xml file will be readable by excel:

Excel does support an xml format - see this article:

http://www.codeproject.com/KB/office/excelxmlspreadsheet.aspx

<Workbook>
    <Styles>
    </Styles>
    <Worksheet ss:Name="Sheet1">
        <Table>
            <Row>
                <Cell>Data</Cell>
                <Cell>Data</Cell>
            </Row>
        </Table> 
        <WorksheetOptions> </WorksheetOptions>
    </Worksheet> 
    <Worksheet ss:Name="Sheet2">
        <Table>
            <Row>
                <Cell>Data</Cell>
                <Cell>Data</Cell>
            </Row>
        </Table> 
    </Worksheet> 
    ......
    ...... 
    ...... 
    ...... 
<Workbook>

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.