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

Free Support Forum - aspose.com

Text Autofit in range of cells in Aspose.Cells


I want to have autofit of texts in a range of cells(I am creating a range because i want to display some discalimer in the first row.).But i am not able to do so.Looks like the row height is fix and only on double click i can see the full text.

I have attached the sample excel sheet.

My code is like below:

Cells cells = sheet.Cells;

cells["A1"].PutValue(rx.Replace(HttpUtility.HtmlDecode(ltrTestDisclaimer.Text), "").Trim());

//Get Style Object

Aspose.Cells.Style style = cells["A1"].GetStyle();

style.IsTextWrapped = true;

style.VerticalAlignment = TextAlignmentType.Top;

Range rng = sheet.Cells.CreateRange("A1", "K1");




Can you please help me out.




Thanks for the sample file.

Well, I am afraid, in MS Excel, you cannot auto-fit a row whose cells are merged. You may confirm this behavior in MS Excel by selecting the first row in the sheet of your template file, now place the mouse cursor on the bottom line of row label “1” to get the “+” handle, now double click on it, you will see that nothing happens as the merged cells are not auto-fitted to display the full contents as wrapped text. Aspose.Cells follows MS Excel standards.

For your situation. Either you have to un-merge the cells in the first row and do the auto-fitting or extend the row height accordingly in your code. e.g

sheet.Cells.SetRowHeightPixel(0, 100);
This line works fine to display the contents fully.

Thanks for your understanding!