dotnetcore / NPOI

A .NET library for reading and writing Microsoft Office binary and OOXML file formats.
Apache License 2.0
1.93k stars 413 forks source link

NPOI docx的word 表格,怎么复制并插入上一行。 #155

Closed doneself closed 4 years ago

doneself commented 4 years ago

NPOI里面docx的表格每行的列不一样的时候,没有找到很好的复制一行,然后插入到表格末尾的办法。

doneself commented 4 years ago

搜了一下,看到别人的做法。

for (int j = 0; j < oldRow.GetTableCells().Count; j++)
{
          newRow.CreateCell();
          CT_Tc cttc1 = newRow.GetCell(j).GetCTTc();
          CT_TcPr tcpr1 = cttc1.AddNewTcPr();
          tcpr1.tcW = oldRow.GetCell(j).GetCTTc().tcPr.tcW;
          tcpr1.tcBorders = oldRow.GetCell(j).GetCTTc().tcPr.tcBorders;
          tcpr1.tcMar = oldRow.GetCell(j).GetCTTc().tcPr.tcMar;
          tcpr1.gridSpan = oldRow.GetCell(j).GetCTTc().tcPr.gridSpan;
}