public static void CopyTable(XWPFDocument fileWord, int sourceIndex, int targetIndex)
{
var sourceTable = fileWord.Tables[sourceIndex];
CT_Tbl sourceCTTBl = fileWord.Document.body.GetTblArray(1);
var targetTable = fileWord.CreateTable();
fileWord.SetTable(targetIndex, targetTable);
var targetCTTbl = fileWord.Document.body.GetTblArray()[fileWord.Document.body.GetTblArray().Length - 1];
targetCTTbl.tblPr = sourceCTTbl.tblPr;
targetCTTbl.tblGrid = sourceCTTbl.tblGrid;
for (int i = 0; i < sourceTable.Rows.Count; i++)
{
var tbRow = targetTable.CreateRow();
var targetRow = tbRow.GetCTRow();
tbRow.RemoveCell(0);
XWPFTableRow row = sourceTable.Rows[i];
targetRow.trPr = row.GetCTRow().trPr;
targetRow.trPr = row.GetCTRow().trPr;
targetRow.trPr = row.GetCTRow().trPr;
targetRow.trPr = row.GetCTRow().trPr;
for (int j = 0; j < row.GetTableCells().Count; j++)
{
var tbCell = tbRow.CreateCell();
tbCell.RemoveParagraph(0);
var targetCell = tbCell.GetCTTc();
XWPFTableCell cell = row.GetTableCells()[j];
targetCell.tcPr = cell.GetCTTc().tcPr;
for (int z = 0; z < cell.Paragraphs.Count; z++)
{
var tbPhs = tbCell.AddParagraph();
XWPFParagraph para = cell.Paragraphs[z];
for (int y = 0; y < para.Runs.Count; y++)
{
var tbRun = tbPhs.CreateRun();
CT_R targetRun = tbRun.GetCTR();
XWPFRun run = para.Runs[y];
var runCTR = run.GetCTR();
targetRun.rPr = runCTR.rPr;
targetRun.rsidRPr = runCTR.rsidRPr;
targetRun.rsidR = runCTR.rsidR;
CT_Text text = targetRun.AddNewT();
text.Value = run.Text;
}
}
}
}
targetTable.RemoveRow(0);
}