首页 > 其他 > 详细

Excel最简洁解析

时间:2018-05-25 12:41:14      阅读:202      评论:0      收藏:0      [点我收藏+]

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();
  }
}

Excel最简洁解析

原文:https://www.cnblogs.com/lh-masteryi/p/9087120.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!