필드 속성 사용자 지정
Contents
[
Hide
]
Aspose.Words 프로그래밍 방식으로 다양한 필드 속성과 상호 작용하는 기능을 제공합니다. 이 기사에서는 필드 속성 작업의 기본 원리를 이해할 수 있도록 몇 가지 예를 살펴볼 것입니다. 해당 클래스의 각 필드 유형에 대한 전체 속성 목록을 볼 수 있습니다. Fields namespace.
필드 속성 업데이트
때때로 사용자는 필드 속성의 값을 변경해야 합니다. 예를 들어,업데이트 AuthorName 의 재산 AUTHOR
필드 또는 변경 FieldName 의 재산 MERGEFIELD
필드
다음 코드 예제에서는 단어 문서에서 병합 필드의 이름을 바꾸는 방법을 보여 줍니다:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
auto doc = MakeObject<Document>(); | |
auto builder = MakeObject<DocumentBuilder>(doc); | |
builder->InsertField(u"MERGEFIELD MyMergeField1 \\* MERGEFORMAT"); | |
builder->InsertField(u"MERGEFIELD MyMergeField2 \\* MERGEFORMAT"); | |
// Select all field start nodes so we can find the merge fields. | |
SharedPtr<NodeCollection> fieldStarts = doc->GetChildNodes(NodeType::FieldStart, true); | |
for (const auto& fieldStart : System::IterateOver<FieldStart>(fieldStarts)) | |
{ | |
if (fieldStart->get_FieldType() == FieldType::FieldMergeField) | |
{ | |
auto mergeField = MakeObject<WorkingWithFields::MergeField>(fieldStart); | |
mergeField->set_Name(mergeField->get_Name() + u"_Renamed"); | |
} | |
} | |
doc->Save(ArtifactsDir + u"WorkingWithFields.RenameMergeFields.docx"); |
필드 표시 결과
Aspose.Words 필드 구분 노드가 없는 필드에 대한 필드 결과를 가져오는 속성을 제공합니다. 우리는 이것을"가짜 결과"또는 표시 결과라고 부릅니다; Microsoft Word 필드 값을 즉시 계산하여 문서에 표시하지만 문서 모델에는 이러한 값이 없습니다.
다음 코드 예제에서는 DisplayResult 재산:
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
auto doc = MakeObject<Document>(MyDir + u"Various fields.docx"); | |
doc->UpdateFields(); | |
for (const auto& field : System::IterateOver(document->get_Range()->get_Fields())) | |
{ | |
std::cout << field->get_DisplayResult() << std::endl; | |
} |