[英]How do i get row,column coordinates on selected String in excel
如何獲取 excel 文件中的行、列坐標? 我正在嘗試確認用戶名在文件中。 所以我嘗試創建一個循環來讀取 excel 文件中的所有輸入並找到與用戶名相同的名稱並返回行和列。 這是我的代碼。
private int ReadName(String Name){
Iterator<Row> rowIterator = librarianSheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
if(cell.getCellType() == CellType.STRING){
String random = cell.getRichStringCellValue().getString();
}
if(random == Name){
}
}
}
//return ;
}
但我似乎被困在那里,因為我不知道該怎么做才能獲得理想的 output。請幫助我..
找到所需名稱后,返回單元格。
private Cell readName(String name){
Iterator<Row> rowIterator = librarianSheet.iterator();
while (rowIterator.hasNext()) {
Row row = rowIterator.next();
Iterator<Cell> cellIterator = row.cellIterator();
while (cellIterator.hasNext()) {
Cell cell = cellIterator.next();
if(cell.getCellType() == CellType.STRING){
String random = cell.getStringCellValue();
if(random.equals(name)){
return cell;
}
}
}
}
return null;
}
然后你可以像這樣使用它:
Cell cell = readName("Muhammad");
if(cell != null) {
int column = cell.getColumnIndex();
int row = cell.getRowIndex();
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.