com.aspose.cells.CellsException : Invalid password

@here I am getting below exception very frequently when user trying to view excel file
All three exceptions are coming in common scenario. I ll attach one of the exception log. We are using 20.4 version of aspose cells for java
Please help me to find out the root cause and how I can fix this.

  1. com.aspose.cells.CellsException : Invalid password
  2. com.aspose.cells.CellsException: Invalid FontUnderlineType string val
  3. com.aspose.cells.CellsException: This file’s format is not supported or you don’t specify a correct format.
    logLevel=ERROR thread=http-nio-8080-exec-3 Error occurred due to detecting ContainsUnsupportedFeature in excel com.aspose.cells.CellsException: This file’s format is not supported or you don’t specify a correct format.
    at com.aspose.cells.zjy.a(Unknown Source)
    at com.aspose.cells.zjy.a(Unknown Source)
    at com.aspose.cells.Workbook.a(Unknown Source)
    at com.aspose.cells.Workbook.(Unknown Source)
    at com.mrll.javelin.wopi.service.WOPIService.isContainsUnsupportedFeature(WOPIService.java:235)
    at com.mrll.javelin.wopi.service.WOPIService.getPdfViewMessage(WOPIService.java:196)
    at com.mrll.javelin.wopi.controller.WOPIHostController.validateOfficeView(WOPIHostController.java:96)
    at com.mrll.javelin.wopi.controller.WOPIHostController$$FastClassBySpringCGLIB$$6163e929.invoke()
    at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
    at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:752)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
    at org.springframework.security.access.intercept.aopalliance.MethodSecurityInterceptor.invoke(MethodSecurityInterceptor.java:69)
    at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)

Thank you,

@hirekhan,

Could you zip your template Excel file and attach it to reproduce the issue, we will check it soon.

Also, provide password if the file is encrypted/password protected.

@Amjad_Sahi
I would have definitely attached it but the problem is this issue is happening in the production environment, I am trying to reproduce it in dev env to debug but I am not able to do it because I don’t have the document
And coming to the second point we are not providing support for password protected files.
There are 3 conditions in our case when the excel document will be open in pdf

  1. if file size > 15 mb
  2. if excel is 195 format type
  3. if excel contains unsupported feature out of this any
    return wb.hasMacro() || wb.getSettings().isProtected() || containsWatch(wb);
    out of these I am getting exception in 3rd case.
    I am getting exception at this line
    Workbook wb = new Workbook(inputStream);

@hirekhan,

I am afraid, without a template for reproducing the issue, we might not help much. We do need your template file to evaluate your issue on our end. Please do the needful and provide us the sample file.

@Amjad_Sahi

yes I understood, I will try to get the template and come back to you

Thank you

@hirekhan,

Alright! we are looking forward to get your template file soon.

@hirekhan,

Please note, for template files which have been encrypted and need password to open, you should provide the correct password to open it (new Workbook(templatefile)). To check whether it is encrypted and avoid such kind of exception, you may try:
e.g
Sample code:

                FileFormatInfo info = FileFormatUtil.DetectFileFormat(pathCase);
                if (!info.IsEncrypted)
                {
                    ...
                }

For issues/exceptions 2 and 3, we need your template file to reproduce the issue. And maybe the files have been corrupted so they cause such exceptions.

@Amjad_Sahi,

Thank you for all the information, Now the concern is i wanted to handle this exception gracefully and for that in catch block i wrote
LOG.error("Error occurred due to detecting ContainsUnsupportedFeature in excel ", e.getMessage()); previously it was only e here which was giving stacktrace in log

i want to avoid stack trace for it any how for such case we are opening the document in pdf viewer.
but the problem is this e.getMessage() is not giving any message
do you know anything regarding this?

Thank you

@hirekhan,

As requested earlier, we need your template file(s) to evaluate your issue(s) precisely. So, we are waiting for your template file(s).

@Amjad_Sahi,

yes I got your point, yes I got the document from prod, I downloaded the blob and saved it with the given extension. It is password protected and I don’t have the password.

Thank you,

@Amjad_Sahi,
this is one of the file where I am getting exception,
password is test1
workbook_protected.zip (8.0 KB)

@Amjad_Sahi,

i have one doubt, can we handle CellsException in our code ?
Right now we have are handling generic exception so i just wanted to handle the cellsException seperately. When i am creating one exception class extending CellsException , i saw we dont have any constructor in CellsException,
i am stuck here now
image.png (107.0 KB)

@hirekhan,

Please note, since your file is encrypted/password protected so when you use the following line of code to load the file, “com.aspose.cells.CellsException : Invalid password” is inevitable:
Workbook wb = new Workbook("f:\\files\\workbook_protected.xlsx");

See the following sample code that works fine and you may refer to it and try it:
e.g
Sample code:

FileFormatInfo info = FileFormatUtil.detectFileFormat("f:\\files\\workbook_protected.xlsx");
        if (info.isEncrypted())
        {
        	//since the file is protected, so you got to load it by specifying valid password in code.
        	com.aspose.cells.LoadOptions loadoptions = new com.aspose.cells.LoadOptions(com.aspose.cells.LoadFormat.XLSX);
            loadoptions.setPassword("test1");
            
        	Workbook wb = new Workbook("f:\\files\\workbook_protected.xlsx", loadoptions);
        	
        	System.out.println("loaded password procted file");
        }
        else
        {
		Workbook wb = new Workbook("f:\\files\\workbook_protected.xlsx");
		System.out.println("loaded file");
        }

@Amjad_Sahi,
Thank you again for the resolution. And i have one more question , I have catch the exception and trying to log with error message, but the ce.getMessage() method is not giving message like Invalid password. Do you have any idea about this?
catch (CellsException ce){
LOG.error("Error occurred due to detecting ContainsUnsupportedFeature in excel ", ce.getMessage());

Thank you

@hirekhan,
We have tried the scenario using following sample code but no issue is observed as exception is thrown properly for invalid password. Could you please test the following code and share feedback?

System.out.println("Product Version" + CellsHelper.getVersion());
try
{
       FileFormatInfo info = FileFormatUtil.detectFileFormat("workbook_protected.xlsx");
       if (info.isEncrypted())
    {
    //since the file is protected, so you got to load it by specifying valid password in code.
    com.aspose.cells.LoadOptions loadoptions = new com.aspose.cells.LoadOptions(com.aspose.cells.LoadFormat.XLSX);
    loadoptions.setPassword("test12");
    Workbook wb = new Workbook("workbook_protected.xlsx", loadoptions);

    System.out.println("loaded password procted file");
    }
else
{
    Workbook wb = new Workbook("c:\\test\\workbook_protected.xlsx");
    System.out.println("loaded file");
}
}
catch(CellsException ex)
{
	System.out.println("Exception:" + ex.getMessage());
}

Program Output
Product Version20.9.0
Exception:Invalid password.

If issue is not resolved, please share a sample runnable project which can be compiled and executed here to test the scenario.

actually i am using it in log statement
LOG.error("Error occurred due to detecting ContainsUnsupportedFeature in excel ", ce.getMessage());

in console it is printing "Error occurred due to detecting ContainsUnsupportedFeature in excel " till here only

@hirekhan,

Which version of the product you are using? As recommended, please try using latest version (Aspose.Cells for Java v20.9.x). If you still find the issue, as requested earlier, kindly provide a console Java program/code (runnable) so we could execute it to reproduce the issue, we will check it soon.

@hirekhan,
If you are using log4j etc. for your LOG class, please add {} in the first parameter and try again as follows:

LOG.error("Error occurred due to detecting ContainsUnsupportedFeature in excel: {}", ce.getMessage());