Spire.XLS is a professional Excel API that enables developers to create, manage, manipulate, convert and print Excel worksheets. Get free and professional technical support for Spire.XLS for .NET, Java, Android, C++, Python.

Thu Jul 22, 2021 3:34 pm

So this may seem like an unusual situation, but I have had several users encounter this issue recently under similar circumstances...They have .XLS spreadsheets which are actually in .XLSX format (take any .XLSX spreadsheet and change the extension to .XLS). I (nor the users) can establish why the spreadsheets have the wrong extension for their format but unfortunately, they do...

The rest of the Spire.XLS library deals with this without a problem and loads the spreadsheet, understanding that it is actually a .XLSX in disguise.

Unfortunately though, Workbook.IsPasswordProtected does not understand and rather than throwing an exception or giving any other indication, it falsely returns true.

The recreation code is simply:

Code: Select all
public void TestForPassword(string strSource)
{
    return(Workbook.IsPasswordProtected(strSource));
}


Where the strSource contains the file name for a file that has been created as described above.

wraydc
 
Posts: 130
Joined: Wed Apr 11, 2018 5:14 am

Fri Jul 23, 2021 2:46 am

Hello,

Thanks for your inquiry.
I simulated an excel file to test your code, and did reproduce your issue. I have logged the issue into our Bug tracking system with the ticket number SPIREXLS-3366. Our development team will investigate and fix it. Once it is resolved, I will inform you. Sorry for the inconvenience caused.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Jul 23, 2021 8:49 am

I have done some further investigation that may be useful to you or anyone else experiencing the issue.

This is a longer post, but I hope it is useful.

What I have discovered is that when an incorrectly extensioned and password-protected file is loaded, it will have 0 sheets, this is obviously not usual so this can be used to detect and resolve the issue.

The version number reported by Spire seems to be correct when the file extension is incorrect at least for non-passworded files.

If a password-protected file with the wrong file extension is reloaded, this time specifying the version information from the previous attempt, the file will correctly report if the file is password-protected or at least give a password related exception.

.\XLSX with XLS Extension.xls
IsPasswordProtected Reports: True
Workbook has opened successfully, and reports version as Version2016
Sheet Count:2

.\XLS with XLSX Extension.xlsx
IsPasswordProtected Reports: False
Workbook has opened successfully, and reports version as Version97to2003
Sheet Count:2

.\XLSX with XLS Extension with Password.xls
IsPasswordProtected Reports: False
Workbook has opened successfully, and reports version as Version97to2003
Sheet Count:0
Attempting Reload
sprᵷ: Invalid password.
at sprᶺ.ᜀ(sprᦫ A_0)
at sprᶺ.ᜀ(String A_0, sprᵁ A_1)
at sprᶺ..ctor(String A_0, sprᵁ A_1)
at Spire.Xls.Core.Spreadsheet.XlsWorkbook..ctor(Object A_0, String A_1, ExcelVersion A_2)
at Spire.Xls.Workbook.LoadFromFile(String fileName, ExcelVersion version)
at SpireCurrentTests.UnitTest1.WorkbookLockedTest() in UnitTest1.cs:line 139

.\XLS with XLS Extension with Password.xls
IsPasswordProtected Reports: True
sprᵷ: Please provide password for the Workbook file.
at sprℂ.᜼(spr⃸ A_0)
at sprℂ.ᜀ(MemoryStream A_0)
at sprℂ.ᜀ(sprᦫ A_0)
at sprᶺ.ᜀ(String A_0, sprᵁ A_1)
at sprᶺ..ctor(String A_0, sprᵁ A_1)
at Spire.Xls.Core.Spreadsheet.XlsWorkbook..ctor(Object A_0, String A_1, ExcelVersion A_2)
at Spire.Xls.Workbook.LoadFromFile(String fileName, ExcelVersion version)
at SpireCurrentTests.UnitTest1.WorkbookLockedTest() in UnitTest1.cs:line 124

.\XLSX with XLSX Extension with Password.xlsx
IsPasswordProtected Reports: True
sprᵷ: Invalid password.
at sprᶺ.ᜀ(sprᦫ A_0)
at sprᶺ.ᜀ(String A_0, sprᵁ A_1)
at sprᶺ..ctor(String A_0, sprᵁ A_1)
at Spire.Xls.Core.Spreadsheet.XlsWorkbook..ctor(Object A_0, String A_1, ExcelVersion A_2)
at Spire.Xls.Workbook.LoadFromFile(String fileName, ExcelVersion version)
at SpireCurrentTests.UnitTest1.WorkbookLockedTest() in UnitTest1.cs:line 124

