Is there a way to SetWidth() on multiple column ranges at once? Kind of like below:
//get columns 0 to 2, 5 to 10 and 26 to 29 and set width
worksheet.Columns[0,2].Columns[5,10].Columns[26,29].SetWidth(
new
ColumnWidth(400,
true
));
4 Answers, 1 is accepted
Hello Karl,
When you set the configuration of the widgets using the Telerik UI for ASP.NET MVC server-side wrapper for the Spreadsheet you can set the width for each individual column:
.Columns(columns => { columns.Add().Width(100); columns.Add().Width(215); columns.Add().Width(115); columns.Add().Width(115); columns.Add().Width(115); columns.Add().Width(155); })
Alternatively, you could use Razor syntax to set the configuration of the columns:
.Columns(columns =>
{
{for (int i = 0; i < 5; i++)
{
columns.Add().Width(300);
}
}
})
Finally, you could also change the column width on the client-side using the sheet.columnwWdth() method as shown in this dojo:
var sheet = $("#spreadsheet").getKendoSpreadsheet().activeSheet();
var columns = [1,3,4,6];
columns.forEach(function(idx){
sheet.columnWidth(idx, 300);
})
I hope this helps. Let me know if you have other questions.
Regards,
Aleksandar
Progress Telerik
I was thinking more of getting a collection of column ranges and applying setWidth() one time. This also works.
List<ColumnSelection> ColumnSelectionList =
new
List<ColumnSelection>();
ColumnSelectionList.Add(worksheet.Columns[7, 8]);
ColumnSelectionList.Add(worksheet.Columns[25]);
ColumnSelectionList.Add(worksheet.Columns[28,29]);
foreach
(var columnSelection
in
ColumnSelectionList)
{
columnSelection.SetWidth(columnWidth);
}
Or
ColumnWidth columnWidth =
new
ColumnWidth(UnitHelper.ExcelColumnWidthToPixelWidth(workbook, 52.00),
true
);
List<ColumnSelection> ColumnSelectionList =
new
List<ColumnSelection>();
ColumnSelectionList.Add(ws.Columns[7, 8]);
ColumnSelectionList.Add(ws.Columns[25]);
ColumnSelectionList.Add(ws.Columns[28,29]);
ColumnSelectionList.ForEach(c => c.SetWidth(columnWidth));
Hi Karl,
Thank you for sharing these approaches for the benefit of the community. Indeed, when resizing the width of the columns on the server using the RadSpreadProcessing library, those are valid approaches.
Regards,
Aleksandar
Progress Telerik