简体   繁体   English

向 ContentRange GemBox 添加一个部分

[英]Adding a section to ContentRange GemBox

I am trying to add a whole section to a particular occurence using GemBox.我正在尝试使用 GemBox 将整个部分添加到特定事件中。

Section section = new Section(documentModel);
documentModel.Sections.Add(section);

ContentRange backgroundCheckSection = documentModel.Content.Find("@@BackGroundChecks").First();
backgroundCheckSection.Start.InsertRange(section);

This code does not work since it cannot implicity conver a ContentRange object to a Section object.此代码不起作用,因为它无法将 ContentRange 对象隐式转换为 Section 对象。 The goal is to add that whole section to where the variable @@BackgroundChecks appears.目标是将整个部分添加到变量@@BackgroundChecks 出现的位置。 I havent figured out how to do it and was wondering if someone could help me out.我还没有想出如何去做,想知道是否有人可以帮助我。

I'm not 100% sure what you want to accomplish, but in order to insert the section's content range you just need to do the following:我不是 100% 确定您想要完成什么,但为了插入该部分的内容范围,您只需要执行以下操作:

backgroundCheckSection.Start.InsertRange(section.Content);

If you could provide more details about exactly what you want to achieve I could help you out further.如果您可以提供有关您想要实现的目标的更多详细信息,我可以进一步帮助您。

Nevertheless what I presume that you want is not to insert a section (this will split the section in which you're inserting into two so you'll end up with 3 sections) in the document, you want to insert only the content of that section into a specified place (where your placeholder "@@BackGroundChecks" is).尽管如此,我认为您想要的不是在文档中插入一个部分(这会将您插入的部分分成两部分,因此您最终会得到 3 个部分),您只想插入该部分的内容部分到指定的位置(您的占位符“@@BackGroundChecks”所在的位置)。

So for this instead of inserting section.Content you can iterate through section.Blocks and insert their content, like the following:因此,为此,您可以遍历section.Blocks并插入其内容,而不是插入section.Content ,如下所示:

foreach(var block in section.Blocks)
    backgroundCheckSection.Start.InsertRange(block.Content);

After that you'll probably want to remove that placeholder:之后,您可能想要删除该占位符:

backgroundCheckSection.Delete();

In case you do want to insert a section note that each section is separated with a section break and you can manipulate where the section starts with it (for example does it start on a new page or continues right after the previous section).如果您确实想插入一个节,请注意每个节都用分节符分隔,并且您可以操纵该节的开头位置(例如,它是从新页面开始还是在上一节之后继续)。 You do this by setting the section.PageSetup.SectionStart property.您可以通过设置section.PageSetup.SectionStart属性来完成section.PageSetup.SectionStart

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM