Arun Kumar Arun Kumar - 3 months ago 12
Java Question

I need to wrap the text in excel using java

I write some data in excel using java.I need to wrap the particular cell as wrap.can any tell me what is the syntax for wrap text and how can I use it?

Answer

In jxl, you have to use setWrap(true):

WritableCellFormat cellFormat = new WritableCellFormat();
cellFormat.setWrap(true);

sheet.addCell(new Label(1, 1, "A simple test message", cellFormat));    
sheet.addCell(new Label(1, 2, "An other text", cellFormat));

Edit:

To add a bold cell:

WritableFont cellFont = new WritableFont(WritableFont.COURIER, 16);
cellFont.setBoldStyle(WritableFont.BOLD);

WritableCellFormat cellFormatBold = new WritableCellFormat(cellFont);
sheet.addCell(new Label(1, 2, "An other text", cellFormatBold));