Hi,
MS Excel works as follows:
- User set “Wrap text” format for cell A1
- User set the following text in cell A1: “this is a\ntest”
- Next press ENTER
- 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.