Click here to Skip to main content
15,881,624 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
This is my code. By using this code I can export all the table in excel. But I can not export css class. As a result the color and style is diplaying in webpage do not shown in excel. Can anyone help me by provide a right solution. How can I export the css

C#
Worksheet worksheet1 = (Microsoft.Office.Interop.Excel.Worksheet)workbook.Sheets[1];

var itemset2 = webBrowser1.Document.GetElementById("t2");

string str = "";

int rowCount = itemset2.GetElementsByTagName("tr").Count;
int colCount = itemset2.GetElementsByTagName("tr")[0].GetElementsByTagName("td").Count;

for (var i = 0; i < rowCount; i++)
{
    for (var j = 0; j < colCount; j++)
    {

        str = itemset2.GetElementsByTagName("tr")[i].GetElementsByTagName("td")[j].InnerText;

        worksheet1.Cells[i + 1, j + 1] = str;

    }


}


and this is my html page sample:
HTML
<div id="t2" class="tblcss"> 
<table width="100%" cellpadding="0" cellspacing="0">
  <tr id=r1>
    <td>Telephony By Country</td>
    <td>Jan-2013</td>
    <td>Feb-2013</td>
    <td>Mar-2013</td>
  </tr>
  <tr id=r2>
    <td class="tdhighlight">Calls Offered</td>
    <td>33555</td>
    <td>28201</td>
    <td>27563</td>
  </tr>
  <tr id=r3>
    <td class="tdhighlight">Calls Answered</td>
    <td>32042</td>
    <td>27030</td>
    <td>26273</td>
  </tr>
  <tr id=r4> 
</table> </div>
Posted
Comments
Maciej Los 8-Jul-14 17:12pm    
Do you want to save table formatting?
ASP.NET?
sachi Dash 9-Jul-14 3:22am    
I do not use any any asp.net page.... It is a html page. I mean extentension is .html and I use webbrowser desktop control.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900