Auto Fit Column Widths

2 posts, 1 answers
  1. Carl Herlitz
    Carl Herlitz avatar
    7 posts
    Member since:
    Jun 2010

    Posted 21 Oct Link to this post

    Is there a way to set column widths to auto fit? I see that RadSpreadProcessing has ColumnSelection.AutoFitWidth(). Is there any way to get that functionality with IColumnExporter? All I see is SetWidthInPixels() and SetWidthInCharacters(), but I can't get either of those values when creating the spreadsheet.

    If not, are there any plans for this functionality?

  2. Answer
    Nikolay Demirev
    Admin
    Nikolay Demirev avatar
    103 posts

    Posted 26 Oct Link to this post

    Hello Carl,

    There is no AutoFitWidth feature in RadSpreadStreamProcessing, and it is not possible to be implemented.

    While exporting cell values, no data is preserved in the model about the cells. Everything is written directly to the XLSX file. In order to be able to AutoFit the columns, the library should know the width of the widest cell in the column just before creating any rows. This is not possible because of the required order of export  which is forced by the specifics of the XLSX format. The columns should be exported before the cell values.

    The only way to AutoFit the columns is to measure the width of the widest cell before exporting your data. As the default measurement unit of the column width in excel is character count, it might be enough just to count the characters of all cell values in a column and set the width in characters for that column.

    Please bear in mind that the width of one character is equal to the maximum width of the digits from 0 to 9 measured with the font properties of the Normal style. Because this is not exact measurement the results may vary. Also, if you set the font size, font family, bold, italic or some other property that might change the width of the characters, this will not alter the meaning of one character width and the cell value will not fit the cell.

    Hope this is helpful.

    Regards,
    Nikolay Demirev
    Telerik by Progress

Back to Top