เพิ่มหรือแก้ไขการเชื่อมโยงหลายมิติ
การเชื่อมโยงหลายมิติในMicrosoft Wordเอกสารคือฟิลด์HYPERLINK
ในAspose.Wordsการเชื่อมโยงหลายมิติจะดำเนินการผ่านFieldHyperlinkคลาส.
การแทรกการเชื่อมโยงหลายมิติ
ใช้วิธีการInsertHyperlinkเพื่อแทรกการเชื่อมโยงหลายมิติลงในเอกสาร วิธีนี้ยอมรับสามพารามิเตอร์:
- ข้อความของลิงก์ที่จะแสดงในเอกสาร
- เชื่อมโยงปลายทาง(URLหรือชื่อของบุ๊กมาร์กภายในเอกสาร)
- พารามิเตอร์บูลีนที่ควรเป็นจริงถ้า
URL
เป็นชื่อของบุ๊กมาร์กภายในเอกสาร
วิธีInsertHyperlinkจะเพิ่มเครื่องหมายวรรคตอนที่จุดเริ่มต้นและจุดสิ้นสุดของURLเสมอ.
Font
.
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการแทรกการเชื่อมโยงหลายมิติลงในเอกสารโดยใช้DocumentBuilder:
//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->Write(u"Please make sure to visit "); | |
builder->get_Font()->set_Color(System::Drawing::Color::get_Blue()); | |
builder->get_Font()->set_Underline(Underline::Single); | |
builder->InsertHyperlink(u"Aspose Website", u"http://www.aspose.com", false); | |
builder->get_Font()->ClearFormatting(); | |
builder->Write(u" for more information."); | |
doc->Save(ArtifactsDir + u"AddContentUsingDocumentBuilder.InsertHyperlink.docx"); |
แทนที่หรือแก้ไขการเชื่อมโยงหลายมิติ
การเชื่อมโยงหลายมิติในMicrosoft Wordเอกสารคือฟิลด์ เขตข้อมูลในเอกสารคำเป็นโครงสร้างที่ซับซ้อนประกอบด้วยหลายโหนดที่มีเขตข้อมูลเริ่ม ฟิลด์สามารถซ้อนกันมีเนื้อหาที่อุดมไปด้วยและขยายหลายย่อหน้าหรือส่วนในเอกสาร.
คลาสFieldHyperlink
ใช้ฟิลด์HYPERLINK
.
ตัวอย่างโค้ดต่อไปนี้จะแสดงวิธีค้นหาไฮเปอร์ลิงก์ทั้งหมดในเอกสาร Word และเปลี่ยน URL
และชื่อที่แสดง:
//For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C | |
auto doc = MakeObject<Document>(MyDir + u"Hyperlinks.docx"); | |
for (const auto& field : System::IterateOver(doc->get_Range()->get_Fields())) | |
{ | |
if (field->get_Type() == FieldType::FieldHyperlink) | |
{ | |
auto hyperlink = System::DynamicCast<FieldHyperlink>(field); | |
// Some hyperlinks can be local (links to bookmarks inside the document), ignore these. | |
if (hyperlink->get_SubAddress() != nullptr) | |
{ | |
continue; | |
} | |
hyperlink->set_Address(u"http://www.aspose.com"); | |
hyperlink->set_Result(u"Aspose - The .NET & Java Component Publisher"); | |
} | |
} | |
doc->Save(ArtifactsDir + u"WorkingWithFields.ReplaceHyperlinks.docx"); |