datagridview到worddocument [英] datagridview to worddocument

查看:78
本文介绍了datagridview到worddocument的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我解决这篇文章吗?
将datagrid视图导出到C#中的Word中."可以通过在C#中提供代码或相关链接来帮助我吗?

can anybody help me to solve this article
" Export datagrid view to Word in C# " .can you help me by giving the code or related links in C#

推荐答案

尝试一下,
Response.Clear();
Response.AddHeader("content-disposition", "attachment;filename=filename.doc");
Response.Charset = "";
Response.ContentType = "application/msword";

StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

grid.RenderControl(htmlWrite);
Response.Write(stringWrite.ToString());
Response.End();


如果您现在运行此代码,将会收到错误-类型为"GridView"的控件" ctl00_ContentPlaceHolder1_grid必须置于带有runat = server的表单标记内".所以,别担心.只需复制并粘贴以下代码.完成了.


If u run this code now, you will get error - ''Control ''ctl00_ContentPlaceHolder1_grid'' of type ''GridView'' must be placed ''inside a form tag with runat=server''. so, Don''t worry. Just copy and paste the below code. Its done.

public override void VerifyRenderingInServerForm(Control control)
{
    // Confirms that an HtmlForm control is rendered for the specified ASP.NET
    // server control at run time. <br>
}</br>


这篇关于datagridview到worddocument的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