SpreadsheetGear 2012
AutoFit Method (IRange)
Example 






Automatically sets the width of the specified columns or the height of the specified rows.
Syntax
'Declaration
 
Sub AutoFit() 
'Usage
 
Dim instance As IRange
 
instance.AutoFit()
void AutoFit()
procedure AutoFit(); 
function AutoFit();
void AutoFit(); 
void AutoFit(); 
Remarks
When IRange.AutoFit is used on columns, the width of the columns is set to the appropriate width immediately. However, for rows, the height is set to the default height and a flag is set indicating that the row height is automatic, and Excel will actually set the height when the row is displayed.
Example
// Automatically set the width on columns B and C.
worksheet.Cells["B:C"].Columns.AutoFit();
 
// Set the row height to automatic on rows 7 through 9.
worksheet.Cells["7:9"].Rows.AutoFit();
' Automatically set the width on columns B and C.
worksheet.Cells("B:C").Columns.AutoFit()
 
' Set the row height to automatic on rows 7 through 9.
worksheet.Cells("7:9").Rows.AutoFit()
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

IRange Interface
IRange Members
Rows Property
Columns Property
ColumnWidth Property
RowHeight Property

Send Feedback