insertstyleseparator()在章节开始[aspose Word]的开始中添加带有文本的空白

发布于 2025-02-04 04:00:31 字数 105 浏览 2 评论 0原文

我正在使用.net aspose word api生成Word文档,但是在使用InsertStyleSeparator()时,页面断开后,它将使用第一行和第二行文本添加空白。有人为此做任何工作吗?

I am using .net aspose word api to generate word document but after page break when i use insertStyleSeparator() it add white space with first and second line text. Anyone have any work around for that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

妄想挽回 2025-02-11 04:00:31

听起来您不正确地使用样式分离器。当您需要使用不同样式的单个段落格式化零件时,使用样式分离器。但是从您的描述来看,您可以通过普通段落和

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

for (int i = 0; i < 3; i++)
{
    // to make a title to move to new page set ParagraphFormat.PageBreakBefore property.
    builder.ParagraphFormat.PageBreakBefore = true;
    builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
    builder.Writeln("Section title:");

    // Clear paragraph format to reset ParagraphFormat.PageBreakBefore property.
    builder.ParagraphFormat.ClearFormatting();
    // Now DocumentBuilder cursor is in a new paragraph, so we can reset the style
    builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;

    // Insert an empty paragraph
    builder.Writeln();

    // Insert content
    builder.Writeln("This is a section content.");
}

doc.Save(@"C:\Temp\out.docx");

It sounds that you are using Style Separator improperly. Style Separator is used when you need to format parts for a single paragraph with different styles. But from your description you can achieve what you need with normal paragraphs and ParagraphFormat.PageBreakBefore property to init page break instead of explicit page break. For example see the following code:

Document doc = new Document();
DocumentBuilder builder = new DocumentBuilder(doc);

for (int i = 0; i < 3; i++)
{
    // to make a title to move to new page set ParagraphFormat.PageBreakBefore property.
    builder.ParagraphFormat.PageBreakBefore = true;
    builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Title;
    builder.Writeln("Section title:");

    // Clear paragraph format to reset ParagraphFormat.PageBreakBefore property.
    builder.ParagraphFormat.ClearFormatting();
    // Now DocumentBuilder cursor is in a new paragraph, so we can reset the style
    builder.ParagraphFormat.StyleIdentifier = StyleIdentifier.Normal;

    // Insert an empty paragraph
    builder.Writeln();

    // Insert content
    builder.Writeln("This is a section content.");
}

doc.Save(@"C:\Temp\out.docx");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文