在生成的HTML .doc中插入分页符

bak*_*ked 7 html asp.net ms-word

我目前正在使用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();
Run Code Online (Sandbox Code Playgroud)

Cod*_*ePB 16

Word有自己的特殊类.MSO的特殊字符:分页; 如Pekka所述,在这种情况下确实有效,但缺少的是这应该在<br>标签上.所以下面的代码将起作用:

<br clear=all style='mso-special-character:line-break;page-break-before:always'>
Run Code Online (Sandbox Code Playgroud)

这不是特别好的解决方案,但在我的情况下我别无选择(我没有编写原始代码,更改它是一个更大的工作).


Ric*_*ard 1

我会使用 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