首页 > 解决方案 > 无法通过使用带有 Aspose 工作簿的 java 在 ADO(s3 存储桶)中提供密码来取消保护 xlsx、xls 文件

问题描述

我在使用 java 的 ADO 中没有收到任何错误或异常。我在 java 中使用过 Aspose 库。请在下面找到代码。它没有抛出任何错误或异常。我试过很多。我没有得到任何解决方案。这是我第一次在 ADO 环境下工作。

public void removePassword(){
    log.info("****** Entered into  removePassword()*** ");
    try{
        LoadOptions loadOptions = new LoadOptions(LoadFormat.XLSX);
        loadOptions.setPassword("XXXX"); 
        if ("true".equalsIgnoreCase(isAWS)) {
            File file = awss3Service.loadFileFromS3(rsmAccessEntity.getIfluxawss3bucket(),"dev/sample/upload/22-01-2021/ABCP/" ,"Check_1.xlsx");
            log.info("****** file length*** "+file.length());
            com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(new FileInputStream(file),loadOptions);
            workbook.save("Check_1.xlsx", FileFormatType.XLSX);
            File file1 = new File("Check_1.xlsx");
            log.info("****** file1 *** "+file1.length());
            boolean isXlsxProtect = ProtectedFilesUtility.isXlsxProtected(new FileInputStream(file1));
            log.info("****** isXlsxProtect *** "+isXlsxProtect);
            awss3Service.uploadFile(new FileInputStream(file1),"dev/sample/upload/22-01-2021/ABCP/","Check_1.xlsx");    
        }
    }catch(Exception e){
        log.info("****** exception  *** "+e);
    }
}

标签: javaado

解决方案


我尝试了上面的方法它不起作用,仍然文件有受保护的文件。我没有得到任何异常或错误。请找到我的一段代码..

public void removePassword(){
   log.info("****** Entered into  removePassword()*** ");
   try{
       LoadOptions loadOptions = new LoadOptions(LoadFormat.XLSX);
       loadOptions.setPassword("XXXX"); 
       if ("true".equalsIgnoreCase(isAWS)) {
           File file = awss3Service.loadFileFromS3(rsmAccessEntity.getIfluxawss3bucket(),"dev/sample/upload/22-01-2021/ABCP/" ,"Check_1.xlsx");
           log.info("****** file length*** "+file.length());
           com.aspose.cells.Workbook workbook = new com.aspose.cells.Workbook(new FileInputStream(file),loadOptions);
           workbook.getSettings().setPassword("XXXX");
           workbook.save("Check_1.xlsx", FileFormatType.XLSX);
           File file1 = new File("Check_1.xlsx");
           log.info("****** file1 *** "+file1.length());
           boolean isXlsxProtect = ProtectedFilesUtility.isXlsxProtected(new FileInputStream(file1));
           log.info("****** isXlsxProtect *** "+isXlsxProtect);
           awss3Service.uploadFile(new FileInputStream(file1),"dev/sample/upload/22-01-2021/ABCP/","Check_1.xlsx");    
       }
   }catch(Exception e){
       log.info("****** exception  *** "+e);
   }
}

推荐阅读