Free Support Forum -

Automatic column width/row height calculations

Is there a way(probably an algorithm, or a feature given by Aspose.cells implementing the algorithm) through which we can adjust the column widths/row heights depending upon the contents in the cells, so that it looks more pleasing to the eyes?
I know there are autofit column widths and autofit row heights options but they just max out the column widths or row heights. Fox ex : in cases where a cell contains a paragraph, the column width becomes very huge if the autofit column is on(it takes the full length of the paragraph) and the user has to scroll horizontally alot to read the content.

Akash Srivastava

Thanks for your query.
I am afraid that there is no direct mechanism to make row/height pleasing to eyes. However you may please use following sample code to change the column width and set wraptext to true.

Workbook wb = new Workbook(path + "Book1.xlsx");
Worksheet _worksheet = wb.Worksheets[0];

// Create a Style object using CellsFactory class
CellsFactory cf = new CellsFactory();
Aspose.Cells.Style st = cf.CreateStyle();
st.IsTextWrapped = true;
_worksheet.Cells.Columns[1].ApplyStyle(st, new StyleFlag() { WrapText = true });
_worksheet.Cells.Columns[1].Width = 10;
wb.Save(path + "output.xlsx");

If you find some mechanism using Excel, please share the steps with us. We will try to implement the same if currently not available.