GetPreferredCellSize not working with merge cell

Posted by: laggen on 8 September 2017, 3:24 pm EST

  • Posted 8 September 2017, 3:24 pm EST

    Dim value As Size
    value = .Sheets(0).GetPreferredCellSize(1, 1)

    My cell (1,1) are merge with cell(1,2)

    .Sheets(0).GetPreferredCellSize(1, 1) only check cell (1,1) and don't count with the merge cell(1,2)
  • Replied 8 September 2017, 3:24 pm EST

    Hi Gina

    Thanks for your answer.
    The problem with this ae that it's check all cells in this column, but I only want to check a specific cell.

    when text are not fit in a cell I let it overflow to next line, therefore I have different hight on rows to.

    look attached image.
  • Replied 8 September 2017, 3:24 pm EST

    Upload are not working .png not supported?
  • Replied 8 September 2017, 3:24 pm EST


    Try posting the image again. They had to fix an issue with the forum.

    Thanks, Gina
  • Replied 8 September 2017, 3:24 pm EST

    Here are the image

  • Replied 8 September 2017, 3:24 pm EST


    The GetPrerredCellSize method does not have a span option. You could try the GetPreferredColumnWidth method and see if that works for you. For example:

    float size;
    size = fpSpread1.ActiveSheet.GetPreferredColumnWidth(0, true, false, true);

    Thanks, Gina
  • Marked as Answer

    Replied 8 September 2017, 3:24 pm EST


    To calculate the preferred size of the span cell, you need to use the lower-level GetPreferredSize method implemented inside the IRenderer for the cell and pass the size of the span cell for the size argument. GetPreferredCellSize ignored span cells and always uses the actual cell size when computing the preferred cell size, but the IRenderer method will use the specified size to compute the preferred size. If the IRenderer wraps the text then GetPreferredSize will return the height required to show the wrapped text in the specified size.Width, otherwise it will return the width required to show the text in one line. To get the IRenderer for the cell, you can use Cell.Renderer.

Need extra support?

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

Learn More

Forum Channels