Resizing row height according to text size

Hi,

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

Hi,

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;
ws.AutoFitRow(0);
wb.Save("d:\\test\\fittext.xls", FileFormatType.Excel2003);

Thank you.

Hi,

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.

Hi,

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.

E.g.,

Workbook wb = new Workbook();
wb.Open("d:\\test\\RoleProfiles.xls");
Worksheet ws = wb.Worksheets["Role Profiles"];
Cells cells = ws.Cells;
cells["B75"].Style.IsTextWrapped = true;
cells.UnMerge(74,1,1,1);
cells["C75"].Style.IsTextWrapped = true;
cells.UnMerge(74,2,1,1);
ws.AutoFitRow(74);
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.PutValue(itemRow.item_question);
itemQuestionCell.Style = ItemQuestionStyle;

sheet.AutoFitRow(row);

Hi,

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.SetRowHeight(2,40);
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);
sheet.AutoFitRow(2);
book.Save("d:\\test\\mergefit.xls");

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.