C# 通过Aspose在word文档中存储构建块

C# 通过Aspose在word文档中存储构建块,c#,aspose.words,C#,Aspose.words,我正在寻找一个使用Aspose word Api在word文档中存储构建块的示例。我想在本文档中独家使用这些构建块 有人有想法吗,这是如何实现的 问候 Tobi.如果您的计算机上安装了MS Word 2013,您很可能会在以下位置找到Word文档“内置Building Blocks.dotx”: C:\Users\Awais\AppData\Roaming\Microsoft\Document Building Blocks\1033\15\Build-In Building Blocks.do

我正在寻找一个使用Aspose word Api在word文档中存储构建块的示例。我想在本文档中独家使用这些构建块

有人有想法吗,这是如何实现的

问候


Tobi.

如果您的计算机上安装了MS Word 2013,您很可能会在以下位置找到Word文档“内置Building Blocks.dotx”:

C:\Users\Awais\AppData\Roaming\Microsoft\Document Building Blocks\1033\15\Build-In Building Blocks.dotx

Word附带的预定义内置构建块条目存储在上述模板文档中。使用Aspose.Words,您可以从中提取任何构建块,粘贴到另一个Word文档中,并保存新文档以备将来使用

Aspose中的GlossaryDocument类。Word表示此类构建块。请尝试使用以下代码:

Document docBuildingBlocks = new Document(MyDir + @"Building Blocks.dotx");
Document doc = new Document(MyDir + @"input.docx");

GlossaryDocument glossaryDocument = docBuildingBlocks.GlossaryDocument;
foreach (BuildingBlock buildingBlock in glossaryDocument.BuildingBlocks)
{
    if (buildingBlock.Gallery.ToString().StartsWith("CoverPage"))
    {
        Section sec = (Section)buildingBlock.FirstChild;
        doc.AppendChild(doc.ImportNode(sec, true));
    }
}

doc.Save(MyDir + @"15.6.0.docx");
希望,这有帮助


我与Aspose合作,担任开发人员福音传道者。

您能详细解释一下构建块吗?如果您发布一个Word示例文档,这将非常有用,我们可以查看并指导您如何使用Aspose.Words实现。