TableStyle.CharacterFormat.FontName not working

I use version, and I can’t get TableStyle.CharacterFormat.FontName to work. I only get Font Arial. The size works fine.

Here is my code: I Have Also Tried Fonts like Verdana and Tahoma.

TableStyle = New TableStyle("CustomTableStyle")
firstLastRowColor = New Color(255, 255, 255)
Dim firstRowFormat = TableStyle.ConditionalFormats(TableStyleFormatType.FirstRow)
firstRowFormat.CharacterFormat.Bold = False
firstRowFormat.CharacterFormat.FontColor = Color.Black
TableStyle.ConditionalFormats(TableStyleFormatType.FirstRow).CellFormat.BackgroundColor = firstLastRowColor
TableStyle.TableFormat.DefaultCellPadding = New Padding(2)
TableStyle.CharacterFormat.Size = dok_grid_font_size
TableStyle.CharacterFormat.FontName = "Times New Roman"

Hi Thor,

I believe that someone is overriding the character format, perhaps the paragraph’s formatting.
Can you send us your DOCX file that reproduces your issue so that we can investigate it?
Also, can you please try again with the latest bugfix version?


I saw no that I worked with a old template DOC files that has been saved as DOCX files.
When I Created a new emtpy DOCX file with the Bookmark for a Table, and tried it there, it works :slight_smile:
So then I have to open all my customers templates and copy them over to new DOCX files :slight_smile:

Can you send us one of those DOC files that reproduce your issue so that we can investigate it?

This is a specific behavior that Word files have, it’s related to paragraph styles inside the table element.

Perhaps the easiest way to detect this behavior is to create a new document, add some sample paragraphs outside the table and inside the table, you’ll notice that they have different spacing:


In other words, “Sample 1” and “Sample 2” have some spacing after, but “Sample 3”, “Sample 4”, etc. don’t have that spacing.

Anyway, this occurs when there is a difference between the document’s default formatting and the document’s style.
In your case, the DOC file has a default formatting that specifies “Times New Roman” font, but the “Normal” style specifies “Arial” font. Because of this, the paragraphs inside the table will have “Arial” font unless you specify a different font directly on them or change their style.

Perhaps the easiest way to resolve this problem is to change the font in the document’s default formatting to be the same as the font in the “Normal” style and then remove the font definition from the “Normal” style.

In other words, try this:

Dim document = DocumentModel.Load("ordrebekreftelse_mal.doc")
Dim normalStyle = CType(document.Styles("Normal"), ParagraphStyle)

document.DefaultCharacterFormat.FontName = normalStyle.CharacterFormat.FontName
normalStyle.CharacterFormat.FontName = Nothing

' ...

Does this solve your issue?