Word开发工具推荐:使用Aspose.Words for C++创建重复节内容控件
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 doc=System::MakeObject();
System::SharedPtr builder=System::MakeObject(doc);
System::SharedPtr xmlPart=doc->get_CustomXmlParts()->Add(u"Books", u"Everyday ItalianGiada De LaurentiisHarry PotterJ K. RowlingLearning XMLErik T. Ray");
System::SharedPtr
table=builder->StartTable();
builder->InsertCell();
builder->Write(u"Title");
builder->InsertCell();
builder->Write(u"Author");
builder->EndRow();
builder->EndTable();
System::SharedPtr repeatingSectionSdt=System::MakeObject(doc, SdtType::RepeatingSection, MarkupLevel::Row);
repeatingSectionSdt->get_XmlMapping()->SetMapping(xmlPart, u"/books[1]/book", u"");
table->AppendChild(repeatingSectionSdt);
System::SharedPtr repeatingSectionItemSdt=System::MakeObject(doc, SdtType::RepeatingSectionItem, MarkupLevel::Row);
repeatingSectionSdt->AppendChild(repeatingSectionItemSdt);
System::SharedPtr row=System::MakeObject(doc);
repeatingSectionItemSdt->AppendChild(row);
System::SharedPtr titleSdt=System::MakeObject(doc, SdtType::PlainText, MarkupLevel::Cell);
titleSdt->get_XmlMapping()->SetMapping(xmlPart, u"/books[1]/book[1]/title[1]", u"");
row->AppendChild(titleSdt);
System::SharedPtr authorSdt=System::MakeObject(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();
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· 白话解读 Dapr 1.15:你的「微服务管家」又秀新绝活了