AutoFitRow

Hello,

I am having a problem with the AutoFitRow() method. When I open the created Excel file, the rows are not auto-fit. I am using version 2.4.0.0. Here is my code:

Dim i, j As Integer

For i = 0 To x

ws.AutoFitRow(i)

For j = 0 To CELL_COUNT

ws.Cells(i, j).Style.IsTextWrapped = True

Next

Next

Please advice, Thanks!
C.

Hi,

Please set IsTextWrapped to true before you call AutoFitRow method.

Dim i, j As Integer

For i = 0 To x

For j = 0 To CELL_COUNT

ws.Cells(i, j).Style.IsTextWrapped = True

Next

ws.AutoFitRow(i)


Next

@clchris,
Aspose.Excel is no more available now and is not under active development now. It is replaced with a new product Aspose.Cells which contains all the features of its predecessor along with the support of the latest features in different versions of MS Excel. Following example demonstrates the AutoFitRow function:

// For complete examples and data files, please go to https://github.com/aspose-cells/Aspose.Cells-for-.NET
// The path to the documents directory.
string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

string InputPath = dataDir + "Book1.xlsx";

// Creating a file stream containing the Excel file to be opened
FileStream fstream = new FileStream(InputPath, FileMode.Open);

// Opening the Excel file through the file stream
Workbook workbook = new Workbook(fstream);

// Accessing the first worksheet in the Excel file
Worksheet worksheet = workbook.Worksheets[0];

// Auto-fitting the 3rd row of the worksheet
worksheet.AutoFitRow(1);

// Saving the modified Excel file
workbook.Save(dataDir  + "output.xlsx");

// Closing the file stream to free all resources
fstream.Close();

Here is a detailed article which provides description and examples of auto fitting the rows, columns, ranges and merged cells:
AutoFit Rows and Columns

Latest trial version is available here:
Aspose.Cells for .NET (Latest Version)

Here is a complete solution which can be executed to test different features of Aspose.Cells.