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

标签 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();

最佳答案

Word 有自己的特殊类。 mso-特殊字符:分页符;正如 Pekka 所提到的,在这种情况下确实有效,但是缺少的是这应该在
标签上。所以下面的代码将起作用:

<br clear=all style='mso-special-character:line-break;page-break-before:always'>

这不是特别好的解决方案,但就我而言,我别无选择(我没有编写原始代码,更改它的工作量更大)。

关于html - 在生成的 HTML .doc 中插入分页符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4896863/

相关文章:

javascript - 调整浏览器中视频的播放速度

html - Bootstrap 导航栏在屏幕尺寸不可移动时显示 2 行

java - 将页码放入文档中

asp.net - RowCommand GridView 花了 6.7 秒

asp.net - 在 Web 应用程序中对长时间运行的任务进行排队

browser - 您可以在浏览器中对 Word 文档进行复杂的编辑吗?

delphi - 如何在 Delphi 的 OLE 自动化过程中使 Word 不可见

javascript - 使用 jQuery 定位和更改 HTML 内容

javascript - HTML Selectbox 值 ajax 调用用于页面

.net - 回发不适用于 aspx 页面作为默认文档