Getting/setting table borders and shading

I need to know how to get/set borders and shading for a table
for instance, I have a table variable. I want to store the borders and shading for the table, then restore the values after I’ve added new rows to apply at the table level.

@conniem,

Thanks for your inquiry. To ensure a timely and accurate response, please ZIP and attach the following resources here for testing:

  • Your sample input Word document
  • Your expected Word document showing the correct output. Please create this document by using MS Word.

As soon as you get these pieces of information ready, we will start investigation into your issue and provide you code to achieve the same by using Aspose.Words. Thanks for your cooperation.

doing research, I found this to SET the border information
table.SetBorder(BorderType.Left, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Right, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Top, LineStyle.Single, 1.5, Color.Green, true);
table.SetBorder(BorderType.Bottom, LineStyle.Single, 1.5, Color.Green, true);

but how do I GET the information?
i.e.
Borders = table.GetBorder(based on border type)?

@conniem,

Please note that border data is specific to RowFormat of each row, and Shading is specific to CellFormat of each cell.

SetBorders is just a shorthand method for setting all Borders for all rows to the same value, and hence SetShading sets the shading for every cell in every row.

GetBorder and GetShading is not quite possible since border and shading data can vary across rows and cells in the table.

Depending on what you want, you can either check the borders of a single row and shading of a single cell (or all rows/cells in the table) to get the needed data.

what I’m trying to get to is the border/shading at the table level.
when you use word, and go to table properties, you can set the border to apply to the table.
are you saying that I am unable to get to that level? I have to use the row for borders and the cell for the shading, when applied to the table?

@conniem,

If you apply borders at Table level, even then you need to use Row.RowFormat.Borders, Cell.CellFormat.Borders and Cell.CellFormat.Shading properties to get the desired values.