删除Word文档(OpenXml.Wordprocessing)中的表格中的单元格边框

时间:2018-11-07 11:11:58

标签: c# openxml wordprocessingml

我正在使用DocumentFormat.OpenXml.Wordprocessing在Word文档中添加表格。我需要删除表格的最后3(/ N)行中前4(/ 6)个单元格的边框。这些行的添加方式如下:

t.Append(new TableRow(
    new TableCell(new Paragraph(new Run(new Text()))),
    new TableCell(new Paragraph(new Run(new Text()))),
    new TableCell(new Paragraph(new Run(new Text()))),
    new TableCell(new Paragraph(new Run(new Text()))),
    new TableCell(new Paragraph(new Run(new Text("Total:")))),
    new TableCell(new Paragraph(new Run(new Text(priceTotal.ToString()))))
    ));

如何设置TableCellBorders?我已经尝试过一些类似的事情:

TableCell cell = new TableCell();
cell.TableCellProperties.TableCellBorders.LeftBorder.Size.Value = 0;
cell.TableCellProperties.TableCellBorders.RightBorder.Size.Value = 0;
cell.TableCellProperties.TableCellBorders.TopBorder.Size.Value = 0;
cell.TableCellProperties.TableCellBorders.BottomBorder.Size.Value = 0;

但是,我尝试过的所有内容都会返回System.NullReferenceException。删除单元格边界的正确方法是什么?

1 个答案:

答案 0 :(得分:1)

您可以像这样用无边界的单词创建表格:

     <div title="mytitle">
      <star-rating-comp [starType]="'svg'" 
                        [showHalfStars]="true" 
                        [rating]="cards[questionNumber].rating" 
                        [readOnly]="true" 
                        title="mytitle">
      </star-rating-comp>
    </div>

根据您的需要对其进行自定义和优化:)