We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Spreadsheet Column widths are not updating in worksheets

I'm trying to take the column widths of one of the worksheets and apply it to all the other worksheets in a spreadsheet.    The values look as though they are set but the worksheets are not reflecting the change.   I'm not sure if there is anything I'm missing on getting the control to update the column widths that i'm missing.



        Dim Source = ManifestSpreadsheet1.Workbook.Worksheets(worksheetIndex)
        Dim maxcol = 10

        For i = 0 To 7
            If i <> worksheetIndex Then
                For icol = 1 To maxcol
                    ManifestSpreadsheet1.Workbook.Worksheets(i).SetColumnWidth(icol, Source.GetColumnWidth(icol))
                Next
            End If
        Next
        If ManifestSpreadsheet1 IsNot Nothing Then
            If ManifestSpreadsheet1.ActiveGrid IsNot Nothing Then
                ManifestSpreadsheet1.ActiveGrid.InvalidateCells()
            End If
            ManifestSpreadsheet1.Refresh()
        End If



3 Replies

Arulraj A January 23, 2019 05:20 AM UTC

Hi Spotty, 

Thanks for using Syncfusion product. 

To set the column width for all the sheets, you could use the SpreadSheet.SetColumnWidth method in WorkbookLoaded event. Please refer the following code example. 

VB 
AddHandler Me.spreadsheet.WorkbookLoaded, AddressOf Spreadsheet_WorkbookLoaded 
Private Sub Spreadsheet_WorkbookLoaded(ByVal sender As Object, ByVal args As Syncfusion.Windows.Forms.Spreadsheet.Helpers.WorkbookLoadedEventArgs) 
    Dim maxCol As Integer = 10 
    For j As Integer = 0 To Me.spreadsheet.Workbook.Worksheets.Count - 1 
        Dim grid = Me.spreadsheet.GridCollection(Me.spreadsheet.Workbook.Worksheets(j).Name) 
        grid.SetColumnWidth(1, maxCol, 150) 
    Next j 
End Sub 


Please get back to us if you require further assistance from us.  
Regards, 
Arulraj A 


SP Spotty January 23, 2019 04:24 PM UTC

Seems to work great.    

Can you give a bit of a summary on the difference between the Grids and Worksheets collections and when we should be using one as opposed to the other.
  

Arulraj A January 24, 2019 10:35 AM UTC

Hi Spotty, 

Thanks for your update. 

Worksheets collection is maintained by XlsIO source  and GridCollection is maintained by SpreadsheetGrid. If you want to make UI level changes in grid, you could use the Grid (Ex: Hide the rows/Columns, Change the Height/Width for Rows/Columns, (etc)). Please refer the following UG link, 

If you would like to make the change in excel file, you could use the worksheet. And this file changes will be reflected in grid when you invalidate the grid using  
InvalidateCell method. 

Please refer the following UG link, 

Please get back us if you need any further assistance on this. 
 
Regards, 
Arulraj A 

Loader.
Live Chat Icon For mobile
Up arrow icon