poi操作excel导出是否修改模板文件内容的问题

来源:互联网 发布:网络弊大于利四辩总结 编辑:程序博客网 时间:2024/05/16 11:40
public Workbook loadExcel(String filePath) throws FileNotFoundException,IOException, EncryptedDocumentException, InvalidFormatException{

   Workbook book = null;

                  if(filePath==null)return null;

  if(filePath.endsWith(".xls")){
   POIFSFileSystem ps=new POIFSFileSystem(new File(filePath));
book =WorkbookFactory.create(ps);
}else if(filePath.endsWith(".xlsx")){
//解决模板污染问题
InputStream input=new FileInputStream(new File(filePath));
book=new XSSFWorkbook(input);
}
        return book;

}

//通过流的方式去创建则原文件不会被修改。

0 0
原创粉丝点击