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

Free Support Forum - aspose.com

Resizing row height according to text size


I have some text in my excel file which is quite big enough to display properly in a cell even if the wrap text of that cell is kept to true. Can i resize my row height in excel file to accomodate that text ??

Thanx in advance


Thanks for considering Aspose.

Yes, you may use Worksheet.AutoFitRow and Worksheet.AutoFitColumn methods to adjust the row height and column width accordingly. You may also utilize Cells.SetRowHeight and Cells.SetColumnWidth methods to manually extend the rows / columns height and width.

Please consult the following code snippet.

Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets["Sheet1"];
Cells cell = ws.Cells;
cell[0, 0].PutValue("Voor meer informatie, nga naar");
cell[0, 0].Style.IsTextWrapped = true;
wb.Save("d:\\test\\fittext.xls", FileFormatType.Excel2003);

Thank you.


i am sorry. I am still not able to increase the rowsize to accomodate my text in a cell. I am attaching my downloaded excel file from my ASP.NET application. Please see the last tab named "Role Profiles". In that you will find some cells which have more text but didn't get displayed because of row not resizing appropriately.


For your info, If a cell is specified as merged cell, you cannot perform AutoFit -Row involving the cell. This functionality is similar to MS Excel. For confirmation, you may check the worksheet "Role Profiles" (in MS Excel) and try to perform Auto-Fit Row operation upon those rows involving cells. i.e., B26, C26, G26, H26, I26,B27, C27, G27, H27, I27,B34, C34, G34, H34, I34, .....................B75, C75, G75, H75, I75 etc. Right-Click these cells in MS Excel and Click Format Cells.... then, Click Alignment tab and you may see the cells are Merge Cells. I think you should unmerge those cells first (either using MS Excel or using Aspose.Cells APIs) and then perform AutoFit Row Operation.


Workbook wb = new Workbook();
Worksheet ws = wb.Worksheets["Role Profiles"];
Cells cells = ws.Cells;
cells["B75"].Style.IsTextWrapped = true;
cells["C75"].Style.IsTextWrapped = true;
wb.Save("d:\\test\\fit_text.xls", FileFormatType.Excel2003);

Thank you.

How is this functionality similar to Excel? in Excel 2003 I am able to auto-fit a row which has merged cells. When I attempt to do the same using Aspose.Cells v4.4.3.1 the row gets sized as though the cells were not merged. Please let me know if I am making some mistake. If not, is this a bug that will be fixed in a future version of Aspose.Cells?

Code snippet:

Cell itemQuestionCell = cells[row, itemQuestionColumn];
cells.Merge(row, itemQuestionColumn, 1, 3);
itemQuestionCell.Style = ItemQuestionStyle;



Well, Aspose.Cells works in the same way as MS Excel does. If your merged range comprises of multiple rows, the autofit row feature cannot be applied (you may check this in MS Excel). But, if you merge single row multi cols, autofit feature would work and Aspose.Cells also sets autofit row feature on such a range. To verify, I used the following code (I extend the height of the second row first. I merged some cells in a single row with 3 cols and then applied autofit row operation on it.):

Sample code:

Workbook book = new Workbook();
Worksheet sheet = book.Worksheets[0];
sheet.Cells[2, 2].PutValue("test1");
sheet.Cells[2, 3].PutValue("test2");
sheet.Cells[2, 4].PutValue("test3");
sheet.Cells.Merge(2, 2,1,3);

Attached is the output file.

If you have different results or ideas, kindly do post your template file with sample code to show it, we will check it soon.

Thank you.