Click here to Skip to main content
15,901,035 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to export data from listview to excel, I am using below code, it exports data to excel but along with html design, how could I export listview data without exporting HTML content...

C#
Response.ClearContent();
            Response.AddHeader("content-disposition", "attachment;filename=Result.xls");
            Response.ContentType = "applicatio/excel";
            StringWriter sw = new StringWriter(); ;
            HtmlTextWriter htm = new HtmlTextWriter(sw);
            ListView2.RenderControl(htm);
            Response.Write(sw.ToString());
            Response.End();


Data in excel sheet is represented as below...

HTML
<tr>
     <td>&nbsp;118711&nbsp;</td>
     <td>&nbsp;101&nbsp;</td>
     <td>&nbsp;TLALA,,KHALI&nbsp;</td>
     <td>&nbsp;43.00&nbsp;</td>
     <td>&nbsp;43&nbsp;</td>
     <td>&nbsp;43&nbsp;</td>
     <td>&nbsp;43&nbsp;</td>
     <td>&nbsp;43&nbsp;</td>
     <td>&nbsp;C&nbsp;</td>
     <td>&nbsp;1&nbsp;</td>
 </tr>

 <tr>
     <td>&nbsp;118714&nbsp;</td>
     <td>&nbsp;102&nbsp;</td>
     <td>&nbsp;LARA,,BROWN&nbsp;</td>
     <td>&nbsp;45.00&nbsp;</td>
     <td>&nbsp;45&nbsp;</td>
     <td>&nbsp;45&nbsp;</td>
     <td>&nbsp;45&nbsp;</td>
     <td>&nbsp;45&nbsp;</td>
     <td>&nbsp;C&nbsp;</td>
     <td>&nbsp;1&nbsp;</td>
 </tr>



 <tr>
     <td>&nbsp;118717&nbsp;</td>
     <td>&nbsp;103&nbsp;</td>
     <td>&nbsp;MARTIN,,FRASER&nbsp;</td>
     <td>&nbsp;23.00&nbsp;</td>
     <td>&nbsp;23&nbsp;</td>
     <td>&nbsp;23&nbsp;</td>
     <td>&nbsp;23&nbsp;</td>
     <td>&nbsp;23&nbsp;</td>
     <td>&nbsp;D&nbsp;</td>
     <td>&nbsp;0&nbsp;</td>
 </tr>

 <tr>
     <td>&nbsp;118720&nbsp;</td>
     <td>&nbsp;104&nbsp;</td>
     <td>&nbsp;WILLIAM,,BLACK&nbsp;</td>
     <td>&nbsp;56.00&nbsp;</td>
     <td>&nbsp;56&nbsp;</td>
     <td>&nbsp;56&nbsp;</td>
     <td>&nbsp;56&nbsp;</td>
     <td>&nbsp;56&nbsp;</td>
     <td>&nbsp;B&nbsp;</td>
     <td>&nbsp;2&nbsp;</td>
 </tr>
Posted
Updated 18-Nov-13 5:00am
v4
Comments
ZurdoDev 18-Nov-13 10:13am    
Don't render the control but instead get the values and create a csv file. Just one option.

1 solution

How would I store only values of listview to excel file.
 
Share this answer
 

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