Spread Windows Forms 17
Spread Windows Forms 17.0 Product Documentation / Developer's Guide / Rows and Columns / Setting the Row Height or Column Width
In This Topic
    Setting the Row Height or Column Width
    In This Topic

    You can set the row height or column width as a specified number of pixels. Each sheet uses and lets you set a default size, making all rows or columns in the sheet the same size. You can override that setting by setting the value for individual rows or columns.

    Example of Row Higher and Column Wider

    Users can change the row height or column width by dragging the header lines between rows or columns.

    For more details refer to the Column.Width method or Row.Height method. For more information, kindly refer to "Allowing the User to Resize Rows or Columns".

    Method to set

    Get a collection of rows and columns in the Rows and Columns property of the SheetView class, and specify the target row and column by index. The row height is set by the Height property of the Row class, and the column width is set by the Width property of the Column class.

    Example

    This example code sets the second column’s width to 100 pixels.

    C#
    Copy Code
    // Set second column width to 100.
    fpSpread1.Sheets[0].Columns[1].Width = 100;
    
    VB
    Copy Code
    ' Set second column width to 100.
    fpSpread1.Sheets(0).Columns(1).Width = 100
    

    Note: When the Column.Width or Row.Height methods are set to zero, the row height and column width are set to zero and they appear as hidden.

    You can also set the row height and column width to zero to hide the rows and columns by using RowHeight and ColumnWidth properties. However, in this case, the originally set row height or column width is retained when they are re-displayed. The below example code explains this scenario. You can also use the Axis model to change the width and height which is restored on being re-displayed.

    C#
    Copy Code
    GrapeCity.Spreadsheet.IWorksheet sheet1 = fpSpread1.AsWorkbook().ActiveSheet;
    sheet1.Rows[5].RowHeight = 50;  // Initial row height is set to 50
    sheet1.Rows[5].RowHeight = 0;   // The row is now hidden, the row height is still 50 internally
    sheet1.Rows[5].Hidden = false;  // The row is visible and the row height is 50
    sheet1.Rows[5].Hidden = true;   // The row height is still 50 internally
    fpSpread1.ActiveSheet.Models.RowAxis.SetSize(5, 100); // Use AxisModel to change row height
    sheet1.Rows[5].Hidden = false;  // The row height is 100
    
    VB
    Copy Code
    GrapeCity.Spreadsheet.IWorksheet sheet1 = fpSpread1.AsWorkbook().ActiveSheet
    sheet1.Rows(5).RowHeight = 50  'Initial row height is set to 50
    sheet1.Rows(5).RowHeight = 0   'The row is now hidden, the row height is still 50 internally
    sheet1.Rows(5).Hidden = false  'The row is visible and the row height is 50
    sheet1.Rows(5).Hidden = true   'The row height is still 50 internally
    fpSpread1.ActiveSheet.Models.RowAxis.SetSize(5, 100) 'Use AxisModel to change row height
    sheet1.Rows(5).Hidden = false  'The row height is 100
    

    Using the Properties Window

    1. At design time, in the Properties window, select the Spread component.
    2. Select the Sheets property.
    3. Click the button to display the SheetView Collection Editor.
    4. In the Members list, select the sheet for which to set the column width for a column.
    5. In the properties list, set the Columns property (or Row property) and then click the button to display the Cell, Column, and Row Editor.
    6. Click the column heading of the column for which you want to set the width (or row for the height).
    7. In the properties list, set the Width property (Height property for the row).
    8. Click OK to close the Cell, Column, and Row Editor.
    9. Click OK to close the SheetView Collection Editor.

    Using the Spread Designer

    1. To set the default column width,
      1. Select the sheet tab for the sheet for which you want to set the default column width.
      2. In the property list, in the Appearance category, select Columns to expand the list of properties for the columns.
      3. In the list of properties for columns, select Default to expand the list of default column settings.
      4. In the list of default settings, change the Width setting.
      5. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
    2. To set a specific column width,
      1. Select the column for which you want to change the width.
      2. In the properties list for that column, change the Width property.
      3. From the File menu choose Apply and Exit to apply your changes to the component and exit Spread Designer.
    See Also