Tabela podzielona
Tabela, reprezentowana w Aspose.Words Document Object Model, składa się z niezależnych wierszy i komórek, co ułatwia podział tabeli.
Aby manipulować stołem, aby podzielić go na dwie tabele, musimy przenieść niektóre wiersze z oryginalnej tabeli na nową. Aby to zrobić, musimy wybrać wiersz, w którym chcemy podzielić stół.
Możemy stworzyć dwie tabele z oryginalnej tabeli poprzez następujące proste kroki:
- Utwórz klon tabeli bez klonowania dzieci, aby utrzymać przeniesione wiersze i umieścić je po pierwotnej tabeli
- Począwszy od określonego wiersza, przenieś wszystkie kolejne wiersze do tej drugiej tabeli
Poniższy przykład kodu pokazuje jak podzielić tabelę na dwie tabele w określonym wierszu:
// 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"); |