在ASP.net中将aspx页面导出为单词c# [英] Export aspx page to word in ASP.net c#

查看:67
本文介绍了在ASP.net中将aspx页面导出为单词c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我试图使用下面的代码将mt aspx页面导出为word格式,



pageObject.Response.Clear();

pageObject.Response.AddHeader(content-disposition,attachment; filename = FileName.doc);

pageObject.Response.Charset =;

pageObject.Response.Cache.SetCacheability(HttpCacheability.NoCache);

pageObject.Response.ContentType =application / doc;

StringWriter stringWrite = new StringWriter();

HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);

myDiv.RenderControl(htmlWrite);

pageObject.Response.Write(stringWrite.ToString());

pageObject.Response.End();







代码生成了输出,但无论CSS应用于页面还是应用于word文档(输出d) oc)。



请帮助我。



谢谢。

解决方案

请通过以下链接查看您的问题...



http://social.msdn.microsoft.com/Forums/vstudio / en-US / 7621cb04-f8e7-48aa-b8b2-1580579e6fcd / export-aspx-page-to-word?forum = csharpgeneral [ ^ ]



http://www.nullskull.com/q/51714/export-from-web-page-to-word-include-images.aspx [ ^ ]


 StringBuilder strHTMLContent =  new  StringBuilder(); 
// 附加样式表
strHTMLContent.Append( < style> .tableHeader {background-color:#CCCCCC; font-weight:bold;} .style1 {width:100%; border-collapse:collapse;}。firstHeader {background-color:#3366CC; font-weight:bold; color:#FFFFFF;}< / style> .ToString());

// strHTMLContent.Append(< style> .firstHeader {background-color: #3366CC; font-weight:bold; color:#FFFFFF;}< / style>。ToString());

pageObject.Response.Clear();
pageObject.Response.AddHeader( content-disposition attachment; filename = FileName.doc);
pageObject.Response.Charset = ;
pageObject.Response.Cache.SetCacheability(HttpCacheability.NoCache);
pageObject.Response.ContentType = application / doc;
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myDiv.RenderControl(htmlWrite);

pageObject.Response.Write(strHTMLContent.Append(stringWrite).ToString()); // 发送stringWrite
pageObject.Response.End();


Hi,

I was trying to export mt aspx page to word format using the below code,

pageObject.Response.Clear();
pageObject.Response.AddHeader("content-disposition", "attachment; filename=FileName.doc");
pageObject.Response.Charset = "";
pageObject.Response.Cache.SetCacheability(HttpCacheability.NoCache);
pageObject.Response.ContentType = "application/doc";
StringWriter stringWrite = new StringWriter();
HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
myDiv.RenderControl(htmlWrite);
pageObject.Response.Write(stringWrite.ToString());
pageObject.Response.End();



Code was produced the output but whatever CSS has been applied to the page which are not applied to the word document(output doc).

Kindly help me.

Thanks .

解决方案

pls go through below link for your problem...

http://social.msdn.microsoft.com/Forums/vstudio/en-US/7621cb04-f8e7-48aa-b8b2-1580579e6fcd/export-aspx-page-to-word?forum=csharpgeneral[^]

http://www.nullskull.com/q/51714/export-from-web-page-to-word-include-images.aspx[^]


StringBuilder strHTMLContent = new StringBuilder();
            //appending the style sheet 
            strHTMLContent.Append("<style>.tableHeader{background-color:#CCCCCC;font-weight:bold; }.style1 { width: 100%;border-collapse:collapse;}.firstHeader { background-color: #3366CC; font-weight: bold;color: #FFFFFF;}</style>".ToString());
            
             //strHTMLContent.Append("<style>.firstHeader { background-color: #3366CC; font-weight: bold;color: #FFFFFF;}</style>".ToString());
        
            pageObject.Response.Clear();
            pageObject.Response.AddHeader("content-disposition", "attachment; filename=FileName.doc");
            pageObject.Response.Charset = "";
            pageObject.Response.Cache.SetCacheability(HttpCacheability.NoCache);
            pageObject.Response.ContentType = "application/doc";
            StringWriter stringWrite = new StringWriter();
            HtmlTextWriter htmlWrite = new HtmlTextWriter(stringWrite);
            myDiv.RenderControl(htmlWrite);

            pageObject.Response.Write(strHTMLContent.Append(stringWrite).ToString());   // send the stringWrite          
            pageObject.Response.End();


这篇关于在ASP.net中将aspx页面导出为单词c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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