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。
Aspose.Words for C ++与其等效的.NET版本的API相比有一些差异:
- 当前版本不支持加密功能-无法验证,签名,加密或解密文档。
- 当前版本不支持从Internet下载远程资源。
- 当前版本不支持计量许可证。
- 当前版本不支持多页TIFF格式。
- 当前版本不支持LINQ和报告功能。
- 当前版本对数据库功能的支持有限-C ++没有用于DB的通用API,例如.Net System.Data。
- 当前版本仅支持Microsoft Visual C ++版本2015或更高版本,并且仅支持x64平台。
本文将为大家介绍一个有趣的的功能——在Word文档中创建重复节内容控件。
重复部分内容控件允许重复其中包含的内容。为此,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。下面的代码示例演示如何配置到内容定制属性的链接。
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();