Use new lines in cells on Excel Sheet Using JExcel APIs.

Use new lines in cells on Excel Sheet Using JExcel APIs.

Previous Home Next

 

In this section we will learns how to use new lines in cells on Excel Sheet Using JExcel APIs.

Here we will see how can we use or add a new line 
 The following code snippet will show you how can you add new line to your cells of the excel sheet contained in the current workbook.

WritableWorkbook workbook=Workbook.createWorkbook(new File("F:/JAVA PROJECTS/Jexcel/src/r4r/co/in/firstsheet.xls"));   // created a workbook
WritableSheet sheet=workbook.createSheet("mysheet", 0);              // created a sheet in the workbook
Label lblName=new Label(0,0,"\nNames");                          // created label using the new line character \n for creating the new line
Label lblFloatNum1=new Label(1,0,"\nFloatnum1");                 // crated second label by adding the new line character \n for creating new line in cell
sheet.addCell(lblName);                                        // added label to the sheet
WritableCellFormat.setWrap(true);
sheet.addCell(lblFloatNum1);                                   
                                  
workbook.write();
workbook.close();

It is also important to note that while using the new line character \n in the cell  make sure to turn on cell wrapping with WritableCellFormat.setWrap(true) or the newline will show up as a square (unknown character).


 

Previous Home Next