解读Java对Execl读取数据

1.读取execl文件路径,或者打开execl

        // 初始化文件流
        FileInputStream in = null;
        in = new FileInputStream(new File(path));
        workbook = new XSSFWorkbook(in);
        sheet = workbook.getSheetAt(0);
        rows = sheet.getPhysicalNumberOfRows();

2.读取execl中sheet页数,即获取当前Excel所有sheet页的个数

        int sheets = 0;
        if (workbook != null) {
            sheets = workbook.getNumberOfSheets();
        }
        return sheets;

3.读取execl中sheet名称,即获取当前execl所有sheet的名称

    public String getSheetName(int sheetIndex) {
        String sheetname = "";
        if (workbook != null)
            sheetname = workbook.getSheetName(sheetIndex);
        return sheetname;
    }

4.根据sheet名使用sheet页。

        if (workbook != null) {
            sheet = workbook.getSheet(sheetName);
            rows = 

你可能感兴趣的:(Java,java,开发语言)