Working with JXL API
Working with
JXL API
Step 1: first we need
to import
Import jxl.*;
Imprt java.io.*;
Step 2: For reading
data, we need to create a workbook object.
Workbook wk =
Workbook.getWorkbook(new File(“D://frame.xls”));
// Workbook wk =
Workbook.getWorkbook(new File("D://Framework.xls"));
Step 3: Find Number of Sheets in a Workbook.
Int number_of_sheets;
Number_of_sheets = wk.getNumberOfShets();
System.out.println(“number of sheets” + Number_of_sheets);
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
number_of_sheets
= wk.getNumberOfSheets();
System.out.println("Number of Sheets
"+number_of_sheets);
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
Step 4 : Work on
sheets of the workbook
For this, every sheet in workbook having an index start from 0.
Step 5: First we need
to create object of that sheet.
Sheet s1 = wk.getSheet(0);
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
Sheet s1 = wk.getSheet(0);
‘’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’’
Step 6: Count Number
of rows and Columns
Int number_of_rows;
Int number_of_columns;
number_of_rows = s1.getRows();
number_of_columns =
s1.getColumns();
number_of_rows =
s1.getRows();
number_of_columns
= s1.getColumns();
System.out.println("Number
of Rows in First Sheet "+number_of_rows);
System.out.println("Number of Cols in First Sheet "+number_of_columns);
Step 7 Read Data from Sheet, for that first we need
to create object of the cell which we want to access and then we will get
content of the cell.
To create cell object use getCell() function.
To get data from cell use getContect() function.
Cell c1 =
s1.getCell(1, 1);
System.out.println("Data of the Cell
"+c1.getContents());
Subscribe to:
Post Comments
(
Atom
)
No comments :
Post a Comment