เพิ่มหรือแก้ไขการเชื่อมโยงหลายมิติ
การเชื่อมโยงหลายมิติใน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-Java | |
Document doc = new Document(); | |
DocumentBuilder builder = new DocumentBuilder(doc); | |
builder.write("Please make sure to visit "); | |
builder.getFont().setColor(Color.BLUE); | |
builder.getFont().setUnderline(Underline.SINGLE); | |
builder.insertHyperlink("Aspose Website", "http://www.aspose.com", false); | |
builder.getFont().clearFormatting(); | |
builder.write(" for more information."); | |
doc.save(getArtifactsDir() + "AddContentUsingDocumentBuilder.InsertHyperlink.docx"); |
แทนที่หรือแก้ไขการเชื่อมโยงหลายมิติ
การเชื่อมโยงหลายมิติในMicrosoft Wordเอกสารคือฟิลด์ เขตข้อมูลในเอกสารคำที่เรากล่าวว่าก่อนหน้านี้เป็นโครงสร้างที่ซับซ้อนประกอบด้วยโหนด ฟิลด์สามารถซ้อนกันมีเนื้อหาที่อุดมไปด้วยและขยายหลายย่อหน้าหรือส่วนในเอกสาร.
ในการแทนที่หรือแก้ไขการเชื่อมโยงหลายมิติจำเป็นต้องค้นหาการเชื่อมโยงหลายมิติในเอกสารและแทนที่ข้อความURLsหรือทั้งสองอย่าง.
ตัวอย่างโค้ดต่อไปนี้จะแสดงวิธีค้นหาไฮเปอร์ลิงก์ทั้งหมดในเอกสาร Word และเปลี่ยน URL
และชื่อที่แสดง:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java | |
Document doc = new Document(getMyDir() + "Hyperlinks.docx"); | |
for (Field field : doc.getRange().getFields()) | |
{ | |
if (field.getType() == FieldType.FIELD_HYPERLINK) | |
{ | |
FieldHyperlink hyperlink = (FieldHyperlink) field; | |
// Some hyperlinks can be local (links to bookmarks inside the document), ignore these. | |
if (hyperlink.getSubAddress() != null) | |
continue; | |
hyperlink.setAddress("http://www.aspose.com"); | |
hyperlink.setResult("Aspose - The .NET & Java Component Publisher"); | |
} | |
} | |
doc.save(getArtifactsDir() + "WorkingWithFields.ReplaceHyperlinks.docx"); |