Javaを使用してExcelやExcelで繰り返し処理に問題があります。私はすべての数字を収集し、コンストラクタにそれを渡す必要がイテレータを前進させずにセル値を取得する方法 - Excel、Java POI
:私は、このようにシートに構造化されたデータを持っています。私はこのようにsthを試しました:
Iterator<Row> iterator = firstSheet.iterator();
while (iterator.hasNext()){
Row nextRow = iterator.next();
Iterator<Cell> cellIterator = nextRow.cellIterator();
int id = (int) cellIterator.next().getNumericCellValue();
int pr = (int) cellIterator.next().getNumericCellValue();
int[] prId = new int[2];
prId[0] = (int) cellIterator.next().getNumericCellValue();
iterator.next(); // i have to move down one row to get 5 and 6
precId[1] = // what should I type here?? cellIterator.next() will cause, that cell with value "5" will be omitted and I will get "6"
int co = (int) cellIterator.next().getNumericCellValue();
list.add(new Rule(id, pr, prId, co));
}
どのように対処するには?事前に 感謝:)
EDIT:
私は他の方法で細胞を取得することを決めた:
for(int rowNum = rowStart+1; rowNum < rowEnd; rowNum++){
Row r = sheet.getRow(rowNum);
if(r == null){
continue;
}
int lastColumn = Math.max(r.getLastCellNum(), 4);
for(int cn = 0; cn < lastColumn; cn++){
@SuppressWarnings("deprecation")
Cell c = r.getCell(cn, Row.RETURN_BLANK_AS_NULL);
if(c == null){
continue;
}else{
System.out.println(c);
}
}
}
このソリューションは明らかに良いですが、私はSystem.out.println(c)
iであるため代わりにショー細胞値の問題を抱えていますイテレータの例のように、この値をコンストラクタに渡す必要があります。しかし、今私はループを使用しているセルへのアクセスを持っているので、次のセルの値を得ることができません.next()またはsthの類似 - 私は同じ行をコードの1行に次のセルを取得することはできません上記のように(イテレータで)、このコードを使用していますか?
"移動する前にセルの値を取得する方法"移動する前に値を格納しますか? – Moira
@ 1blustone私はこの値を得る方法を知らない。私の説明を読むだけでなく、ティラール:) – pulpet112
私はそれを保存すると言った理由は私がした。イテレータが動いている問題は何ですか? 'Cell stored = cellIterator.next()'のような行を作り、それを 'precId [1]'に使用しますか?または正しく理解しませんでした – Moira