简体   繁体   English

使用Apache Poi在特定列中的Excel中查找Excel的最后一行

[英]Find last row no in excel in a particular columnno using Apache poi

我的excel截图

i want to find the row no ie 10 of value "sam" using columnno 6 我想使用列号6查找行号即值“ sam”的10

any inbuilt function in apache poi like this col(6).getLastRowNum() apache poi中的任何内置函数,例如col(6).getLastRowNum()

Try below code to identify last row from excelsheet. 尝试下面的代码,以识别excelsheet中的最后一行。 Below code automatically iterate through all rows and identify last row from all columns. 下面的代码自动遍历所有行,并标识所有列的最后一行。

public static void main(String[] args) throws IOException {

        // Making of excel file object
        File myFile = new File(CommonMethods.getFilePath("testdata", "Sample.xlsx"));
        FileInputStream fis = new FileInputStream(myFile);
        XSSFWorkbook myWorkBook = new XSSFWorkbook(fis);
        XSSFSheet mySheet = myWorkBook.getSheet("Logout");
        XSSFRow row = null;

        // Making the object of excel row
        row = mySheet.getRow(0);

        int colCount = row.getLastCellNum();
        System.out.println("Column Count :- " + colCount);

        int rowCount = mySheet.getLastRowNum() + 1;
        System.out.println("Row Count :- " + rowCount);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM