Articles in this section
Category / Section

How to fit columns which are inserted at runtime in WinRT Spreadsheet?

1 min read

User can fit the column based on its content, which are inserted at runtime in SfSpreadsheet by calling AutofitColumns method for the inserted range and setting the column width using SetColumnWidth function of SpreadsheetGrid and then refresh the UI using InvalidateCell method like below code example

C#

/For inserting columns,
spreadsheet.ActiveSheet.InsertColumn( 2, 1, ExcelInsertOptions.FormatAsAfter);
spreadsheet.ActiveGrid.Model.InsertColumns(2, 1);
 
//For setting cell value,
var range = spreadsheet.ActiveSheet.Range[2, 2];
spreadsheet.ActiveGrid.SetCellValue(range, "This is a sample using Autofit");
 
//For Auto fit that particular column(2),
spreadsheet.ActiveSheet["B1:B100"].AutofitColumns();
var width = spreadsheet.ActiveSheet.GetColumnWidthInPixels(2);
spreadsheet.ActiveGrid.SetColumnWidth(2,2,width); 
 
//For refreshing the view   
spreadsheet.ActiveGrid.InvalidateCell(GridRangeInfo.Col(2));
 

 

For more reference, please find the sample link below,

 

WPF

UWP

WINRT

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment
Access denied
Access denied