ปรับแต่งคุณสมบัติฟิลด์

Aspose.Wordsให้ความสามารถในการโต้ตอบทางโปรแกรมกับคุณสมบัติของฟิลด์ต่างๆ ในบทความนี้เราจะดูคู่ตัวอย่างเพื่อให้คุณเข้าใจหลักการพื้นฐานของการทำงานกับคุณสมบั คุณสามารถดูรายการทั้งหมดของคุณสมบัติสำหรับแต่ละชนิดเขตข้อมูลในชั้นเรียนที่สอดคล้.

ปรับปรุงคุณสมบัติฟิลด์

บางครั้งผู้ใช้ต้องเปลี่ยนค่าของคุณสมบัติฟิลด์ ตัวอย่างเช่นปรับปรุงคุณสมบัติAuthorNameของฟิลด์AUTHORหรือเปลี่ยนแปลงคุณสมบัติFieldNameของฟิลด์MERGEFIELD.

ตัวอย่างรหัสต่อไปนี้แสดงวิธีการเปลี่ยนชื่อฟิลด์ผสานในเอกสารคำ:

// 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.insertField("MERGEFIELD MyMergeField1 \\* MERGEFORMAT");
builder.insertField("MERGEFIELD MyMergeField2 \\* MERGEFORMAT");
for (Field f : doc.getRange().getFields())
{
if (f.getType() == FieldType.FIELD_MERGE_FIELD)
{
FieldMergeField mergeField = (FieldMergeField)f;
mergeField.setFieldName(mergeField.getFieldName() + "_Renamed");
mergeField.update();
}
}
doc.save(getArtifactsDir() + "WorkingWithFields.RenameMergeFields.docx");

ผลลัพธ์การแสดงผลฟิลด์

Aspose.Wordsจัดเตรียมคุณสมบัติเพื่อให้ได้ผลลัพธ์ของฟิลด์สำหรับฟิลด์ที่ไม่มีโหนดตัวคั่นฟิลด์ เราเรียกสิ่งนี้ว่า"ผลลัพธ์ปลอม"หรือแสดงผล;MSคำแสดงในเอกสารโดยการคำนวณค่าของฟิลด์ใ.

ตัวอย่างรหัสต่อไปนี้แสดงการใช้คุณสมบัติDisplayResult:

// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java
Document document = new Document(getMyDir() + "Various fields.docx");
document.updateFields();
//ExEnd:UpdateDocFields
for (Field field : document.getRange().getFields())
System.out.println(field.getDisplayResult());