0

我有 n 行和列的 Excel 表。例子

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

所以在上面的数据中,我想读取 Orderid 和 Count 并将它们作为下一次调用的输入。我使用了下面的代码

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);

  } 
}

上面的代码读取 excel 表并在控制台中提供输入,但我希望在某个数组或列表中分配特定角色,从那里我可以将其作为输入以迭代方式提供给下一个函数。有人可以帮我弄这个吗。

4

1 回答 1

0

我会说制作一个整数数组列表(顺序和计数似乎是整数),或者如果你想要它们作为字符串,则为字符串

  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应该是这样的

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

你可以将它传递给另一个方法,假设这个方法

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

你打电话:

myOtherMethod(data);
于 2018-03-26T08:34:43.543 回答