1
我在docx文件中有一行表,我想添加一些行。對於第一個存在的行,我將GridSpan設置爲3.在下一個行中,我只需要添加一行與兩個單元格,然後獲得圖片上的結果。我怎樣才能修復新的行寬到表寬度?當我在新行中只添加一個單元格時,我也想做同樣的事情。使用Open XML SDK修復Word中的單元格寬度
我的代碼:
private static TableRow AddRow(WordprocessingDocument docx, Table tbl, int cellsQuantity)
{
TableRow newRow = new TableRow();
var firstCell = tbl.Descendants<TableRow>().First()
.Descendants<TableCell>().First();
firstCell.Append(new TableCellProperties(new GridSpan() { Val = 3 }));
for (int i = 0, max = cellsQuantity; i < max; i++)
{
// TableCellProperties tcp = new TableCellProperties(new TableCellWidth() { Width = firstCell.TableCellProperties.TableCellWidth.Width, Type = firstCell.TableCellProperties.TableCellWidth.Type });
TableCell cell = new TableCell(new Paragraph(new Run(new Text("test"))));
newRow.AppendChild(cell);
}
tbl.Append(newRow);
return newRow;
}