How call variable from another class which is array? - java

I use Selenium Web Driver in Eclipse with IUnit. I have code which read data from excel file. Every column is presented as array. This is code:
class ReadExcel {
ArrayList path_name = new ArrayList();
ArrayList field_key = new ArrayList();
ArrayList field_name = new ArrayList();
ArrayList window_new = new ArrayList();
ArrayList link = new ArrayList();
lov_name = new ArrayList();
public void mai() {
int i = 0;
String path_namel = "", field_keyl = "", field_namel = "", window_newl = "", linkl = "", lov_namel = "";
String filename = "E:/data.xls";
if (filename != null && !filename.equals("")) {
FileInputStream fs = new FileInputStream(filename);
HSSFWorkbook wb = new HSSFWorkbook(fs);
for (int k = 0; k < wb.getNumberOfSheets(); k++) {
int j = i + 1;
HSSFSheet sheet = wb.getSheetAt(k);
int rows = sheet.getPhysicalNumberOfRows();
for (int r = 1; r < rows; r++) {
HSSFRow row = sheet.getRow(r);
int cells = row.getPhysicalNumberOfCells();
HSSFCell cell1 = row.getCell(0);
path_namel = cell1.getStringCellValue();
HSSFCell cell2 = row.getCell(1);
field_keyl = cell2.getStringCellValue();
HSSFCell cell3 = row.getCell(2);
field_namel = cell3.getStringCellValue();
HSSFCell cell4 = row.getCell(3);
window_newl = cell4.getStringCellValue();
HSSFCell cell5 = row.getCell(4);
linkl = cell5.getStringCellValue();
HSSFCell cell6 = row.getCell(5);
lov_namel = cell6.getStringCellValue();
path_name.add(path_namel);
field_key.add(field_keyl);
field_name.add(linkl);
window_new.add(window_newl);
link.add(linkl);
lov_name.add(lov_namel);
}
i++;
}
}
}
}
In my selenium test I have such cycle:
for (int i=0; i<path_name.length; i++){
driver.findElement(By.xpath(path_name[i])).click();
}
Here I use variable path_name which is array and must be equal path_name from class ReadExcel. Actually I want use this values from excel as array. How should I call variable from ReadExcel?
Edit
I try use getter and setter methods.
int q;
String g;
public String getG() {
return g;}
public void setG(String g) {
this.g = g;}
public int getQ() {
return q;}
public void setQ(int q) {
this.q = q;}
q=path_name.size();
g=path_name.get(i).toString();
I my test I call variables in such way
ReadExcel h = new ReadExcel();
String k= h.getG();
ReadExcel p = new ReadExcel();
int n= p.getQ();
for (int j=0; j<n; j++){
driver.findElement(By.xpath(k)).click();}
Have no errors in editor, but cycle do not work. It should click on links (k), but have no effect.
Also I try this (was suggested in first answer)
ReadExcel readExcel = new ReadExcel();
ArrayList<String> path_name = readExcel.getPath_name();
for(String pathName: path_name){
driver.findElement(By.xpath(pathName)).click();
}
The same effect. It does not click on links

Can you convert your variable into field of that class? And then add a method there to return value of that field to anyone interested.

One way would be to implement setter() and getter() methods in your ReadExcel class for the variables that you want to access. And they would obviously be public methods.
Edit:
Guessing from what you've tried to update and my understanding, you're doing a lot of things wrong. Assuming that you're calling your last piece of code from another class, here's what you really should have done:
Also, I'm assuming that you've modified your ReadExcel class to look something like this
public class ReadExcel {
ArrayList<String> pathName = new ArrayList<String>();
ArrayList<String> fieldKey = new ArrayList<String>();
ArrayList<String> fieldName = new ArrayList<String>();
ArrayList<String> windowNew = new ArrayList<String>();
ArrayList<String> link = new ArrayList<String>();
public ReadExcel() {
pathName = new ArrayList<String>();
fieldKey = new ArrayList<String>();
fieldName = new ArrayList<String>();
windowNew = new ArrayList<String>();
link = new ArrayList<String>();
}
/**
* Not so sure of this method name. But make sure that this method is called before
* you try to call getXX() methods
*/
public void mai() {
String filename = "E:/data.xls";
if(fileName == null || "".equals(fileName))
return;
HSSFWorkbook workBook = null;
FileInputStream fileInputStream = null;
HSSFSheet sheet;
HSSFRow row;
int rows;
try{
fileInputStream = new FileInputStream(new File(fileName));
workBook = new HSSFWorkbook(fileInputStream);
for(int sheetIndex = 0; sheetIndex < workBook.getNumberOfSheets(); sheetIndex++){
sheet = workBook.getSheetAt(sheetIndex);
rows = sheet.getPhysicalNumberOfRows();
for(int rowIndex = 0; rowIndex < rows; rowIndex++){
/**
* Update with your own logic for retrieval
*/
row = sheet.getRow(rowIndex);
if(row.getPhysicalNumberOfCells() < 6)
continue;
pathName.add(row.getCell(0).getStringCellValue());
fieldKey.add(row.getCell(0).getStringCellValue());
fieldName.add(row.getCell(0).getStringCellValue());
windowNew.add(row.getCell(0).getStringCellValue());
link.add(row.getCell(0).getStringCellValue());
}
}
} catch (FileNotFoundException fileNotFoundException) {
fileNotFoundException.printStackTrace();
} catch (IOException ioException) {
ioException.printStackTrace();
}finally{
if(fileInputStream != null){
try {
fileInputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
workBook = null;
}
}
}
/**
* The getter/setter methods for the variables
*/
public ArrayList<String> getPathName() {
return pathName;
}
public void setPathName(ArrayList<String> pathName) {
this.pathName = pathName;
}
public ArrayList<String> getFieldKey() {
return fieldKey;
}
public void setFieldKey(ArrayList<String> fieldKey) {
this.fieldKey = fieldKey;
}
public ArrayList<String> getFieldName() {
return fieldName;
}
public void setFieldName(ArrayList<String> fieldName) {
this.fieldName = fieldName;
}
public ArrayList<String> getWindowNew() {
return windowNew;
}
public void setWindowNew(ArrayList<String> windowNew) {
this.windowNew = windowNew;
}
public ArrayList<String> getLink() {
return link;
}
public void setLink(ArrayList<String> link) {
this.link = link;
}
}
And I hope that you're somewhere calling your mai() method (this name sounds really weird though) to retrieve the data from the excel and store them in the ArrayList before you're trying to call the following piece of code:
ReadExcel readExcel = new ReadExcel();
ArrayList<String> path_name = readExcel.getPath_name();
for(String pathName: path_name){
driver.findElement(By.xpath(pathName).click();
}
Some pointers to your code:
Use generics. Instead of defiing ArrayList pathNameList consider, using ArrayList<String> pathNameList
It looks good if you use Java Naming Convention when you code. One of them is to compose method names using mixed case letters, beginning with a lower case letter and starting each subsequent word with an upper case letter. So instead of having a getPath_name(), consider having something like getPathName() or even getPath_Name() (although most of us would prefer the 1st one). Here's a link that can help you with that.

Related

Reduce number of arguments when calling from DataProviders in testng using java

I am reading the data from Excel file, let us say I have 5 rows and 15 columns in Java testNG.
Review the below code
Class ReadExcel {
public String[][] getCellData(String path, String sheetName) throws InvalidFormatException, IOException {
FileInputStream stream = new FileInputStream(path);
XSSFWorkbook workbook = new XSSFWorkbook(stream);
Sheet s = workbook.getSheet(sheetName);
int rowcount = s.getLastRowNum();
int cellcount = s.getRow(0).getLastCellNum();
String data[][] = new String[rowcount][cellcount];
FormulaEvaluator evaluator= workbook.getCreationHelper().createFormulaEvaluator();
DataFormatter df = new DataFormatter();
for (int i = 1; i <= rowcount; i++) {
Row r = s.getRow(i);
for (int j = 0; j < cellcount; j++) {
Cell c = r.getCell(j);
try {
if(c!=null){
if (c.getCellType() == c.CELL_TYPE_STRING) {
data[i - 1][j] = c.getStringCellValue();
}else if (c.getCellType() == c.CELL_TYPE_FORMULA) {
data[i - 1][j] = df.formatCellValue(c, evaluator);
}
else if (c.getCellType() == c.CELL_TYPE_BOOLEAN) {
data[i - 1][j] = df.formatCellValue(c, evaluator);
}
else{
data[i - 1][j] = String.valueOf(c.getNumericCellValue());
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
return data;
}
}
Another class for processing the data
public class Sample
{
ReadExcel read = new ReadExcel();
#DataProvider (parallel= true)
public String[][] getFilterValues() throws InvalidFormatException, IOException, InterruptedException{
return read.getCellData("fileLoc","fileName");
}
#Test(dataProvider = "getFilterValues")
public void verifyReports(String row, String name, String age, String lastname and so on...) throws Exception
{
System.out.println(FileName);
}
So, here I need to reduce the argument count in verifyReports method and should able to retrieve the entire records in the same method.
Note: Argument count may be changed in future.
So I tried with Map concept but I could not find out.
The main goal is to reduce the no. of arguments in verifyReports method. How to achieve this.
I achieved by using the below code. But it would be in 2D array in order to use it in testNG DataProviders
Below is the code, I tried using list of map.
public ArrayList<String> readHeader(String path, String sheetName) throws IOException
{
FileInputStream stream = new FileInputStream(path);
XSSFWorkbook workbook = new XSSFWorkbook(stream);
Sheet s = workbook.getSheet(sheetName);
int rowcount = s.getLastRowNum();
int cellcount = s.getRow(0).getLastCellNum();
ArrayList<String> al = new ArrayList<String>();
Row r = s.getRow(0);
for(int i=0;i<cellcount;i++)
{
Cell c = r.getCell(i);
al.add(c.getStringCellValue());
}
return al;
}
public ArrayList<HashMap<String,String>> getCellData(String path, String sheetName) throws InvalidFormatException, IOException {
//ExcelConfig ec = new ExcelConfig();
FileInputStream stream = new FileInputStream(path);
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
XSSFWorkbook workbook = new XSSFWorkbook(stream);
Sheet s = workbook.getSheet(sheetName);
int rowcount = s.getLastRowNum();
int cellcount = s.getRow(0).getLastCellNum();
FormulaEvaluator evaluator= workbook.getCreationHelper().createFormulaEvaluator();
DataFormatter df = new DataFormatter();
ArrayList<String> head = ec.readHeader(path, sheetName);
for (int i = 1; i <= rowcount; i++) {
HashMap<String,String> map = new HashMap<String,String>();
Row r = s.getRow(i);
for (int j = 0; j < cellcount; j++) {
Cell c = r.getCell(j);
try {
if(c!=null){
if (c.getCellType() == c.CELL_TYPE_STRING) {
map.put(head.get(j), c.getStringCellValue());
}else if (c.getCellType() == c.CELL_TYPE_FORMULA) {
map.put(head.get(j), df.formatCellValue(c, evaluator));
}
else if (c.getCellType() == c.CELL_TYPE_BOOLEAN) {
map.put(head.get(j), df.formatCellValue(c, evaluator));
}
else{
map.put(head.get(j), String.valueOf(c.getNumericCellValue()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
list.add(map);
}
return list;
}
public void multiRec() throws InvalidFormatException, IOException
{
ArrayList<HashMap<String, String>> map = read.getCellData(fileLoc,"ComparisonStatus");
for(HashMap<String, String> ls : map)
{
System.out.println(ls.get("Row"));
System.out.println(ls.get("FileName"));
}
}
Here, Row and FileName are Excel file header. So now I reduced the no. of arguments. But how to convert it to 2D array will be the task now.
The best way would be to create a class containing all the arguments as fields of the class. Let the class name be CellData
class CellData {
private String row;
private String name;
// and all other relevant fields..
}
In the getCellData method, create and initialize an object of CellData with the relevant values of each row and instead of returning String[][] return CellData[]. Then make the below changes:
#DataProvider (parallel= true)
public Object[][] getFilterValues() throws InvalidFormatException, IOException, InterruptedException{
CellData[] cellData = read.getCellData("fileLoc","fileName");
Object[][] data = new Object[cellData.length][];
for(int i = 0; i < cellData.length; i++) {
data[i][0] = cellData[i];
}
return data;
}
#Test(dataProvider = "getFilterValues")
public void verifyReports(CellData data) throws Exception
{
// test code.
}
Since you are saying that new arguments could be introduced in the future, using a class would be very much beneficial as it could help the code be maintainable and readable. Any future updates would also require much less code changes as there is no need of updating the DataProvider method or the test method. The only change would be a new field in the CellData class and setting the values for the new fields in getCellData method.

Unable to write new excel using Apache POI after removing duplicate rows

I am new to Apache POI.
I have written a small code for removing duplicate records from a excel file. I am successfully able to identify the duplicate records across sheets but when writing to a new file after removing records, no output is being generated.
Please help where I am goin wrong?
Am I writing properly ?? Or am missing something?
public static void main(String args[]) {
DataFormatter formatter = new DataFormatter();
HSSFWorkbook input_workbook;
HSSFWorkbook workbook_Output_Final;
HSSFSheet input_workbook_sheet;
HSSFRow row_Output;
HSSFRow row_1_index;
HSSFRow row_2_index;
String value1 = "";
String value2 = "";
int count;
//main try catch block starts
try {
FileInputStream input_file = new FileInputStream("E:\\TEST\\Output.xls"); //reading from input file
input_workbook = new HSSFWorkbook(new POIFSFileSystem(input_file));
for (int sheetnum = 0; sheetnum < input_workbook.getNumberOfSheets(); sheetnum++) { //traversing sheets
input_workbook_sheet = input_workbook.getSheetAt(sheetnum);
int input_workbook_sheet_total_row = input_workbook_sheet.getLastRowNum(); //fetching last row nmber
for (int input_workbook_sheet_row_1 = 0; input_workbook_sheet_row_1 <= input_workbook_sheet_total_row; input_workbook_sheet_row_1++) { //traversing row 1
for (int input_workbook_sheet_row_2 = 0; input_workbook_sheet_row_2 <= input_workbook_sheet_total_row; input_workbook_sheet_row_2++) {
row_1_index = input_workbook_sheet.getRow(input_workbook_sheet_row_1); //fetching one iteration row index
row_2_index = input_workbook_sheet.getRow(input_workbook_sheet_row_2); //fetching sec iteration row index
if (row_1_index != row_2_index) {
count = 0;
value1 = "";
value2 = "";
for (int row_1_index_cell = 0; row_1_index_cell < row_1_index.getLastCellNum(); row_1_index_cell++) { //traversing cell for each row
try {
value1 = value1 + formatter.formatCellValue(row_1_index.getCell(row_1_index_cell)); //fetching row cells value
value2 = value2 + formatter.formatCellValue(row_2_index.getCell(row_1_index_cell)); //fetching row cells value
} catch (NullPointerException e) {
}
count++;
if (count == row_1_index.getLastCellNum()) {
if (value1.hashCode() == value2.hashCode()) { //remove the duplicate logic
System.out.println("deleted : " + row_2_index);
System.out.println("------------------");
input_workbook_sheet.removeRow(row_2_index);
}
}
}
}
}
}
}
FileOutputStream fileOut = new FileOutputStream("E:\\TEST\\workbook.xls");
input_workbook.write(fileOut);
fileOut.close();
input_file.close();
} catch (Exception e) {
//e.printStackTrace();
}
//main try catch block ends
}
A couple of things to note:
you swallow any kind of Exception; Igotsome nullpointers with my test data, and that would prevent the workbook from being written
when removing rows, it is an old trick to move backwards through the row numbers because then you don't have to adjust for the row number you have just removed
the code empties the row, but it doesn't move all rows upwards (=there is a gap after the delete). If you want to remove that gap, you can work with shiftRows
you compare things by hashcode, which is possible (in some use cases), but I feel like .equals() is what you want to do. See also Relationship between hashCode and equals method in Java
Here's some code that worked for my test data, feel free to comment if something doesn't work with your data:
public static void main(String args[]) throws IOException {
DataFormatter formatter = new DataFormatter();
HSSFWorkbook input_workbook;
HSSFWorkbook workbook_Output_Final;
HSSFSheet input_workbook_sheet;
HSSFRow row_Output;
HSSFRow row_1_index;
HSSFRow row_2_index;
String value1 = "";
String value2 = "";
int count;
FileInputStream input_file = new FileInputStream("c:\\temp\\test.xls");
input_workbook = new HSSFWorkbook(new POIFSFileSystem(input_file));
for (int sheetnum = 0; sheetnum < input_workbook.getNumberOfSheets(); sheetnum++) {
input_workbook_sheet = input_workbook.getSheetAt(sheetnum);
int input_workbook_sheet_total_row = input_workbook_sheet.getLastRowNum();
for (int input_workbook_sheet_row_1 = input_workbook_sheet_total_row; input_workbook_sheet_row_1 >=0; input_workbook_sheet_row_1--) { // traversing
for (int input_workbook_sheet_row_2 = input_workbook_sheet_total_row; input_workbook_sheet_row_2 >= 0 ; input_workbook_sheet_row_2--) {
row_1_index = input_workbook_sheet.getRow(input_workbook_sheet_row_1);
row_2_index = input_workbook_sheet.getRow(input_workbook_sheet_row_2);
if (row_1_index != null && row_2_index != null && row_1_index != row_2_index) {
count = 0;
value1 = "";
value2 = "";
int row_1_max = row_1_index.getLastCellNum() - 1;
for (int row_1_index_cell = 0; row_1_index_cell < row_1_max; row_1_index_cell++) {
try {
value1 = value1 + formatter.formatCellValue(row_1_index.getCell(row_1_index_cell));
value2 = value2 + formatter.formatCellValue(row_2_index.getCell(row_1_index_cell));
} catch (NullPointerException e) {
e.printStackTrace();
}
count++;
if (value1.equals(value2)) {
System.out.println("deleted : " + row_2_index.getRowNum());
System.out.println("------------------");
input_workbook_sheet.removeRow(row_2_index);
input_workbook_sheet.shiftRows(
row_2_index.getRowNum() + 1,
input_workbook_sheet_total_row,
-1,
true,
true);
}
}
}
}
}
}
FileOutputStream fileOut = new FileOutputStream("c:\\temp\\workbook.xls");
input_workbook.write(fileOut);
fileOut.close();
input_file.close();
input_workbook.close();
}

read multiple excel sheet selenium-webdriver, java, eclipse

I want to run selenium-webdriver-java-eclipse, using excel file contains multiple excel sheets with different name(sheet1,sheet2,sheet3,...), i need a for loop help me to do that and read from this sheets.
public class ExcelDataConfig {
XSSFWorkbook wb;
XSSFSheet sheet = null;
public ExcelDataConfig(String Excelpath) throws IOException {
// TODO Auto-generated method stub
try {
File file = new File(Excelpath);
// Create an object of FileInputStream class to read excel file
FileInputStream fis = new FileInputStream(file);
wb = new XSSFWorkbook(fis);
} catch (Exception e) {
}
}
public String GetData(int sheetNumber, int Row, int Column) {
Iterator<Row> rowIt=sheet.rowIterator();
DataFormatter formatter = new DataFormatter();
XSSFCell cell = sheet.getRow(Row).getCell(Column);
String data = formatter.formatCellValue(cell);
return data;
}
public int GetRowCount(String sheetNumber) {
int row = wb.getSheet(sheetNumber).getLastRowNum();
row = row + 1;
return row;
}
}
try something like this, it is working for me you need to add the sheet numbers and cell numbers at the places of k and j
enter code here
String filePath="C:\\Users\\USER\\Desktop\\Book1.xlsx";// file path
FileInputStream fis=new FileInputStream(filePath);
Workbook wb=WorkbookFactory.create(fis);
ArrayList<String> ls=new ArrayList<String>();
for(int k=0; k<=3;k++)//k =sheet no
{
Sheet sh=wb.getSheetAt(k);
System.out.println(sh);
// int count=0;
for(int i=0;i<=sh.getLastRowNum();i++)
{
System.out.println("row no:"+i);
for(int j=0; j<=4;j++)//j=column no
{
try {
String values=sh.getRow(i).getCell(j).getStringCellValue().trim();
System.out.println(values);
//condetions
/* if(values.contains("condtn1"))
{
System.out.println("Value of cell "+values+" ith row "+(i+1));
ls.add(values);
count++;
}
if(values.contains("condn2"))
{
System.out.println("Value of cell "+values+" ith row "+(i+1));
ls.add(values);
count++;
}*/
}catch(Exception e){
}
}
}
}
}
}
Please try writing similar to something like this:
for (int i = startRow; i < endRow + 1; i++) {
for (int j = startCol; j < endCol + 1; j++) {
testData[i - startRow][j - startCol] = ExcelWSheet.getRow(i).getCell(j).getStringCellValue();
Cell cell = ExcelWSheet.getRow(i).getCell(j);
testData[i - startRow][j - startCol] = formatter.formatCellValue(cell);
}
}
Terms used in method are pretty self explanatory. Let us know if you get stuck or need more info.

Apache POI - Reading excel file in 2D array - returning null values

I am trying to read Excel -2*2 matrix through Apache POI. But the first value returned by 2D array is [null,null]. Please check my code and advise for suitable corrections.
public String[][] getDataArray(String sheetName)
{
String value ="";
String[][] data = null;
int rowCount = wb.getSheet(sheetName).getLastRowNum();
int colCount = wb.getSheet(sheetName).getRow(1).getLastCellNum()-1;
data = new String[rowCount][colCount];
for(int i=1; i<=rowCount;i++)
{
Row row = wb.getSheet(sheetName).getRow(i);
for(int j=0;j<colCount;j++)
{
Cell cell = row.getCell(j);
if(cell.getCellType()==Cell.CELL_TYPE_NUMERIC)
{
value = ""+cell.getStringCellValue();
}
else
{
value = cell.getStringCellValue();
}
data[i][j] = value;
}
}
return data;
}
The debug view where we can see that the first value stored in the variable data is null, null
The excel which i am trying to read. I need only the userName and password data(2*2) alone. Not the header and Run mode datas.
Of course the value in the index 0 will be null because the i starts from 1 and not 0
for (int i = 1; i <= rowCount; i++) //i starts from one
...
data[i][j] = value;
either initialize the i from 0 or do like this
data[i-1][j] = value;
public static String[][] getSheetData(final String fileName, final String workSheetName)
throws Exception {
Integer lastRow = null;
short lastCol = 0;
String[][] sheetData = null;
FileInputStream file=new FileInputStream(MettlTest.class.getClass().getResource("/" + fileName).getPath());
workbook = new XSSFWorkbook(file);
sheet = workbook.getSheet(workSheetName);
try {
XSSFRow row;
XSSFCell cell;
lastRow = sheet.getPhysicalNumberOfRows();
lastCol = sheet.getRow(1).getLastCellNum();
sheetData = new String[lastRow - 1][lastCol];
for (int r = 1; r < lastRow; r++) {
row = sheet.getRow(r);
if (row != null) {
for (int c = 0; c < lastCol; c++) {
cell = row.getCell(c);
if (cell == null) {
sheetData[r][c] = null;
} else {
sheetData[r-1][c] = new DataFormatter().formatCellValue(cell);
}
}
}
}
return sheetData;
}
catch (final Exception e) {
throw e;
}
finally {
try {
file.close();
} catch (IOException io) {
Reporter.log("Unable to close File : " + fileName);
throw io;
}
}

String Array from excel column

How can I get a string array from a excel column?
Let's say the column is like this
String0
String1
String2
String3
String4
and I want my array to be like: array[0]="String0", array[1]="String1" etc.
This is the code I am currently using but it always returns "null":
public static String[] excelvalue(String columnWanted, int sheet_no, String path) {
int i = 0;
String[] column_content_array = new String[140];
try {
int instindicator = -1;
FileInputStream file = new FileInputStream(new File(path));
HSSFWorkbook filename = new HSSFWorkbook(file);
HSSFSheet sheet = filename.getSheetAt(sheet_no);
Integer columnNo = null;
Integer rowNo = null;
List<Cell> cells = new ArrayList<Cell>();
Row firstRow = sheet.getRow(0);
for (Cell cell : firstRow) {
if (cell.getStringCellValue().equals(columnWanted)) {
columnNo = cell.getColumnIndex();
rowNo = cell.getRowIndex();
}
}
if (columnNo != null) {
for (Row row : sheet) {
Cell c = row.getCell(columnNo);
String cell_value = "" + c;
cell_value = cell_value.trim();
try {
if ((!cell_value.equals("")) && (!cell_value.equals("null")) && (!cell_value.equals(columnWanted))) {
column_content_array[i] = cell_value;
i++;
}
} catch (Exception e) {
}
}
return column_content_array;
}
} catch (Exception ex) {
return column_content_array;
}
return column_content_array;
}
Instead of storing just last reference of row and column, store all of them in a list like:
List<Integer> columnNos = new ArrayList<>();
List<Integer> rowNos = new ArrayList<>();
And in your for loop, just add rows and columns into list like:
if (cell.getStringCellValue().equals(columnWanted)) {
columnNos.add(cell.getColumnIndex());
rowNo.add(cell.getRowIndex());
}
And then you could iterate over rows and columns and continue with your business logic further.

Categories

Resources