fangry

  已有一个导入功能,只支持xls文件导入。要扩展,使其同时兼容xlsx文件导入。

  首先,需要删除xbean-2.2.0.jar包,引入xmlbeans-2.3.0.jar包。

  判断导入excel文件的版本:

        /**
	 * 判断excel文件版本
	 * @param file
	 * @return
	 */
	public String checkExcelVersion(File file) {
		String result = "";
		try {
		  InputStream is = new FileInputStream(file);
	          BufferedInputStream bis = new BufferedInputStream(is);
	          if(POIFSFileSystem.hasPOIFSHeader(bis)) {
	              result = "2003及以下";
	          } else {
	        	result = "2007及以上";
	          } 
	        /*if(POIXMLDocument.hasOOXMLHeader(bis)) {
	            
	        }*/
		} catch (Exception e) {
		  e.printStackTrace();
		}
		return result;
	}
	

  2003及以下使用HSSFWorkbook,2007及以上使用XSSFWorkbook。两个版本的导入代码调用相同。

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2022-02-22
  • 2022-01-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-04
  • 2022-01-19
猜你喜欢
  • 2022-12-23
  • 2022-02-17
  • 2022-12-23
  • 2021-12-04
  • 2021-11-14
  • 2022-02-02
  • 2021-12-29
相关资源
相似解决方案