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

    xiaoxiao2021-03-25  93

    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;

    }

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

    转载请注明原文地址: https://ju.6miu.com/read-21255.html

    最新回复(0)