翻譯|使用教程|編輯:李顯亮|2019-10-24 11:29:37.317|閱讀 237 次
概述:近期更新了Aspose.Words for C ++ v19.10,允許在同一項目中使用多個Aspose產品,在Skia上實現渲染引擎以提高渲染的質量和穩定性,本文將為大家介紹一個有趣的的功能——在Word文檔中創建重復節內容控件。
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
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 .Net v19.10更新說明】
Aspose.Words for C ++與其等效的.NET版本的API相比有一些差異:
本文將為大家介紹一個有趣的的功能——在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();
ASPOSE技術交流QQ群(642018183)已開通,各類資源及時分享,歡迎交流討論!
如果你對Aspose的產品感興趣或有任何技術難題都可以掃描下方二維碼告訴我們哦~
↓↓↓
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn