将Gridview数据导出到MS Word 2007和MS Excel 2007
问题描述:
嗨......
如何将gridview数据导出到msword和msexcel ...我已经做到了,但是它不支持XML数据....因为我拥有MSword 2007和MS excel 2007
这是我的编码:-
hi....
how to export the gridview data to msword and msexcel ...i have done it but its not supporting XML data....since i am having MSword 2007 and MS excel 2007
and this is my coding:-
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
binddate();
}
}
private void binddate()
{
try
{
string connection = ConfigurationManager.AppSettings["ConnectInfo"];
SqlConnection con = new SqlConnection(connection);
SqlDataAdapter da = new SqlDataAdapter("select * from quanta", con);
DataTable dt = new DataTable();
da.Fill(dt);
gv_details.DataSource = dt;
gv_details.DataBind();
}
catch (Exception ex)
{
Response.Write(ex.Message);
}
}
public override void VerifyRenderingInServerForm(Control control)
{
/* verifies the control is rendered*/
}
protected void btn_word_Click(object sender, ImageClickEventArgs e)
{
gv_details.AllowPaging = false;
gv_details.DataBind();
Response.ClearContent();
Response.AddHeader("content-disposition", string.Format("attachment;filename={0}", "Doc1.docx"));
Response.Charset="";
Response.ContentType="application/ms-word 2007";
StringWriter sw = new StringWriter();
HtmlTextWriter htw=new HtmlTextWriter(sw);
gv_details.RenderControl(htw);
Response.Write(sw.ToString());
Response.End();
}
}
请帮助我....在此先感谢...
please help me....thanks in advance...
答
尝试以下链接:-
http://forums.asp.net/t/1412788.aspx [
try this link:-
http://forums.asp.net/t/1412788.aspx[^]
Please don''t forget to mark this as your answer if it helps you out.
Thanks