Table widths: fixed tablewidth and width not responding to builder.CellFormat.Width


#1

I'm experiencing problems with generated tables in code. The width of the table stays the same after a while. Below is the code to generate a table.

builder.CellFormat.ClearFormatting()
' Header rij met vette koppen en onderlijnd

builder.Font.Bold = True
builder.CellFormat.Borders(Aspose.Words.BorderType.Bottom).LineStyle = LineStyle.Single

builder.StartTable()
builder.InsertCell()
builder.CellFormat.Width = 170.0
builder.Write("Naam")

builder.InsertCell()
builder.CellFormat.Width = 40.0
builder.Write("Keten")

builder.InsertCell()
builder.CellFormat.Width = 40.0
builder.Write("FPZ")

builder.InsertCell()
builder.CellFormat.Width = 85.0
builder.Write("Marktaandeel")

builder.InsertCell()
builder.CellFormat.Width = 105.0
builder.Write("Marktontwikkeling")

builder.EndRow()

' Overige regels gewoon

builder.Font.Bold = False
builder.CellFormat.ClearFormatting()
builder.CellFormat.Borders(Aspose.Words.BorderType.Bottom).ClearFormatting()

For Each S1_ConcurrentieApotheek In colConcurentieApotheken
For x = 0 To 4
builder.InsertCell()
builder.CellFormat.ClearFormatting()

Select Case x
Case 0
builder.CellFormat.Width = 170.0
builder.Write(S1_ConcurrentieApotheek.Naam)
Case 1
builder.CellFormat.Width = 40.0
builder.Write(S1_ConcurrentieApotheek.Keten)
Case 2
builder.CellFormat.Width = 40.0
builder.Write(S1_ConcurrentieApotheek.Fpz)
Case 3
builder.CellFormat.Width = 85.0
builder.Write(S1_ConcurrentieApotheek.Omvang)
Case 4
builder.CellFormat.Width = 105.0
builder.Write(S1_ConcurrentieApotheek.Ontwikkeling)
End Select

Next

builder.EndRow()
builder.CellFormat.ClearFormatting()

Next
builder.EndTable()

When running this code the first time it shows perfectly. A second time it doesn't when filling another table with exactly the same formatting code but different data. And suprisingly a third time it works fine again. After some tables the total width of the table will always be the same. This occurs for all instances after tables not generated in code but in MS Word.

I just cannot figure it out what is going wrong. Any suggestions are greatly appreciated.

Regards,

Willem Jan Kortleve


#2

As far as I can see in the attached document, the cell widths in the first table (Naam -170, Keten -40, FPZ - 40, Marktaandeel - 85, Marktontwikkeling - 105) are exactly corresponding to cell widths set in your code.

Try to compose the test project with some dummy data reproducing the problem and attach it here.

Regards,


#3

Hi,

Yes that is true but the second and third table are exactly the same formatted. As you can see the second table looks strange although it has exactly the same dimensions as the first and last one?

The second part of the document contains some tables with different table widths adding up to different table widths but all tables are the same width.

Do I have to reset formatting even more before starting a new table?

If you need more info please tell me what to send.

Regards,

Willem Jan


#4

Ok, but I need something to be able to reproduce the problem. If you make a code snippet that will generate two tables with the same code that will have different format in resulting document then we will be able to start working on the fix right away.

Regards,


#5

Tanks for the response. I tried to setup a simple document with the tables. Ofcourse this works fine. My project document is much bigger (50 + pages with 250 + bookmarks) and contains a lot of code to fill bookmarks.

My project is due tomorrow so at the moment i'm stressed to meet the deadline. I will keep the formatting as is for now and try to reproduce a simple document later this week.

Regards,

Willem Jan