c1Excel render range centred

Posted by: jxbhome on 5 November 2019, 12:58 am EST

  • Posted 5 November 2019, 12:58 am EST

    Have:

    
    DIm XLBook as new C1XLBook
    Dim Sheet as c1ExcelSheet = c1ExcelBook.Sheets(0)
    
    Dim styleBoldCentred as New XLStyle(c1ExcelBook)
    With styleBoldCentred
    		.AlignHorz = XLHorizTextAlign.Center
    			.AlignVert = XLVertTextAlign.Center
    			.ForeColor = Color.Black
    			.SetBorderStyle(XLLineStyleEnum.Thin)
    End With
    
    Dim Range As XLCellRange = New XLCellRange(0, 3,0,0)
    Sheet.MergedCells.Add(Range)
    Range.Style = styleBoldCentred
    
    With Sheet(0, 0)
    	.Value = "Text"
    End With
    
    
    

    Without the range the cell renders correctly being centred in the cell.

    Using the it renders the text on line 3 i.e. at bottom of the cell not centred.

    Any ideas?

    Thanks - John

  • Posted 6 November 2019, 5:46 am EST

    Thanks Mohit

    The workaround works for time being.

    John

  • Posted 6 November 2019, 5:55 pm EST

    Hello John,

    There is some issue in XLVertTextAlign enum mapping. I have escalated the issue to the development team(404731). You can use the following code as a workaround:

    Dim XLBook As New C1XLBook
             Dim Sheet As C1.C1Excel.XLSheet = XLBook.Sheets(0)
    
             Dim styleBoldCentred As New XLStyle(XLBook)
             With styleBoldCentred
                  .AlignHorz = XLHorizTextAlign.Center
    
                  .AlignVert = XLVertTextAlign.Top
    
                  .ForeColor = Color.Blue
                  .SetBorderStyle(XLLineStyleEnum.Thin)
             End With
             With Sheet(0, 0)
                  .Value = "Text"
             End With
    
    

    Hope it helps.

    Thanks,

    Mohit

  • Posted 6 November 2019, 7:58 pm EST

    Hello,

    This is by- design. Please use the following line of code:

     Dim XLBook As New C1XLBook
              Dim Sheet As C1.C1Excel.XLSheet = XLBook.Sheets(0)
    
              Dim styleBoldCentred As New XLStyle(XLBook)
              With styleBoldCentred
                   .AlignHorz = [b]XLAlignHorzEnum.Center[/b]
    
                   .AlignVert = [b]XLAlignVertEnum.Center[/b]
    
                   .ForeColor = Color.Blue
                   .SetBorderStyle(XLLineStyleEnum.Thin)
              End With
    
              Dim Range As XLCellRange = New XLCellRange(0, 3, 0, 0)
              Sheet.MergedCells.Add(Range)
              Range.Style = styleBoldCentred
    
    
              With Sheet(0, 0)
                   .Value = "Text"
              End With
    
              XLBook.Save("test.xlsx")
    

    Thanks,

    Mohit

  • Posted 6 November 2019, 7:59 pm EST

    Use the XLAlignVertEnum instead XLVertTextAlign.

  • Posted 6 November 2019, 10:06 pm EST

    OK. All understood.

    Probably worthwhile amending the documentation to indicate that XLVertTextAlign refers to text in a single cell whereas XLAlignVertEnum refers to a range of cells.

    Thanks - John

  • Posted 7 November 2019, 6:20 pm EST

    Hello,

    Thanks for the feedback. I have forwarded your suggestion to the concerned team.

    Sorry for the inconvenience caused to you.

    Thanks,

    Mohit

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels