forked from nbhat1/Selenium-JavaCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadExcel.java
More file actions
59 lines (42 loc) · 1.64 KB
/
Copy pathreadExcel.java
File metadata and controls
59 lines (42 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package main.java.excelReading;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import java.io.FileInputStream;
/**
* Created by neeraj.bhatnagar on 1/17/2017.
*/
public class readExcel {
public String path;
private XSSFWorkbook workbook;
private XSSFSheet sheet;
public readExcel(String path) throws Exception {
this.path= path;
FileInputStream fis = new FileInputStream(path);
workbook = new XSSFWorkbook(fis);
}
public void getCellData() {
sheet = workbook.getSheet("userData");
System.out.println(sheet.getRow(1).getCell(0).getStringCellValue());
}
public int getRowCount(){
int sheetTopRow = sheet.getFirstRowNum();
int sheetBottomRow = sheet.getLastRowNum();
int totalrow = sheetBottomRow - sheetTopRow;
System.out.println("Number of rows are " + " " + (totalrow+1));
System.out.println("Row count from getPhysical number of row method." + " " +sheet.getPhysicalNumberOfRows());
System.out.println("Row count from last row method."+ " " +sheet.getLastRowNum());
return totalrow;
}
public int getColCount(){
int totalColumn = sheet.getRow(1).getLastCellNum();
System.out.println("Total Number of Columns are " + " " + totalColumn);
return totalColumn;
}
public static void main(String[] args) throws Exception {
String path = System.getProperty("user.dir")+"\\testdata\\testData.xlsx";
readExcel obj = new readExcel(path);
obj.getCellData();
obj.getRowCount();
obj.getColCount();
}
}