AutoFit a Range

Posted by: aruiz on 18 February 2022, 3:20 am EST

  • Posted 18 February 2022, 3:20 am EST - Updated 30 September 2022, 4:14 am EST

    I’m working with a Fspread Item but I were unable to set the width of a column based on a range of the cells.

    On that column got a cell that contains a long text But i do not want the column to get the width of that cell since on an other rows I got a text that context a normal size text and I want the column to resize to those row text and not to the one with the long text. Example:

    I got this:

    And I want to give it the range that Auto Fit the cells in the range of StartRow=3, StartColum = 1, EndRow = 7, EndColumn = 2,

    So it looks like this:

    But when I use:

    fpSpread1.AcrtiveSheet.Columns[1].Width = fpSpread.ActiveSheet.Columns[1].GetPreferredWidth();

    pSpread1.AcrtiveSheet.Columns[2].Width = fpSpread.ActiveSheet.Columns[2].GetPreferredWidth();

    This Happens where it takes in to account the cell 1,1 like this:

    Is there any solution to this? That doesn’t involve doing this:

    Since for big sheets it down crease the performance a lot by doing GetPreferredCellSize for each cell in the range.

  • Posted 18 February 2022, 3:26 am EST

    I have tried this:

    
    IWorkbook workbook = fpSpread1.AsWorkbook();
    workbook.ActiveSheet.Range(new Reference(3, 1, 7, 2)).AutoFit();
    
    

    But didn’t work either.

  • Posted 20 February 2022, 6:08 pm EST

    Hi,

    Please continue the thread on the same support case [CAS-29165-M4F1C7]. We have responded to the case there.

    Regards

    Avnish

Need extra support?

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

Learn More

Forum Channels