Spread Windows Forms 9.0 Product Documentation
Resizing the Row or Column to Fit the Data

You can resize the column width or row height based on the length or breadth of data in the cells in that column or row. The size of the row or column with the largest data is referred to as the preferred size.

The methods that make use of the preferred size are:

The Row class GetPreferredHeight method and Column class GetPreferredWidth method always include the header cells. The SheetView class overloaded GetPreferredColumnWidth method has one overload that always includes the header cells while another overload allows you to choose whether to include or exclude header cells. In the following code, width1 and width2 include the header cells but width3 excludes the header cells.

float width1 = fpspread.Sheets[0].Columns[0].GetPreferredWidth();

float width2 = fpspread.Sheets[0].GetPreferredColumnWidth(0);

float width3 = fpspread.Sheets[0].GetPreferredColumnWidth(0, true);

For information on setting the cell size based on the size of the data, refer to Resizing a Cell to Fit the Data.

For information on allowing the user to resize the data, refer to Allowing the User to Resize Rows or Columns.

Using Code

Use the listed methods to set the width and height of columns or rows.

Example

This example sets the row height and column width.

C#
Copy Code
FarPoint.Win.Spread.Row row;
FarPoint.Win.Spread.Column col;
float sizerow;
float sizercol;
row = fpSpread1.ActiveSheet.Rows[0];
col = fpSpread1.ActiveSheet.Columns[0];
fpSpread1.ActiveSheet.Cells[0, 0].Text = "This text is used to determine the height and width.";
sizerow = row.GetPreferredHeight();
sizecol = col.GetPreferredWidth();
row.Height = sizerow;
col.Width = sizecol;
VB
Copy Code
Dim row As FarPoint.Win.Spread.Row
Dim col As FarPoint.Win.Spread.Column
Dim sizerow As Single
Dim sizecol As Single
row = FpSpread1.ActiveSheet.Rows(0)
col = FpSpread1.ActiveSheet.Columns(0)
FpSpread1.ActiveSheet.Cells(0, 0).Text = "This text is used to determine the height and width."
sizerow = row.GetPreferredHeight()
sizecol = col.GetPreferredWidth()
row.Height = sizerow
col.Width = sizecol

 

 


Copyright © GrapeCity, inc. All rights reserved.

Support Options | Documentation Feedback