java获得Excel中的单元格内容,比直接用excel内部内部公式方便多

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/pmdream/article/details/84235062
public class GetExcelInfo {
    public static void main(String args[]){
        File f=new File("c:/test/00.xls");
        try {
            Workbook book=Workbook.getWorkbook(f);//
            Sheet sheet=book.getSheet(0); //获得第一个工作表对象
            for(int i=0;i<sheet.getRows();i++){
                Cell cell1 = sheet.getCell(0, i);
                Cell cell2 = sheet.getCell(1, i);
                for(int j=0;j<sheet.getColumns();j++){
                    Cell cell=sheet.getCell(j, i); //获得单元格
                    System.out.print(cell.getContents() + " ");
                }
                System.out.print("\n");
            }
        } catch (BiffException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/pmdream/article/details/84235062