Aspose.Words for C ++ 是一种高级Word文档处理API,用于执行各类文档处理任务。API直接在您本身的C ++应用程序中提供文档格式化,操做,邮件合并,水印和更多功能,而无需Microsoft Word。API支持大多数Microsoft Word格式进行处理。数据库
近期更新了Aspose.Words for C ++ v19.10,容许在同一项目中使用多个Aspose产品,在Skia上实现渲染引擎以提升渲染的质量和稳定性,具体更新内容同Aspose.Words for .Net。bash
Aspose.Words for C ++与其等效的.NET版本的API相比有一些差别:app
本文将为你们介绍一个有趣的的功能——在Word文档中建立重复节内容控件。ui
重复部份内容控件容许重复其中包含的内容。为此,SdtType枚举类型提供了RepeatingSectionItem属性。下面的代码示例演示如何将Word文档中的重复节内容控件绑定到表。加密
System::SharedPtr<Document> doc = System::MakeObject<Document>();
System::SharedPtr<DocumentBuilder> builder = System::MakeObject<DocumentBuilder>(doc);
System::SharedPtr<CustomXmlPart> xmlPart = doc->get_CustomXmlParts()->Add(u"Books", u"<books><book><title>Everyday Italian</title><author>Giada De Laurentiis</author></book><book><title>Harry Potter</title><author>J K. Rowling</author></book><book><title>Learning XML</title><author>Erik T. Ray</author></book></books>"); System::SharedPtr<Table> table = builder->StartTable(); builder->InsertCell(); builder->Write(u"Title"); builder->InsertCell(); builder->Write(u"Author"); builder->EndRow(); builder->EndTable(); System::SharedPtr <StructuredDocumentTag> repeatingSectionSdt = System::MakeObject<StructuredDocumentTag>(doc, SdtType::RepeatingSection, MarkupLevel::Row); repeatingSectionSdt->get_XmlMapping()->SetMapping(xmlPart, u"/books[1]/book", u""); table->AppendChild(repeatingSectionSdt); System::SharedPtr <StructuredDocumentTag> repeatingSectionItemSdt = System::MakeObject<StructuredDocumentTag>(doc, SdtType::RepeatingSectionItem, MarkupLevel::Row); repeatingSectionSdt->AppendChild(repeatingSectionItemSdt); System::SharedPtr<Row> row = System::MakeObject<Row>(doc); repeatingSectionItemSdt->AppendChild(row); System::SharedPtr <StructuredDocumentTag> titleSdt = System::MakeObject<StructuredDocumentTag>(doc, SdtType::PlainText, MarkupLevel::Cell); titleSdt->get_XmlMapping()->SetMapping(xmlPart, u"/books[1]/book[1]/title[1]", u""); row->AppendChild(titleSdt); System::SharedPtr <StructuredDocumentTag> authorSdt = System::MakeObject<StructuredDocumentTag>(doc, SdtType::PlainText, MarkupLevel::Cell); authorSdt->get_XmlMapping()->SetMapping(xmlPart, u"/books[1]/book[1]/author[1]", u""); row->AppendChild(authorSdt); doc->Save(outputDataDir + u"Document.docx");复制代码
“ Aspose.Words for C ++” API如今提供了一种方法CustomDocumentProperties.addLinkToContent(String,String)来建立新的“连接至内容”自定义文档属性,该属性将返回新建立的属性对象;若是连接源无效,则返回null。下面的代码示例演示如何配置到内容定制属性的连接。spa
System::SharedPtrdoc = System::MakeObject(inputDataDir + u"test.docx"); // Retrieve a list of all custom document properties from the file. System::SharedPtrcustomProperties = doc->get_CustomDocumentProperties(); // Add linked to content property. System::SharedPtrcustomProperty = customProperties->AddLinkToContent(u"PropertyName", u"BookmarkName"); // Also, accessing the custom document property can be performed by using the property name. customProperty = customProperties->idx_get(customProperties->IndexOf(u"PropertyName")); // Check whether the property is linked to content. bool isLinkedToContent = customProperty->get_IsLinkToContent(); // Get the source of the property. System::String source = customProperty->get_LinkSource(); // Get the value of the property. System::String value = customProperty->get_Value()->ToString();