将listview数据绑定到excel [英] binding listview data to excel
本文介绍了将listview数据绑定到excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨朋友们,
我想从列表视图中导出数据。我尝试了以下代码片段:
Hi friends,
I want to export data from list view.I tried the following code snippet:
try
{
Response.Buffer = true;
Response.ContentType = "application/x-msexcel";
Response.AddHeader("Content-Disposition", "attachment; filename=asdf.xls");
Response.ContentEncoding = Encoding.UTF8;
Response.Charset = "";
StringWriter sw = new StringWriter();
HtmlTextWriter hw = new HtmlTextWriter(sw);
if (dropdown1.SelectedValue=="1")
{
listview.RenderControl(hw);
}
Response.Write(sw.ToString());
Response.End();
}
catch (Exception ex)
{
//catching exception
}
}
在此获取输出但数据导出为< HTML>标签格式。帮助我只导出列表视图中的数据。
In this am obtaining the output but the data are exported as <HTML> tag formats.Help me to export only the data from the list view.
<thead>
<tr>
</tr>
</thead>
<tr>
<td>data</td>
<td>data</td>
<td style="text-align:center;">data</td>
<td style="text-align:right;">data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td style="text-align:center;">data</td>
<td style="text-align:right;">data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td style="text-align:center;">data</td>
<td style="text-align:right;">data</td>
</tr>
<tr>
<td>data</td>
<td>data</td>
<td style="text-align:center;">data</td>
<td style="text-align:right;">data</td>
</tr>
请提供仅获取数据的解决方案。
Please provide a solution to obtain only the data.
推荐答案
这是一个经常被问到的问题。请下次使用 SearchBox [ ^ ]在本网站的右上角。
查看类似的问题:使用c#将listview数据写入excel [ ^ ]
This is quite often asked question. Please, next time use SearchBox[^] on the right-top corner of this site.
Have a look at similar question: listview data write to excel using c#[^]
这篇关于将listview数据绑定到excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文