I have a table in a Word document with 3 rows: 1st for Header, 2nd for Data placeholder, and 3rd for Summary. I want to clone the second row right after it - before Summary row. What I tried to do using NPOI:
XWPFTableRow.CloneRow() - it works but adds a new row at the end of the table:
XWPFTableRow newRow = dataRow.CloneRow();
I looked at the CloneRow() source code and tried to repeat the behavior changing Add() to Insert(). But the new row didn't appear at all:
var ctBaseRow = dataRow.GetCTRow();
var newRow = new XWPFTableRow(ctBaseRow.Copy(), table);
table.Rows.Insert(newIndex, newRow);
There is also the InsertNewTableRow() method that breaks the table:
var newRow = table.InsertNewTableRow(newIndex);
And Copy() method with no effect:
XWPFTableRow newRow = dataRow.Copy();
table.Rows.Insert(newIndex, newRow);
The question is: How to clone a row and insert it at the specified index?