-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathExcelDataConfig.java
48 lines (35 loc) · 1.11 KB
/
ExcelDataConfig.java
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
package utilityPackage;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import org.apache.poi.ss.usermodel.DataFormatter;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRichTextString;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
public class ExcelDataConfig {
public static XSSFWorkbook wb;
public static XSSFSheet sheet;
public static String cellValue;
//Method to load/ initiate the workbook
public ExcelDataConfig(String excelPath)
{
try
{
FileInputStream fis = new FileInputStream(excelPath);
wb = new XSSFWorkbook(fis);
}
catch (Exception e)
{
System.out.println("Excel Exception" +e.getMessage());
}
}
//Method to read a value from a cell in the spreadsheet
public String getData(String sheetName, int rowNumber, int columnNumber)
{
sheet = wb.getSheet(sheetName);
DataFormatter formatter = new DataFormatter();
cellValue = formatter.formatCellValue(sheet.getRow(rowNumber).getCell(columnNumber));
return cellValue;
}
}