.\XLS with XLS Extension.xls
IsPasswordProtected Reports: False
Workbook has opened successfully, and reports version as Version97to2003
Sheet Count:2

.\XLSX with XLSX Extension.xlsx
IsPasswordProtected Reports: False
Workbook has opened successfully, and reports version as Version2016
Sheet Count:2


Here is the test code.
Code: Select all
        public void WorkbookLockedTest()
        {
            string[] strFalseXLS =
            {
                @".\XLSX with XLS Extension.xls",
                @".\XLS with XLSX Extension.xlsx",
                @".\XLSX with XLS Extension with Password.xls",
                @".\XLS with XLS Extension with Password.xls",
                @".\XLSX with XLSX Extension with Password.xlsx",
                @".\XLS with XLS Extension.xls",
                @".\XLSX with XLSX Extension.xlsx"
            };

            foreach (string strCurrent in strFalseXLS)
            {
                bool blPasswordProtectedStatus = Workbook.IsPasswordProtected(strCurrent);

                Console.WriteLine($"\n\n{strCurrent}\nIsPasswordProtected Reports: {blPasswordProtectedStatus}");

                try
                {
                    Workbook wbWorkbook = new Workbook();

                    wbWorkbook.LoadFromFile(strCurrent);
                    wbWorkbook.UnProtectWorkbook("");

                    Console.WriteLine($"Workbook has opened successfully, and reports version as {wbWorkbook.Version}");
                    Console.WriteLine($"Sheet Count:{wbWorkbook.Worksheets.Count}");

                    int iWorksheetCount = wbWorkbook.Worksheets.Count;
                    ExcelVersion evExcelVersion = wbWorkbook.Version;
                    wbWorkbook.Dispose();

                    if (iWorksheetCount == 0)
                    {
                        wbWorkbook = new Workbook();

                        Console.WriteLine("\tAttempting Reload");
                        wbWorkbook.LoadFromFile(strCurrent, wbWorkbook.Version == ExcelVersion.Version97to2003 ? ExcelVersion.Version2016 : ExcelVersion.Version97to2003);

                        Console.WriteLine($"\tWorkbook has opened successfully, and reports version as {wbWorkbook.Version}");
                        Console.WriteLine($"\tSheet Count:{wbWorkbook.Worksheets.Count}");
                        wbWorkbook.Dispose();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                }
            }
        }

wraydc
 
Posts: 130
Joined: Wed Apr 11, 2018 5:14 am

Fri Jul 23, 2021 9:45 am

Hello,

Thank you for your survey information.
I will report this findings to our developers. Once the problem is resolved, I will inform you immediately. Thanks again for your investigation.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Jul 26, 2021 8:26 am

Some more information. If you attempt to load the spreadsheet with a specified version (incorrect or otherwise) for example:

Code: Select all
wbSource.LoadFromFile(strSourceFile, ExcelVersion.Version2016);


It appears to offer a potential solution as it will correctly throw an incorrect password type exception - I thought this was a viable workaround, however, it leaves the library in an unstable state and the next time a spreadsheet is loaded and worked on (must be more than loaded), the library appears to fail in unmanaged code as the .net application doesn't catch the exception and the application closes immediately.

The event viewer log of the event reports the following:

Framework Version: v4.0.30319
Description: The process was terminated due to an unhandled exception.
Exception Info: System.NullReferenceException
at Spire.Xls.Core.Spreadsheet.XlsWorkbook.Dispose()
at Spire.Xls.Core.Spreadsheet.XlsObject.Finalize()

wraydc
 
Posts: 130
Joined: Wed Apr 11, 2018 5:14 am

Mon Jul 26, 2021 10:05 am

Hello,

Thank you for further sharing your investigation.
The good news is that our development team has solved the raised issue, and it is going to test phase now. If the test goes well, we will provide a hotfix for you as soon as possible.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Mon Jul 26, 2021 11:20 am

That is excellent news - I look forward to getting the updated release :)

wraydc
 
Posts: 130
Joined: Wed Apr 11, 2018 5:14 am

