---
title: "Join Tables in Java"
---

```

## Purpose Summary

This page explains how to join tables programmatically.

```

A table, represented in the Aspose.Words Document Object Model, is made up of independent rows and cells, making it easy to join tables.

To manipulate a table to join with another table, we just need to move the rows from the second table to the end of the first one and remove the second table's container.

The following code example shows how to merge rows from two tables into one:

{{< gist "aspose-words-gists" "89807559333317718ba2e6084fdcb3e2" "combine-rows.java" >}}

## Related APIs

- `com.aspose.words.Table` - Represents a table in the document.
- `com.aspose.words.Row` - Represents a table row.
- `Document.importNode(Node, boolean)` - Imports a node from another document, preserving formatting when the second parameter is `true`.
- `RowCollection.add(Node)` - Adds a row to the table's row collection.
- `Node.remove()` - Removes the node from the document.

## FAQ

1. **Q:** How can I join two tables in a Word document using Aspose.Words for Java?
   **A:** Locate the two `Table` objects in the document, then move each `Row` from the second table into the first using `firstTable.appendChild(row.deepClone(true))`. After all rows are transferred, remove the now‑empty second table with `secondTable.remove()`. Finally, call `doc.updatePageLayout()` to refresh the layout.

2. **Q:** How do I split a joined table back into separate tables?
   **A:** Create a new `Table` instance, move the rows you want to separate from the original table into the new one, and insert the new table at the desired position using `firstTable.getParentNode().insertAfter(newTable, firstTable)`. Adjust any required formatting on the new table’s rows and cells.

3. **Q:** The joined table loses its original formatting after moving rows. What should I do?
   **A:** Preserve formatting by cloning the row with `row.deepClone(true)`, which copies both content and formatting. After the join, call `firstTable.ensureMinimum()` and `doc.updatePageLayout()` to make sure the table layout is recalculated and the formatting is applied correctly.