HorizontalAlignment for WTableCell not working

Hi,

I have a table with rows and cells. For the cells I want to set the HorizontalAlignment but is does not change the alignment. I use the next code:

    Dim row As WTableRow = table.AddRow()
    
    Dim cell As WTableCell = row.AddCell()
    cell.Width = 200
    cell.CellFormat.BackColor = Color.DarkBlue
    cell.CellFormat.Borders.BorderType = BorderStyle.None
    Call AlignCellContent(cell, VerticalAlignment.Middle, HorizontalAlignment.Right)
    cell.AddParagraph().AppendText("XXXXX")

    cell = row.AddCell()
    cell.Width = 200
    cell.CellFormat.BackColor = Color.DarkBlue
    cell.CellFormat.Borders.BorderType = BorderStyle.None
    Call AlignCellContent(cell, VerticalAlignment.Middle, HorizontalAlignment.Center)
    cell.AddParagraph().AppendText("YYYYY")

    Private Sub AlignCellContent(ByVal tableCell As WTableCell, ByVal verticalAlignment As VerticalAlignment, ByVal horizontalAlignment As HorizontalAlignment)
        tableCell.CellFormat.VerticalAlignment = verticalAlignment
        AlignCellContentForTextBody(tableCell, horizontalAlignment)
    End Sub

    Private Sub AlignCellContentForTextBody(ByVal textBody As WTextBody, ByVal horizontalAlignment As HorizontalAlignment)
        For i As Integer = 0 To textBody.ChildEntities.Count - 1
            Dim bodyItemEntity As IEntity = textBody.ChildEntities(i)

            Select Case bodyItemEntity.EntityType
                Case EntityType.Paragraph
                    Dim paragraph As WParagraph = TryCast(bodyItemEntity, WParagraph)
                    paragraph.ParagraphFormat.HorizontalAlignment = horizontalAlignment
                Case EntityType.Table
                    AlignCellContentForTable(TryCast(bodyItemEntity, WTable), horizontalAlignment)
                Case EntityType.BlockContentControl
                    Dim blockContentControl As BlockContentControl = TryCast(bodyItemEntity, BlockContentControl)
                    AlignCellContentForTextBody(blockContentControl.TextBody, horizontalAlignment)
            End Select
        Next
    End Sub

    Private Sub AlignCellContentForTable(ByVal table As WTable, ByVal horizontalAlignment As Syncfusion.DocIO.DLS.HorizontalAlignment)
        For Each row As WTableRow In table.Rows
            For Each cell As WTableCell In row.Cells
                AlignCellContentForTextBody(cell, horizontalAlignment)
            Next
        Next
    End Sub


3 Replies


VI Vince February 21, 2020 10:27 AM UTC

Thanks, that solved the problem!


VA Vijayasurya Anandhan Syncfusion Team February 21, 2020 10:39 AM UTC

Hi Vince,

Thank you for your update and confirmation.

We are glad to know that the reported problem gets resolved.
Please let us know if you need further assistance in this. As always, we will be happy to assist you. 

Please let us know if you have any questions.

Regards,
Vijayasurya A


Loader.
Up arrow icon