Rozdělená Tabulka
Contents
[
Hide
]
Tabulka reprezentovaná v modelu objektu Aspose.Words dokumentu se skládá z nezávislých řádků a buněk, což usnadňuje rozdělení tabulky.
Chcete-li manipulovat s tabulkou a rozdělit ji na dvě tabulky, stačí přesunout některé řádky z původní tabulky do nové. K tomu musíme vybrat řádek, kterým chceme tabulku rozdělit.
Můžeme vytvořit dvě tabulky z původní tabulky podle těchto jednoduchých kroků:
- Vytvořte klon tabulky bez klonování dětí, abyste udrželi přesunuté řádky a vložili je za původní tabulku
- Počínaje zadaným řádkem 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 na konkrétním řádku:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// For complete examples and data files, please go to https://github.com/aspose-words/Aspose.Words-for-C.git. | |
auto doc = MakeObject<Document>(MyDir + u"Tables.docx"); | |
auto firstTable = System::ExplicitCast<Table>(doc->GetChild(NodeType::Table, 0, true)); | |
// We will split the table at the third row (inclusive). | |
SharedPtr<Row> row = firstTable->get_Rows()->idx_get(2); | |
// Create a new container for the split table. | |
auto table = System::ExplicitCast<Table>(firstTable->Clone(false)); | |
// Insert the container after the original. | |
firstTable->get_ParentNode()->InsertAfter(table, firstTable); | |
// Add a buffer paragraph to ensure the tables stay apart. | |
firstTable->get_ParentNode()->InsertAfter(MakeObject<Paragraph>(doc), firstTable); | |
SharedPtr<Row> currentRow; | |
do | |
{ | |
currentRow = firstTable->get_LastRow(); | |
table->PrependChild(currentRow); | |
} while (currentRow != row); | |
doc->Save(ArtifactsDir + u"WorkingWithTables.SplitTable.docx"); |