Merging cells on Excel Sheet Using JExcel APIs.
Previous | Home | Next |
In this tutorial we will see how to Merge cells on Excel Sheet Using JExcel APIs.
Here, we will see how can we merge the cells in an excel worksheet using the JExcel API. For merging cells in sheet we have to use the jxl.write.WritableWorkbook class to create a class and jxl.write.WritableSheet class to create a sheet, then we can add different components to the sheet .
For merging the cells in the sheet of a certain workbook, we will use the method mergeCells() method on the sheet of the workbook. This following code snippet will show you how to do the same,
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,"Names"); // created label
Label lblFloatNum1=new Label(1,0,"Floatnum1"); // crated second label
sheet.addCell(lblName); // added label to the sheet
sheet.addCell(lblFloatNum1);
sheet.mergeCells(0,0,1,0); // merged the two cell that's created to a single cell
workbook.write();
workbook.close();
Previous | Home | Next |