如何在asp.net c#中将gridview导出到MS-word [英] How do I export gridview to MS-word in asp.net c#

查看:104
本文介绍了如何在asp.net c#中将gridview导出到MS-word的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下链接 http://www.c-sharpcorner.com/UploadFile/ 0c1bb2 / export-gridview-to-word / [ ^ ],这是我的代码是导出gridview到word。



Following link http://www.c-sharpcorner.com/UploadFile/0c1bb2/export-gridview-to-word/[^] , this is my code is export gridview to word.

gridLedgerReport.AllowPaging = false;
            gridLedgerReport.DataSourceID = string.Empty;            
            gridLedgerReport.DataSource = ViewState["grid"];            
            gridLedgerReport.DataBind();
                       
            Response.Clear();
            Response.Buffer = true;
            Response.ClearContent();
            Response.ClearHeaders();
            Response.Charset = "";
            string fileName = "LedgerReportOn" + System.DateTime.Now.ToString("MM/dd/yyyy") + ".doc";
            StringWriter sw = new StringWriter();
            HtmlTextWriter hw = new HtmlTextWriter(sw);
            Response.Cache.SetCacheability(HttpCacheability.NoCache);
            Response.ContentType = "application/msword";  
            Response.AddHeader("Content-Disposition", "attachment;filename="+fileName );
            gridLedgerReport.GridLines = GridLines.Both;
            gridLedgerReport.RenderControl(hw);  
            Response.Write(sw.ToString());            
            Response.End();





但是,此代码对我不起作用。根据我的理解,将显示下载保存或打开选项。但是,此代码对我的应用程序没有任何影响。在调试时,所有代码都执行但没有响应。



有关如何将gridview导出到word的任何帮助。

提前谢谢...



However, this code is not working for me. As per my understanding, a download Save or Open option was to be shown. However, this code shows no effect on my application. On debugging, the all codes executes but no response.

Any help on how can I export my gridview to word.
Thanks in advance...

推荐答案

您可以使用Microsoft Open XML SDK在服务器端生成Word文档。请查看我过去的答案:

如何从Add添加microsoft excel 15.0对象库MS Visual Studio 2010中的参考 [ ^ ],

Microsot office Interop [ ^ ]。



另请参阅Microsoft文章警告不要在服务器设置中使用Office互操作:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2 [ ^ ],

http://support.microsoft.com/kb/257757/en-us [ ^ ]。



-SA
You can use Microsoft Open XML SDK to produce Word document on the server side. Please see my past answers:
How to add microsoft excel 15.0 object library from Add Reference in MS Visual Studio 2010[^],
Microsot office Interop[^].

See also Microsoft articles warning against the use of Office interop in server settings:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;q257757#kb2[^],
http://support.microsoft.com/kb/257757/en-us[^].

—SA


我从页面中删除了更新面板,其中in是要导出的代码。现在它的工作......
I removed update panel from the page where in was the code to export. Now its working...


这篇关于如何在asp.net c#中将gridview导出到MS-word的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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