2

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);
Cindy Meister
  • 25,071
  • 21
  • 34
  • 43
Rob
  • 53
  • 1
  • 9
  • Could it be helpfull maybe [OpenXML SDK having borders for cell](https://stackoverflow.com/questions/15791732/openxml-sdk-having-borders-for-cell) – Belurd Dec 03 '18 at 15:56
  • 2
    My standard comment. Download the OpenXML Productivity Tool from the Microsoft site. Create a Word doc (in Word) that has a table. Save it. Change the table so that a table cell has a top border. Save that file with a different name. Open the productivity tool and use the Compare/Diff button to diff the two files. The answer should be obvious. – Flydog57 Dec 03 '18 at 15:57

3 Answers3

2

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 enter image description here

Marc Kenneth Lomio
  • 429
  • 1
  • 4
  • 11
2

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. enter image description here

Marc Kenneth Lomio
  • 429
  • 1
  • 4
  • 11
-1

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.

Rob
  • 53
  • 1
  • 9