Access the sheets or use sheets

Access the sheets or use sheets

Previous Home Next

 

This tutorial will show you how to access the sheets or use sheets.

For accessing the sheets that are contained in a particular workbook, we have to use jxl.Sheet interface of the jxl package. It has the form,

public interface Sheet

It represents a sheet within a workbook. This interface provides a mechanism to handle the individual cells, or lines of cells that are grouped by a row or column.
 This Sheet interface various methods that are used to read the contents of a sheet, some of them are as follows,

Cell findCell(java.util.regex.Pattern pattern, int firstCol, int firstRow, int lastCol, int lastRow, boolean reverse)
This method gets the cell whose contents match the regular expression string that is passed.

Cell findCell(String contents)
This method gets the cell whose contents match the string passed as a parameter.
 
Cell findCell(String contents, int firstCol, int firstRow, int lastCol, int lastRow, boolean reverse)
This method gets the cell whose contents match the string passed in the method as a parameter.
 
LabelCell findLabelCell(String contents)
This method get the cell whose contents match the string passed in.
 
Cell getCell(int column, int row)
This method returns the cell specified by the columns and row arguments passed in the method.
 
Cell getCell(String loc)
It returns the cell for the specified location.

Cell[] getColumn(int col)
It gets all the cells on the specified column.

int[] getColumnPageBreaks()
It gives the accessor for the page breaks on current sheet.

int getColumns()
Returns the number of columns in this sheet.

CellView getColumnView(int col)
It gets the column width for the specified column.
 
Image getDrawing(int i)
It acts as an accessor for the image.
 
Hyperlink[] getHyperlinks()
This gets the hyperlinks on current sheet.

Range[] getMergedCells()
It gets the cells which have been merged on current sheet.
 
String getName()
This method gets the name of this sheet.

int getNumberOfImages()
It acts as accessor for the number of images on the sheet.
 
Cell[] getRow(int row)
This gets all the cells on the specified row.

int getRows()
This method returns the number of rows in this sheet.
 
CellView getRowView(int row)
 It gives the row height for the specified column passes as an argument in the method.
 
SheetSettings getSettings()
This method gets the settings used on a particular sheet.

For accessing a sheet contained in a particular workbook we can use the following steps,
File f1=new File("F:/JAVA PROJECTS/Jexcel/src/r4r/co/in/firstsheet.xls");
            WorkbookSettings ws=new WorkbookSettings();
            ws.setLocale(new Locale("er","ER"));
            Workbook workbook=Workbook.getWorkbook(f1,ws); //opening an existing workbook
           
           
           Sheet readsheet=workbook.getSheet(0);  //getting the sheet contained at 0th position at the workbook          System.out.println(readsheet.getName());    // getting the name of sheet contained in the workbook
           




 

Previous Home Next