Missing Borders in cell using builder.CellFormat


#1

Hi, I'm using Aspose Words 3.7.0.0 and I'm trying to build a table using
some code like the following
...
builder.MoveToMergeField(bookmark)
builder.Write("")
builder.Font.Name = "Arial"

builder.CellFormat.VerticalAlignment = CellVerticalAlignment.Center
builder.InsertCell()
builder.CellFormat.Borders.LineStyle = LineStyle.None
builder.CellFormat.Width = 2 * px

builder.InsertCell()
'Even commenting the following rows I can't get top and bottom borders
builder.CellFormat.Borders(Aspose.Words.BorderType.Top).LineStyle = LineStyle.Single
builder.CellFormat.Borders(Aspose.Words.BorderType.Left).LineStyle = LineStyle.Single
builder.CellFormat.Borders(Aspose.Words.BorderType.Bottom).LineStyle = LineStyle.Single
builder.CellFormat.Borders(Aspose.Words.BorderType.Right).LineStyle = LineStyle.Single
'Even commenting the previous rows I can't get top and bottom borders
builder.CellFormat.Borders.LineStyle = LineStyle.Single
builder.CellFormat.Borders.LineWidth = 1
builder.CellFormat.Width = 4 * px '7"
builder.Bold = True
builder.RowFormat.Alignment = RowAlignment.Center
builder.ParagraphFormat.Alignment = ParagraphAlignment.Center
builder.Write(dtOffeTestata.Rows(0).Item("NORME"))
...
builder.EndRow()
builder.EndTable()
...

I obtain the word document attached and the top and bottom borders of the cell
with NORME as text are missing, only left and right bordes are visible.

How can I get it working ?

Thank You

Claudio Mellina


#2

The code that you have posted works correctly in my test. Please attach a complete project or try to compose the smaller test project reproducing the error.

Best regards,


#3

Hi,

I've found the problem and how to reproduce it.

Using the attached code, uncommenting the line between TODO the table looses top and bottom borders.

Private Sub Sostituisci(ByRef doc As Aspose.Words.Document, ByRef errMsg As String)

Dim builder As DocumentBuilder = New DocumentBuilder(doc)
Dim ncol As Int32
Dim px As Int32 = 66


DeleteParagraph(doc, "P37", errMsg)
'TODO
'If I execute also the following line the table loses top and bottom borders
'DeleteParagraph(doc, "P38", errMsg)
'TODO

builder = New DocumentBuilder(doc)
builder.MoveToMergeField("P15")
builder.Write("")
builder.Font.Name = "Arial"
...

Claudio


#4

Thank you for this. I will check it up and let you know ASAP.

Best regards,


#5

The DeleteParagraph procedure does not look good. Using exceptions as part of application logic is generally a bad idea. The behavior of library code after the exception is 'swallowed' by calling app is unpredictable. Why not using the simple code like this:

Private Sub DeleteParagraph(ByRef doc As Aspose.Words.Document, ByVal bookmark As String, ByRef errMsg As String)

Dim builder As DocumentBuilder = New DocumentBuilder(doc)

If builder.MoveToMergeField(bookmark) Then

builder.CurrentParagraph.Remove()

End If

End Sub

The problems with disappearing borders are eliminated after this.

Best regards,


#6

Thank You, I'll try

Claudio