We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problems with ws.AutoFitRow()


i’m using the latest hotfix of aspose.excel and could not get the AutoFitRow() function to work properly (AutoFitColumn works perfectly).

i’m trying to fill cells with a fixed width (using “ws.Cells.SetColumnWidth(x,60)”)
with wrapped text (assigning “mystyle.IsWrappedText = true”)
and giving it the correct height with ws.AutoFitRow(x)
but it does not work - the text ist wrapped correctly but i can see only the first line in excel (rows are all only one line high)

did anyone experience similar problems? plz help.

just experienced a funny thing: if i remove
mystyle.VerticalAlignment = TextAlignmentType.Top;
mystyle.HorizontalAlignment = TextAlignmentType.Left;
from the style definition only the last line of the wrapped text is shown in excel.

Hi, thanks for your consideration.

I had not thought of wrapped text. I will fix this bug as soon as possible.

thnx a lot. :slight_smile:

Hi, the bug is fixed. Please go to dowload page to download release 1.6.

We have enhanced this feature and with latest version of Aspose.Cells now it is possible to autofit rows even for cells that have been merged using the AutoFitterOptions API. AutoFitterOptions class provides AutoFitMergedCellsType property that can be used to autofit rows for merged cells. AutoFitMergedCellsType accepts AutoFitMergedCellsType enumerable which has the following members.

  • None: Ignore merged cells.
  • FirstLine: Only expands the height of the first row.
  • LastLine: Only expands the height of the last row.
  • EachLine: Only expands the height of each row.

Give a try to the following sample code to test these latest features:

// Instantiate a new Workbook
Workbook wb = new Workbook();

// Get the first (default) worksheet
Worksheet _worksheet = wb.Worksheets[0];

// Create a range A1:B1
Range range = _worksheet.Cells.CreateRange(0, 0, 1, 2);

// Merge the cells

// Insert value to the merged cell A1
_worksheet.Cells[0, 0].Value = "A quick brown fox jumps over the lazy dog. A quick brown fox jumps over the lazy dog....end";

// Create a style object
Aspose.Cells.Style style = _worksheet.Cells[0, 0].GetStyle();

// Set wrapping text on
style.IsTextWrapped = true;

// Apply the style to the cell
_worksheet.Cells[0, 0].SetStyle(style);

// Create an object for AutoFitterOptions
AutoFitterOptions options = new AutoFitterOptions();

// Set auto-fit for merged cells
options.AutoFitMergedCellsType = AutoFitMergedCellsType.EachLine;

// Autofit rows in the sheet(including the merged cells)

// Save the Excel file
wb.Save(outputDir + "AutofitRowsforMergedCells.xlsx");

For more details have a look at the following article:
AutoFit Rows and Columns

Download the latest version of Aspose.Cells for .NET from the following link:
Aspose.Cells for .NET (Latest Version)

You can download the latest demos here.