This is a migrated thread and some comments may be shown as answers.

Auto Fit Column Widths

1 Answer 869 Views
SpreadStreamProcessing
This is a migrated thread and some comments may be shown as answers.
Carl Herlitz
Top achievements
Rank 1
Carl Herlitz asked on 21 Oct 2016, 03:15 PM

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?

1 Answer, 1 is accepted

Sort by
0
Accepted
Nikolay Demirev
Telerik team
answered on 26 Oct 2016, 09:22 AM
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

Tags
SpreadStreamProcessing
Asked by
Carl Herlitz
Top achievements
Rank 1
Answers by
Nikolay Demirev
Telerik team
Share this question
or