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

SetWidth on multiple column ranges at once

4 Answers 49 Views
Spreadsheet
This is a migrated thread and some comments may be shown as answers.
Kendo Dude
Top achievements
Rank 2
Iron
Kendo Dude asked on 11 Mar 2020, 11:12 PM

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

Sort by
0
Aleksandar
Telerik team
answered on 13 Mar 2020, 04:08 PM

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

Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
0
Kendo Dude
Top achievements
Rank 2
Iron
answered on 13 Mar 2020, 04:52 PM

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);
}

 

 

0
Kendo Dude
Top achievements
Rank 2
Iron
answered on 13 Mar 2020, 05:12 PM

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));

 

 

 

 

 

0
Aleksandar
Telerik team
answered on 17 Mar 2020, 02:07 PM

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

Get quickly onboarded and successful with your Telerik UI for ASP.NET MVC with the dedicated Virtual Classroom technical training, available to all active customers.
Tags
Spreadsheet
Asked by
Kendo Dude
Top achievements
Rank 2
Iron
Answers by
Aleksandar
Telerik team
Kendo Dude
Top achievements
Rank 2
Iron
Share this question
or