用一些表格数据导出到excel [英] Export to excel with some form data
本文介绍了用一些表格数据导出到excel的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
亲爱的朋友,
我需要将表单数据导出到标签中,还需要将网格数据导出到excel中.在asp.net中将网格数据导出到excel很容易,但是如果我也要导出表单数据,则无法找到这样的代码.
请帮忙.
谢谢
Varun Sareen
Dear Friends,
I need to export the form data in labels and also the grid data to excel. It''s easy to export the grid data to excel in asp.net but if I want to export the form data as well, I am not able to find such code.
Please help.
Thanks
Varun Sareen
推荐答案
表格数据是什么意思?数据表对象中可能有什么数据.然后将数据表对象转换为excel.
使用此代码:
What do you mean by form data? What ever the data may be have it in datatable object. Then convert the datatable object to excel.
Use this code:
DataTable dataTable = new DataTable();
string attachment = "attachment; filename=Employee.xls";
Response.ClearContent();
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "application/ms-excel";
StringWriter stw = new StringWriter();
HtmlTextWriter htextw = new HtmlTextWriter(stw);
GridView gvEmployee = new GridView();
gvEmployee.DataSource = dataTable;
gvEmployee.DataBind();
gvEmployee.RenderControl(htextw);
Response.Write(stw.ToString());
Response.End();
这篇关于用一些表格数据导出到excel的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文