Restoring default table borders when using the documentbuilder

As per your examples, I am using the document builder to add tables etc. For the header and footer, I am using tables and turn off the border with builder.CellFormat.Borders.ClearFormatting(), but when it comes to tables in the body of the document, the borders do not get turned back on and I can find no command to restore the defaults. Can you help please (VB code preferred)

Hi Martin,

Thanks for your inquiry. Unfortunately, I have not completely understood your query. It would be great if you please share some detail about your query along with code example. It seems that you want to set table’s border.

The following code example shows how to apply a outline border to a table. Hope this helps you.

Dim doc As New Document(MyDir & "Table.EmptyTable.doc")
Dim table As Table = CType(doc.GetChild(NodeType.Table, 0, True), Table)
' Align the table to the center of the page.
table.Alignment = TableAlignment.Center
' Clear any existing borders from the table.
table.ClearBorders()
' Set a green border around the table but not inside. 
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)
' Fill the cells with a light green solid color.
table.SetShading(TextureIndex.TextureSolid, Color.LightGreen, Color.Empty)
doc.Save(MyDir & "Table.SetOutlineBorders Out.doc")

Tahir,

I don’t think that I could have been any clearer!

I am using the document builder - not tables directly. I have cleared table borders when defining tables for the header and footer. Now I am defining tables in the body of the document and find that the tables have no border. Clearly the document builder is remembering the settings from before. I need to tell the document builder to revert to the default settings for tables. I am not using tables directly. I can see from the documentation how to set borders directly with the table variable. I need to reset the table border settings in the documentbuilder.

Hi Martin,

Thanks for sharing the detail. Please call the CellFormat.ClearFormatting method before creating table in the body of document. This method resets to default cell formatting. Please let us know if you have any more queries.

Dim doc As New Document("in.docx")
Dim builder As New DocumentBuilder(doc)
builder.MoveToHeaderFooter(HeaderFooterType.HeaderPrimary)
' We call this method to start building the table.
builder.StartTable()
builder.InsertCell()
builder.CellFormat.Borders.ClearFormatting()
builder.Write("Row 1, Cell 1 Content.")
' Build the second cell
builder.InsertCell()
builder.Write("Row 1, Cell 2 Content.")
' Call the following method to end the row and start a new row.
builder.EndRow()
' Build the first cell of the second row.
builder.InsertCell()
builder.Write("Row 2, Cell 1 Content")
' Build the second cell.
builder.InsertCell()
builder.Write("Row 2, Cell 2 Content.")
builder.EndRow()
' Signal that we have finished building the table.
builder.EndTable()
builder.MoveTo(doc.FirstSection.Body.FirstParagraph)
' We call this method to start building the table.
builder.StartTable()
builder.InsertCell()
builder.CellFormat.ClearFormatting()
builder.Write("Row 1, Cell 1 Content.")
' Build the second cell
builder.InsertCell()
builder.Write("Row 1, Cell 2 Content.")
' Call the following method to end the row and start a new row.
builder.EndRow()
' Build the first cell of the second row.
builder.InsertCell()
builder.Write("Row 2, Cell 1 Content")
' Build the second cell.
builder.InsertCell()
builder.Write("Row 2, Cell 2 Content.")
builder.EndRow()
' Signal that we have finished building the table.
builder.EndTable()
' Save the document to disk.
doc.Save("Out.docx")