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

Free Support Forum - aspose.com

How to set cell line wrap?

How to set cell line wrap?
we use Java!

@landray.com.cn

Thanks for considering Aspose APIs.

You will have to set the style of the cell and for style, you will have to set text wrapped property to true. Please see the following sample code, its output Excel file and screenshot for your reference.

Download Link:
Output Excel File.zip (5.6 KB)

Java

Workbook wb = new Workbook();

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

Cell cell = ws.getCells().get("B4");
cell.putValue("This is first line.\nThis is second line.");

//Wrap the text in cell
Style st = cell.getStyle();
st.setTextWrapped(true);
cell.setStyle(st);

//Set the width of the 2nd column
ws.getCells().setColumnWidth(1, 20);

wb.save(dirPath + "output.xlsx");

Screenshot: