Worksheet.AutoFitRow

AutoFitRow(int, int, int, int)

Autofits row height in a rectangle range.

public void AutoFitRow(int startRow, int endRow, int startColumn, int endColumn)
ParameterTypeDescription
startRowInt32Start row index.
endRowInt32End row index.
startColumnInt32Start column index.
endColumnInt32End column index.

See Also


AutoFitRow(int)

Autofits the row height.

public void AutoFitRow(int rowIndex)
ParameterTypeDescription
rowIndexInt32Row index.

Remarks

AutoFitRow is an imprecise function.

Examples

// Called: w1.Worksheets[0].AutoFitRow(0);
public void Worksheet_Method_AutoFitRow()
{
    Workbook w1 = new Workbook();
   Assert.AreEqual(12.75,w1.Worksheets[0].Cells.StandardHeight);
    Style style = w1.Worksheets[0].Cells["A1"].GetStyle();
    style.IsTextWrapped = (true);
    w1.Worksheets[0].Cells["A1"].SetStyle(style);
    w1.Worksheets[0].Cells["A1"].Value = ("LOOOOOOOOOOOOOOOOOONG TEEEEEEEEEEXT");
    w1.Worksheets[0].Cells["A2"].Value = ("SOME OTHER LOOOOOOOOOOOOOOOOOONG TEEEEEEEEEEXT");
    w1.Worksheets[0].AutoFitRow(0);
    Assert.AreEqual(12.75, w1.Worksheets[0].Cells.StandardHeight);
}

See Also


AutoFitRow(int, int, int)

Autofits the row height.

public void AutoFitRow(int rowIndex, int firstColumn, int lastColumn)
ParameterTypeDescription
rowIndexInt32Row index.
firstColumnInt32First column index.
lastColumnInt32Last column index.

Remarks

This method autofits a row based on content in a range of cells within the row.

Examples

// Called: wb.Worksheets[0].AutoFitRow(2, 8, 8);
public void Worksheet_Method_AutoFitRow()
{
    Workbook wb = new Workbook(Constants.sourcePath + "example.xlsx");
    Assert.AreEqual(299, wb.Worksheets[0].Cells.GetColumnWidthPixel(8));
    wb.Worksheets[0].AutoFitRow(2, 8, 8);
    Assert.AreEqual(112.5, wb.Worksheets[0].Cells.GetRowHeight(2));
}

See Also


AutoFitRow(int, int, int, AutoFitterOptions)

Autofits the row height.

public void AutoFitRow(int rowIndex, int firstColumn, int lastColumn, AutoFitterOptions options)
ParameterTypeDescription
rowIndexInt32Row index.
firstColumnInt32First column index.
lastColumnInt32Last column index.
optionsAutoFitterOptionsThe auto fitter options

Remarks

This method autofits a row based on content in a range of cells within the row.

Examples

// Called: sourceWorkbook.Worksheets[0].AutoFitRow(0, 0, 16383, oAutoFitterOptions);
public void Worksheet_Method_AutoFitRow()
{
    Workbook sourceWorkbook = new Workbook(Constants.sourcePath +  "example.xlsx");
    AutoFitterOptions oAutoFitterOptions = new AutoFitterOptions { AutoFitMergedCells = true, IgnoreHidden = true, OnlyAuto = false };
    double Height = sourceWorkbook.Worksheets[0].Cells.CreateRange("1:1").RowHeight;
    sourceWorkbook.Worksheets[0].AutoFitRow(0, 0, 16383, oAutoFitterOptions);
    Height = sourceWorkbook.Worksheets[0].Cells.CreateRange("1:1").RowHeight;
    Assert.AreEqual(Height, 15.75);
}

See Also