项目中实践.net导出Word的方法 - 古月容博客-php个人技术博客-技术交流分享

2018
IT资讯信息分享

项目中实践.net导出Word的方法

public void payword(){

                    string d_show = "";

                    daan_show+="<html xmlns:v=\"urn:schemas-microsoft-com:vml\" xmlns:o=\"urn:schemas-microsoft-com:office:office\" xmlns:w=\"urn:schemas-microsoft-com:office:word\" xmlns:m=\"http://schemas.microsoft.com/office/2004/12/omml\" xmlns=\"http://www.w3.org/TR/REC-html40\">";               
                    daan_show+="<head><!--[if gte mso 9]><xml><w:WordDocument><w:View>Print</w:View><w:TrackMoves>false</w:TrackMoves><w:TrackFormatting/>";                        
                    daan_show+="<w:ValidateAgainstSchemas/><w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid><w:IgnoreMixedContent>false</w:IgnoreMixedContent><w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText><w:DoNotPromoteQF/><w:LidThemeOther>EN-US</w:LidThemeOther><w:LidThemeAsian>ZH-CN</w:LidThemeAsian><w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript><w:Compatibility><w:BreakWrappedTables/><w:SnapToGridInCell/><w:WrapTextWithPunct/><w:UseAsianBreakRules/><w:DontGrowAutofit/><w:SplitPgBreakAndParaMark/><w:DontVertAlignCellWithSp/><w:DontBreakConstrainedForcedTables/><w:DontVertAlignInTxbx/><w:Word11KerningPairs/><w:CachedColBalance/><w:UseFELayout/>";
                    daan_show+="</w:Compatibility><w:BrowserLevel>MicrosoftInternetExplorer4</w:BrowserLevel><m:mathPr><m:mathFont m:val=\"Cambria Math\"/><m:brkBin m:val=\"before\"/><m:brkBinSub m:val=\"--\"/><m:smallFrac m:val=\"off\"/><m:dispDef/><m:lMargin m:val=\"0\"/> <m:rMargin m:val=\"0\"/><m:defJc m:val=\"centerGroup\"/><m:wrapIndent m:val=\"1440\"/><m:intLim m:val=\"subSup\"/><m:naryLim m:val=\"undOvr\"/></m:mathPr></w:WordDocument></xml><![endif]-->";
                    daan_show+="<style type=\"text/css\">" ;
                    daan_show+="body{background:#FFF;padding:0px;margin:20px;font-size:18px;font-family:@宋体;text-align:center;color:#000;} " ;
                    daan_show+="th{border:none;} " ;
                    daan_show+="table,tr,td{border:none;border-spacing:0; } " ;  
                    daan_show+="p img{max-width:90%;} " ;                     
                    daan_show+=".testpaper_type1_questions_list{border:none;text-align: left;}";
                    daan_show+="@page{mso-page-border-surround-header:no;mso-page-border-surround-footer:no;}";                  
                    daan_show+="div.Section1{page:Section1;}";                               
                    daan_show+="</style>";
                    daan_show+="</head>";
                    daan_show+="<body>";

                    daan_show+="<div>正文</div>";

                    string fileName = DateTime.Now.ToString("yyyyMMddhhmm") + ".doc";                              
                    HttpContext.Current.Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));
                    HttpContext.Current.Response.ContentType = "application/ms-word";
                    HttpContext.Current.Response.Charset = "UTF-8";
                    HttpContext.Current.Response.ContentEncoding = System.Text.Encoding.UTF8;
                    HttpContext.Current.Response.Write(daan_show);
                    HttpContext.Current.Response.End();

}


在此导出过程中你可能会遇到导出不显示图片的问题、原因可能是图片地址不对造成。于是在下一并给出解决方案:图片地址批量转换




×

感谢您的支持,我们会一直保持!

扫码支持
请土豪扫码随意打赏

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

打赏作者
版权所有,转载注意明处:古月容个人博客 » 项目中实践.net导出Word的方法
标签: word .net

发表评论

表情

网友评论(0)