我正在尝试根据下面的标题获取数据首先我正在设置第一行并存储它在地图中有键。但问题是我想从第二行获取数据,但我得到了iterator.how我可以从第二行获取数据吗?
DataFormatter df=new DataFormatter();
Map<String,Integer> m=new HashMap<String,Integer>();
FileInputStream file = new FileInputStream(new File("/root/Documents/xyz.xlsx"));
//Get the workbook instance for XLS file
XSSFWorkbook workbook = new XSSFWorkbook(file);
//Get first sheet from the workbook
XSSFSheet sheet = workbook.getSheetAt(0);
Row row=sheet.getRow(0);
XSSFRow rowe = (XSSFRow)row;
int s=row.getLastCellNum();
System.out.println(s);
for(int i=0;i<s-1;i++){
String data= df.formatCellValue(rowe.getCell(i));
System.out.println(data);
m.put(data,i);
}
Iterator<Row> rows = sheet.rowIterator();
while (rows.hasNext()) {
XSSFRow rowa = (XSSFRow) rows.next();
System.out.println(df.formatCellValue(rowa.getCell(m.get("Member.Member Card Number"))));
}
答案 0 :(得分:0)
这是你在找什么?
int count =0;
while (rows.hasNext()) {
XSSFRow rowa = (XSSFRow) rows.next();
if(count !=0){
System.out.println(df.formatCellValue(rowa.getCell(m.get("Member.Member Card Number"))));
}
count++;
}
答案 1 :(得分:0)
尝试这样的事情
Vector cellVectorHolder = new Vector();
XSSFSheet mySheet = myWorkBook.getSheetAt(0);
Iterator rowIter = mySheet.rowIterator();
while(rowIter.hasNext()){
XSSFRow myRow = (XSSFRow) rowIter.next();
Iterator cellIter = myRow.cellIterator();
List list = new ArrayList();
while(cellIter.hasNext()){
XSSFCell myCell = (XSSFCell) cellIter.next();
list.add(myCell);
}
cellVectorHolder.addElement(list);
}