java读取excle指定位置的数据

xiaoxiao2021-02-28  169

将Excel指定位置的信息读取出来

步骤

建立File文件获取相应文件建立Workbook文件获取相应table循环遍历文件内容 public void display(String name){ File file = new File("/data/aa"+name+".xls"); try{ //建立文件 Workbook book = Workbook.getWorkbook(file); //获取第一个表 Sheet sheet = book.getSheet(0); //循环输出表头,用制表符格式化 for(int i = 0;i < sheet.getColumns();i++){ System.out.print(sheet.getCell(i, 0).getContents()+"\t"); } System.out.println(); //输出文件内容 for(int i = 6;i < sheet.getRows(); i++){ for(int j = 0; j < sheet.getColumns(); j++){ System.out.print(sheet.getCell(j, i).getContents()+"\t"); } System.out.println(); } }catch(Exception e){ e.printStackTrace(); } }
转载请注明原文地址: https://www.6miu.com/read-18346.html

最新回复(0)