tom
tom

Reputation: 5504

writing excel through JAVA using HSSF workBook

I am using HSSF work book to write data into excel using java, Now i have a column name with n-no of words, if i insert it normally its coming in a same line, i want to break the sentences into two different line and insert into same cell.

below is the code iam using to set the column

 rowhead.createCell((short) 0).setCellValue("Hi there it is my lengthy column please help");

Thanks, Tom

Upvotes: 1

Views: 641

Answers (1)

Benoit Wickramarachi
Benoit Wickramarachi

Reputation: 6216

You just need to use the Java new line '\n' char to break your sentence into 2 lines then set WrapText to true:

    Cell cell = rowhead.createCell((short) 0));
    cell.setCellValue("Hi there it is my lengthy \n column please help");
    CellStyle cs = wb.createCellStyle();
    cs.setWrapText(true);
    cell.setCellStyle(cs);

Upvotes: 2

Related Questions