lh-masteryi

Excel最简洁解析

public static void main(String[] args) {

  File file = new File("D://123.xlsx");
  try {
    InputStream is = new FileInputStream(file);
    Workbook wb = null;
    if (file.getName().endsWith("xls")) { //Excel 2003
      try {
        wb = new HSSFWorkbook(is);
      } catch (IOException e) {
        e.printStackTrace();
      }
    } else if(file.getName().endsWith("xlsx")) { // Excel 2007/2010
      try {
        wb = new XSSFWorkbook(is);
      } catch (IOException e) {
        e.printStackTrace();
      }   
    }

    for (Sheet sheet : wb) {
      for (Row row : sheet) {
        StringBuffer sb = new StringBuffer();
        for (Cell cell : row) {
          sb.append(cell.toString());
        }
        System.out.println(sb);
      }
    }
  } catch (FileNotFoundException e) {
    e.printStackTrace();
  }
}

发表于 2018-05-25 10:32  昭幻昊11  阅读(63)  评论(0编辑  收藏  举报
 

分类:

技术点:

相关文章:

  • 2021-05-21
  • 2022-12-23
  • 2021-07-17
  • 2022-02-21
  • 2022-01-18
  • 2022-12-23
  • 2021-04-21
猜你喜欢
  • 2021-11-21
  • 2022-12-23
  • 2021-11-30
  • 2022-12-23
  • 2021-06-04
  • 2021-11-19
  • 2022-12-23
相关资源
相似解决方案