Rozdělený stůl

Contents
[ ]

Tabulka zastoupená v Aspose.Words Document Object Model, se skládá z nezávislých řad a buněk, takže je snadné rozdělit stůl.

Abychom zmanipulovali stůl, abychom ho rozdělili na dva stoly, stačí přesunout některé řádky z původního stolu na nový. Abychom to udělali, musíme si vybrat řádek, kterým chceme rozdělit stůl.

Můžeme vytvořit dvě tabulky z původní tabulky podle těchto jednoduchých kroků:

  1. Vytvořit klon tabulky bez klonování dětí, aby se pohybovaly řádky a vložit je po původní tabulce
  2. Začínáme v uvedeném řádku, přesuňte všechny následující řádky do této druhé tabulky

Následující příklad kódu ukazuje, jak rozdělit tabulku na dvě tabulky v určitém řádku:

// 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");