Data change does not apply new row height

Hi,


MS Excel works as follows:

  1. User set “Wrap text” format for cell A1
  2. User set the following text in cell A1: “this is a\ntest”
  3. Next press ENTER
  4. MS Excel automatically fit row height to fit content

Run the following code:

@Test

public void autoHeight() throws Exception {

Workbook wb = new Workbook();

Worksheet worksheet = wb.getWorksheets().get(0);

Cells cells = worksheet.getCells();


StyleFlag styleFlag = new StyleFlag();

styleFlag.setWrapText(true);


Style style = cells.getRows().get(0).getStyle();

style.setTextWrapped(true);


cells.getRows().get(0).applyStyle(style, styleFlag);


System.out.println("0. " + cells.getRowHeight(0));

cells.get(0, 0).putValue("This is a" +

"\nautoHeight" +

"\ntest");


System.out.println("0. " + cells.getRowHeight(0));

wb.save("D:\\out.xlsx");

}


Output looks as follows:

0. 12.75

0. 12.75


However when you open out.xlsx in MS Excel the row 0 will have correct height 51.


You provided the following code to fit row:

AutoFitterOptions options = new AutoFitterOptions();

options.setOnlyAuto(true);

worksheet.autoFitRow(0, 0, cells.getMaxColumn(), options);


Could you clarify please is there any option in Aspose to make data change (putValue) with automatic fit as in MS Excel (without additional call worksheet.autoFitRow)?


Thanks.

Hi,


Well, I am afraid, if you got to get row height for certain row(s) at runtime after setting wrap text on for the cells dynamically, you have to call autoFitRow() method first, there is no other alternative for it.

Thank you.

Hi,


Thanks for reply.

MS Excel automatically fits row height on data change to fit the content.

Is there any method in Aspose to get info that row has autofit mode?

Thanks.

Hi,


I am afraid, there is no such API in Aspose.Cells to get to know the auto-fit mode for certain cells.

Thank you.

Hi,


Is there any info in Open XML Spreadsheet format related to row autofit mode to implement this feature in Aspose?

Thanks.

Hi,


Could you try to use Row.setHeightMatched(boolean value) and Row.isHeightMatched() to enable/get the auto-fit mode in MS Excel if it fits your requirements.

Moreover, if you do not want to use auto-fit APIs of Aspose.Cells, instead you want to calculate the row height by yourself, we think Row.IsRowHeightMatched is the right one for your needs before checking whether one row’s height should be calculated manually.

Thank you.