Tue Jul 27, 2021 8:33 am

Hi,

Okay, I will keep you informed once the new version is available.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Sat Sep 18, 2021 5:37 am

Hello,

Thanks for your patience.

Glad to inform you that the issue of ticket SPIREXLS-3366 has been resolved in the newly released Spire.Office Platinum(Hotfix) Version:6.9.1. Welcome to download the new version from the following links for testing.

Website link: https://www.e-iceblue.com/Download/down ... t-now.html
NuGet link: https://www.nuget.org/packages/Spire.Office/6.9.1

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Fri Oct 08, 2021 7:32 am

Hello,

Hope you are doing well!
Have you tried the new version of Spire.Office? Is the issue resolved now? Any feedback will be greatly appreciated.

Sincerely,
Annika
E-iceblue support team
User avatar

Annika.Zhou
 
Posts: 1657
Joined: Wed Apr 07, 2021 2:50 am

Wed Oct 04, 2023 12:01 pm

Hi,

I think I have the same issue with the 13.9.1 Spire.XLS paid version that was supposed to fix the problem.

For me, the "IsPasswordProtected" property of a Worksheet always returns false (XLSX file).
Calling "myWorksheet.Protect("myPassword");" does not change the value of the "IsPasswordProtected" property.
However, I can confirm the worksheet in the file is locked afterwards.

This has been tested and reproduced with a simple XLSX file created from File Explorer, so not from Spire.XLS.
The file contains two Worksheets created and renamed by hand too.
My computer is using the french culture, if that matters.

I have attached the test file.
Attachments
test.zip
(6.12 KiB) Downloaded 585 times
Last edited by olefebvre on Thu Oct 05, 2023 1:59 pm, edited 2 times in total.

olefebvre
 
Posts: 13
Joined: Wed May 26, 2021 11:36 am

Thu Oct 05, 2023 2:54 am

olefebvre wrote:Hi,

I think I have the same issue with the 13.9.1 Spire.XLS paid version that was supposed to fix the problem.

For me, the "IsPasswordProtected" property of a Worksheet always returns false (XLSX file).
Calling "myWorksheet.Protect("myPassword");" does not change the value of the "IsPasswordProtected" property.
However, I can confirm the worksheets in the file are locked afterwards.

This has been tested and reproduced with a simple XLSX file created from File Explorer, so not from Spire.XLS.
The file contains two Worksheets created and renamed by hand too.
My computer is using the french culture, if that matters.

I have attached the test file.

Hi olefebvre,

Thank you for your feedback regarding the issue you have encountered. We have conducted tests and have been able to replicate the issue you have mentioned. We apologize for any inconvenience this has caused you.

Specifically, when using password-protected sheets, the subsequent determination of whether a sheet has password protection has resulted in incorrect results. We have taken note of this issue and have logged it into our issue tracking system with the following ticket number: SPIREXLS-4922.

Thank you for your patience and understanding while we work to rectify this issue. If you have any further questions or concerns, please do not hesitate to contact us.

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Nov 27, 2023 6:28 am

olefebvre wrote:Hi,

I think I have the same issue with the 13.9.1 Spire.XLS paid version that was supposed to fix the problem.
...
I have attached the test file.


Hi olefebvre,

Thanks for your patience.
We are delighted to inform you that we just released Spire.Xls 13.11.4 hotfix, which has fixed the issue SPIREXLS-4922, please download from the following link and have a test.
Website: https://www.e-iceblue.com/Download/download-excel-for-net-now.html
Nuget: https://www.nuget.org/packages/Spire.XLS/13.11.4

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Mon Nov 27, 2023 4:26 pm

Hello,

It seems to be working now from what I can tell.
Thank you.

olefebvre
 
Posts: 13
Joined: Wed May 26, 2021 11:36 am

Tue Nov 28, 2023 1:39 am

olefebvre wrote:Hello,

It seems to be working now from what I can tell.
Thank you.

Hi olefebvre,

Thanks for your feedback.
Glad to hear that your issue has been fixed. If you have any other questions, just feel free to contact us. We are here to help.

Have a nice day!

Best regards,
Triste
E-iceblue support team
User avatar

Triste.Dai
 
Posts: 1000
Joined: Tue Nov 15, 2022 3:59 am

Return to Spire.XLS