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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Spreadsheet Column widths are not updating in worksheets

Thread ID:

Created:

Updated:

Platform:

Replies:

142166 Jan 22,2019 05:37 PM UTC Jan 24,2019 10:35 AM UTC WinForms 3
loading
Tags: Spreadsheet
Spotty
Asked On January 22, 2019 05:37 PM UTC

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



Arulraj A [Syncfusion]
Replied On 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 


Spotty
Replied On 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 [Syncfusion]
Replied On 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 


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon