Set a sheet as selected on Excel Sheet Using JExcel APIs.
Previous | Home | Next |
Now we will see how can we set a sheet as selected on Excel Sheet Using JExcel APIs.
For setting a sheet as selected usng jexcel first of all we have import the jxl.SheetSettings class. This class has the following two constructors that are mainly used,
SheetSettings(Sheet s)
This is the default constructor.
SheetSettings(SheetSettings copy, Sheet s)
This is the Copy constructor and is used in copying sheets.
For setting a sheet as selected we have to use the setSelected() method contained in the jxl.SheetSettings class. The following code snippet will show how can you use this method.
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
Label lblName=new Label(0,0,"Names"); // created different labels
Label lblFloatNum1=new Label(1,0,"Floatnum1");
Label lblFloatNum2=new Label(2,0,"Floatnum2");
Label lblFormula=new Label(3,0,"Formulas");
sheet.addCell(lblName); // adding labels to the cell
sheet.addCell(lblFloatNum1);
sheet.addCell(lblFloatNum2);
sheet.addCell(lblFormula);
sheet.getSettings().setSelected(true); // we have set selected the current sheet as true
workbook.write();
workbook.close();
Previous | Home | Next |