However, such method is missing from Spread WPF. Although we can resize the column to fit the longest string of text in the column by double clicking the right edge of the column header but how do we resize the column when Spread's CanUserResize property is set to false.
Still wondering how??
Let's see how we can do that with simple piece of code :)
After populating the Spread WPF control, we need to set the size of the columns to fit the maximum width of the text using the following code:-
double cellWidth = 0.0F;
for (int r = 0; r < Spread.ActiveSheet.Rows.Count; r++)
for (int c = 0; c < Spread.ActiveSheet.Columns.Count; c++)
var formattedText = new FormattedText(Spread.Sheets.Cells[r, c].Text, CultureInfo.CurrentUICulture,
FlowDirection.LeftToRight, new Typeface("Arial"), FontSize = 14, System.Windows.Media.Brushes.Black);
if (cellWidth < formattedText.Width)
cellWidth = formattedText.Width;
Spread.ActiveSheet.Columns[c].Width = cellWidth;
So this small code snippet completes the implementation process.
To see it in action, you may download the sample with the complete implementation from below mentioned link.