How to wrap text in a cell

Hi,

I want to fit the data in a particular cell that means I want to wrap text in a cell.

For example . My cell size is 40 and my data length exceeds 40. The data should be wrapped into that cell.

I am using

style.setTextWrapped(true);

But it is not working . Please help on that.

Hi Kishore,


Thank you for contacting Aspose support.

There could be a difference in how you are trying to achieve your goal, therefore please review the below provided code snippet & attached output file for your reference.

Java

Workbook book = new Workbook();
Worksheet sheet = book.getWorksheets().get(0);

Cell A1 = sheet.getCells().get(“A1”);
A1.putValue(“This is a very very long text”);

int styleIndex = book.getStyles().add();
Style style = book.getStyles().get(styleIndex);
style.setTextWrapped(true);

StyleFlag flag = new StyleFlag();
flag.setWrapText(true);

A1.setStyle(style, flag);

book.save(myDir + “output.xlsx”);

Please feel free to write back in case you face any difficulty.

Hi,

I tried with above code but it is not working for me . Please suggest me any other alternative.

Thanks in advance.

Hi Kishore,


We have tested again with the previously provided code snippet while using the latest version of Aspose.Cells for Java (Latest Version). The code works perfectly with latest version, therefore if you are not getting the results as shown in the output spreadsheet (shared in the previous post) then there could be a bug in your current version of the API. In such case, we would strongly recommend you to upgrade the API to the latest version.

Moreover, there is no alternative if you wish to apply the wrapped text on a cell. However, you may alternatively call the autoFitColumns method to enlarge the column widths.

In case the problem persists with latest version, please provide you complete code as well the template spreadsheet (if any) for our review.