各位師兄好,小弟菜鳥有個問題想請交~
如圖中,有個學生的編號063365663,要怎樣寫才能讀取到這個編號?

解决方案 »

  1.   

    依次读行,每行识别一个数字,append到StringBuilder对象上,所有行遍历完了,学号就到手了。对了,X是文字吗?
    你需要识别有X的单元格的列号。
      

  2.   

    還是不太懂~
    可以給給code參考嗎?
      

  3.   

    楼主可参考以下程序。当然,针对你的Excel文件格式可能需要小小修改。 String fileName = "numbers.xls"; //本文件中有学号定义。
    try {
    POIFSFileSystem fs = new POIFSFileSystem(new FileInputStream(fileName));
    HSSFWorkbook resourceFile = new HSSFWorkbook(fs);
    HSSFSheet shOrg = resourceFile.getSheet("sheet0");
    if (shOrg == null) {
    System.out.println("打开Excel文件失败。");
    }
    StringBuilder sb = new StringBuilder();
    int rowNo = 0;
    while( sb.length()<9 ){
    HSSFRow curRow = shOrg.getRow(rowNo); //取XSL文件sheet0页上第rowNo+1行;
    int colNo = 0;
    boolean xFound = false;
    while(!xFound){
    HSSFCell curCol = curRow.getCell(colNo);
    if (    curCol != null &&
    curCol.getCellType()==HSSFCell.CELL_TYPE_STRING &&
    "x".equals(curCol.getStringCellValue())){
    xFound = true;
    }
    if (colNo++ > 10) break;
    }
    if (xFound) sb.append(colNo-2);
    rowNo++;
    }
    System.out.println(sb);
    } catch (Exception e) {
    e.printStackTrace();
    }