我目前正在使用asp.NET生成一个.doc文件作为html.
我尝试过使用css style =’page-break-before:always’但它什么也没做.
这是分配给按钮单击事件的代码:
HttpContext.Current.Response.Clear(); HttpContext.Current.Response.Charset =""; HttpContext.Current.Response.ContentType ="application/msword"; string strFileName = "GenerateDocument"+ ".doc"; HttpContext.Current.Response.AddHeader("Content-Disposition","inline;filename=" + strFileName); StringBuilder strHTMLContent = new StringBuilder(); strHTMLContent.Append("<p align='Center'>Content Before Page Break</p>".ToString()); strHTMLContent.Append("<br><br>".ToString()); strHTMLContent.Append("<p class='pageBreak' style='mso-special-character:line-break;'>meh</p>".ToString()); strHTMLContent.Append("<br><br>".ToString()); strHTMLContent.Append("<p align='Center'>Content After Page Break</p>".ToString()); HttpContext.Current.Response.Write(strHTMLContent); HttpContext.Current.Response.End(); HttpContext.Current.Response.Flush();
解决方法
我会改用Gios.Word .NET库.使用表和分页符等创建RTF兼容的word文件要简单得多.
我首先尝试创建基于XML的Doc文件,发现Gios更好:
这是一篇关于它的文章:
http://www.codeproject.com/KB/string/gioswordnetlibrary.aspx
http://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=11252