Hi
Thank you for additional information. Here is the sample code. Also, see the attached documents.
public static void main(String[] args) throws Exception {
// Open all documents
Document doc1 = new Document("C:\\Temp\\doc1.doc");
Document doc2 = new Document("C:\\Temp\\doc2.doc");
Document doc3 = new Document("C:\\Temp\\doc3.doc");
// Create DocumentBuilder object, which will help us to manipulate Doc1
DocumentBuilder builder = new DocumentBuilder(doc1);
// Sinece we will work only with tabels, we do not need to copy whole documents in to the main document
// That is why we get tables from our documents and will work with them
Table mainTable = doc1.getFirstSection().getBody().getTables().get(0);
// We should import tables from sub docuemnt to be able to insert them into the main document
Table tab1 = (Table)doc1.importNode(doc2.getFirstSection().getBody().getTables().get(0), true);
Table tab2 = (Table)doc1.importNode(doc3.getFirstSection().getBody().getTables().get(0), true);
// Insert table 1 into teh main table 7 times
for(int i=0; i<7; i++)
appendTable(mainTable, (Table)tab1.deepClone(true));
// Insett table 2
appendTable(mainTable, (Table)tab2.deepClone(true));
// Now we should insert page break and start new table
// move docuemtn Builder cursor to the end of docuemnt and insert page break
builder.moveToDocumentEnd();
builder.insertBreak(BreakType.PAGE_BREAK);
// Start new table
mainTable = builder.startTable();
// Insert table 1 5 times
for(int i=0; i<5; i++)
appendTable(mainTable, (Table)tab1.deepClone(true));
// Save output document
doc1.save("C:\\Temp\\out.doc");
}
/**
* Append one table to another
*/
private static void appendTable(Table dstTable, Table srcTable) throws Exception
{
for(int i=0; i<srcTable.getRows().getCount(); i++)
dstTable.appendChild(srcTable.getRows().get(i));
}
Hope this helps.
Best regards.
Alexey Noskov
Developer/Technical Support
Aspose Auckland Team