简体   繁体   中英

Open XML - Word Processing Document - Table Cell Border

I can add a border to a table row, but how can I add a top border to a table cell? I cannot seem to find this in the ECMA documentation.

   TableProperties tblProperties = new TableProperties();
    TableBorders tblBorders = new TableBorders();
    TopBorder topBorder = new TopBorder();
    topBorder.Val = new EnumValue<BorderValues>(BorderValues.Thick);
    topBorder.Color = "CC0000";
    tblBorders.AppendChild(topBorder);

    tblProperties.AppendChild(tblBorders);

Add the following to your row element.

 TableCellProperties tableCellProperties = new TableCellProperties();
                                        TableCellBorders tableCellBorders = new TableCellBorders();
                                        TopBorder topBorder = new TopBorder() 
                                        { 
                                          Val = new EnumValue<BorderValues>(BorderValues.CheckedBarBlack),
                                          Color = "000000"
                                        };



  tableCellBorders.AppendChild(topBorder);
                                        tableCellProperties.Append(tableCellBorders);

   rowElement.Append(tableCellProperties);

Attached the expected result在此处输入图像描述

And if you want to have shade on the specific row.

Kindly add the following to your row element.

TableCellProperties tableCellProperties = new TableCellProperties();

                                      var shading = new Shading()
                                      {
                                          Color = "auto",
                                          Fill = "D9D9D9",
                                          Val = ShadingPatternValues.Clear
                                      };
                                      tableCellProperties.Append(shading);
                                      rowElement.Append(tableCellProperties);

Attached the expected result. 在此处输入图像描述

Flydog57's comment to using the OpenXML Productivity Tool is the correct approach. You will spend way too much time attempting to figure things out on your own. Make a word document and then view it using the OpenXML Productivity Tool. Rinse and repeat.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM