0

I have n rows and Columns of Excel sheet . example

Name OrderId Count Date 
ANC 1234 5 23/3/18 
ABCD 2345 6 23/3/18 
XYGS 3567 7 23/3/18

So in the above data , i want to read the Orderid and Count and give them as input to the next call. I have used the below code

if(columnIndex != 0) {

  for(Row row1: sheet) {

    Cell C =row1.getCell(columnIndex);
    po_number =c.getStringCellValue();
    excelList.add(po_number);
    int n = columnIndex+1;
    Cell line_number1= row1.getCell(n);
    line_number = line_number1.getStringCellValue();

    FileOutputStream("D:\Users\abcd\Documents\AMD\Output\output.csv"));

    System.out.println(po_number + " " +line_number);

  } 
}

The above code reads the excel sheet and gives the input in console, but i want the particular role to be get assigned in some array or list , from where i can give it as input to next function in iterative manner. Can someone help me with this.

Bentaye
  • 9,403
  • 5
  • 32
  • 45
jlearner
  • 1
  • 1

1 Answers1

0

I'd say make a list of arrays of ints (order and count seem to be integers), or String if you want them as Strings

  List<int[]> data = new ArrayList<>();
  for(int i=1; i<sheet.getPhysicalNumberOfRows(); i++) {
    Row row = sheet.getRow(i);
    int orderId = (int)row.getCell(1).getNumericCellValue();
    int count = (int)row.getCell(2).getNumericCellValue();
    data.add(new int[] { orderId, count });
  }

data should look like this

[1234, 5], [2345, 6], [3567, 7]

And you can pass it to an other method, assuming this method

private static void myOtherMethod(List<int[]> data) {
  // Do whatever you want here
}

you call:

myOtherMethod(data);
Bentaye
  • 9,403
  • 5
  • 32
  • 45