ตารางแยก
ตารางที่แสดงในแบบจำลองอ็อบเจ็กต์เอกสารAspose.Wordsประกอบด้วยแถวและเซลล์ที่เป็นอิสระทำใ.
ในการจัดการกับตารางที่จะแยกออกเป็นสองตารางเราก็ต้องย้ายบางส่วนของแถวจากต การทำเช่นนี้เราต้องเลือกแถวโดยที่เราต้องการที่จะแยกตาราง.
เราสามารถสร้างตารางสองตารางจากตารางเดิมโดยทำตามขั้นตอนง่ายๆเหล่านี้:
- สร้างโคลนของตารางโดยไม่ต้องโคลนเด็กเพื่อให้แถวย้ายและใส่พวกเขาหลังจากที่ตาร
- เริ่มต้นที่แถวที่ระบุย้ายแถวที่ตามมาทั้งหมดไปยังตารางที่สองนี้
ตัวอย่างรหัสต่อไปนี้แสดงวิธีการแบ่งตารางเป็นสองตารางในแถวที่ระบุ:
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-Java.git. | |
Document doc = new Document(getMyDir() + "Tables.docx"); | |
Table firstTable = (Table) doc.getChild(NodeType.TABLE, 0, true); | |
// We will split the table at the third row (inclusive). | |
Row row = firstTable.getRows().get(2); | |
// Create a new container for the split table. | |
Table table = (Table) firstTable.deepClone(false); | |
// Insert the container after the original. | |
firstTable.getParentNode().insertAfter(table, firstTable); | |
// Add a buffer paragraph to ensure the tables stay apart. | |
firstTable.getParentNode().insertAfter(new Paragraph(doc), firstTable); | |
Row currentRow; | |
do | |
{ | |
currentRow = firstTable.getLastRow(); | |
table.prependChild(currentRow); | |
} while (currentRow != row); | |
doc.save(getArtifactsDir() + "WorkingWithTables.SplitTable.docx"); |