We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Loading a password protected encrypted file via Aspose.Cells in .NET

Hi,

We are using ASPOSE.Cells 16.11.0 (.Net version)

When we try to open the memory stream (that contains an excel sheet), we get error invalid password.
Tried printing the password and it looks correct and were able to open the excel book locally using that password. Are we using the api wrongly?

public Workbook LoadFile(MemoryStream mstream, LoadFormat flType, String password)
{
try
{
//Check if the file is valid.
if (mstream == null) { throw new ApplicationException(“Stream is null!”); }
LoadOptions options = new LoadOptions(flType);
if (!String.IsNullOrEmpty(password)) { options.Password = password; }
Workbook workbook = new Workbook(mstream, options);
return workbook;
}
catch (Aspose.Cells.CellsException ce) { throw TemplateException.TranslateException(ce); }
catch (ApplicationException aa) { throw TemplateException.TranslateException(aa); }
catch (Exception ee) { throw TemplateException.TranslateException(ee); }
}

@ksnaspose

Thanks for using Aspose APIs.

Please provide us your problematic Excel file for our testing. Please also download and try the most recent version and see if it makes any difference and resolves your issue.

We’re still using .NET 3.5 Do you have a .NET 3.5 version?

We read it in the client and try to open the memory stream in server.
For your info, we have a macro and that has been removed for simplicity.

@ksnaspose,

Thanks for the providing us template file.

Please also provide us the password for the encrypted file, so we could evaluate your issue on our end.

Moreover, we recommend you to kindly install our latest verson/fix: Aspose.Cells for .NET v18.4 @ Nuget repos. and get your desired .NET framework compiled assembly (in the folder e.g “.\packages\Aspose.Cells.18.3.0\lib\net35” in your project) for your needs

Oops, was about to type it. the password is test

@ksnaspose,

Thanks for the password.

After an initial test, I am able to observe the issue as you mentioned by using the following sample code with his template file. I found a different exception, i.e., “File is corrupted” when opening the encrypted Excel file:
e.g
Sample code:

 LoadOptions loadoptions = new LoadOptions(LoadFormat.Xlsx); 
            loadoptions.Password = "test"; 

            Workbook workbook = new Workbook("e:\\test2\\test.xls", loadoptions); 

I have logged a ticket with an id “CELLSNET-46081” for your issue. We will look into it soon.

Once we have an update on it, we will let you know here.

Thanks for the link

Is it ok to load xls file with LoadFormat.xlsx?

@ksnaspose,

Please accept my apologies, I made a mistake in my code, the correct should be like following which resolves the issue:
e.g
Sample code:

 LoadOptions loadoptions = new LoadOptions(LoadFormat.Excel97To2003);
            loadoptions.Password = "test";
        
            Workbook workbook = new Workbook("e:\\test2\\test.xls", loadoptions); 

I have closed the ticket as it is not an issue with the APIs.

Please try our latest version/fix: Aspose.Cells for .NET v18.4 (the link is already provided in the previous post) and let know your feedback.

Is it an issue in .NET v16.11? so do we need to upgrade the licence to use the latest aspose?

@ksnaspose,

Yes, if it is not working in v16.11 but works in latest version/fix, then surely it was an issue in older version which was fixed in newer versions.

Regarding upgrade your subscription/licensing, please open your license file into notepad (please do not update anything in the license file least it will not work anymore) and check its subscription expiry date. If your subscription expiry date is greater than latest version’s (e.g v18.4.x) release date, then you may use it without any new license or upgrading your existing subscription. If it is less than it, then I am afraid, you have to upgrade your subscription. What is the expiry date of your subscription?

FYI, when you purchase a license for the product, you are authorized to use the license file with any new (and upcoming (official versions)) versions or hot fixes of the component for the next whole year. Moreover, your license will never expire if you continue to use your license with the product’s version/hotfix that should be released before your subscription expiry date.

It looks like your subscription is expired. Also, if you upgrade your subscription now, you can use any new/upcoming versions/fixes of the product for the next whole year for free.

We tried the latest version ASPOSE 18.4 and noticed a strange behavior.
we email excel sheet generated using aspose to our clients.
in our internal testing,
1) when we save the attachment and upload the xls file, it works fine.
2) when we open the xls file from the mail client (outlook 2011) and save, it prompts it is read only and we give a file name and save it to local disk.. When we upload this xls sheet, it complaints the file has corrupted.

So not sure what’s going wrong. Could you please investigate?

To add the one we got from nuget install is Aspose.cells 18.4

@ksnaspose,

We are not sure about your issue. If 1) is fine then 2) should also be fine. I do not think the issue is with Aspose.Cells APIs. Anyways, if you still think it is an issue with Aspose.Cells, kindly do create a sample console application (runnable) using v18.4.x with all the steps involved, zip the project and provide us here (you may exclude Aspose.Cells assembly) to reproduce the issue on our end, we will check it soon.

Hi,

What is the difference between the following APIs

// book.BuiltInDocumentProperties.Comments = “test comments”;
// book.CustomDocumentProperties.Add(“uid”, 100);
// book.Settings.Password = “test”; —> originally used this
book.ProtectSharedWorkbook(“test”); --> changed to below

Seems when I use the second api, things working. Also I suspect the built in and custom document properties causing something to break.

seems book.ProtectSharedWorkbook(“test”); is not setting the password at all.

I am lost. could you please help. Thanks.

Related to this >> Issue reported earlier

@ksnaspose

Thanks for using Aspose APIs.


BuiltInDocumentProperties

These are predefined properties provided by Microsoft Excel. Key Name exists already but Key Value is provided by you.

CustomDocumentProperties

These are not predefined and you add them. You provide both Key Name and Key Value by yourself.

Please see these articles for more detail about both of them.


Workbook.Settings.Password

This is use to protect your Excel file with password. In the following document, Excel file is password protected and it also explains how to specify encryption for protection.


ProtectSharedWorkbook

This is not for normal Excel files but for those Excel files which are shared on network with multiple users. Please see this document for more help.

We investigated further and the same code works ( ability to open the excel file with password) in

Windows 7 professional standard but not in Windows Server 2008 R2 Standard (service pack 1).
Is there any dependency on OS, culture info etc., ? Thanks.

@ksnaspose

Thanks for using Aspose APIs.

Please try the following code with the most recent version and let us know your feedback. Please also try the code with Book1.xls provided by us.

Download Link:
Input-Book1.zip (16.1 KB)

C#

String ver = CellsHelper.GetVersion();

Console.WriteLine("Aspose.Cells Version: " + ver);

string fileName = "test.xls";

FileFormatInfo finf = FileFormatUtil.DetectFileFormat(fileName);

LoadOptions opts = new LoadOptions(finf.LoadFormat);
opts.Password = "test";

byte[] bts = File.ReadAllBytes(fileName);
MemoryStream ms = new MemoryStream(bts);

Workbook wb = new Workbook(ms, opts);
wb.Save("output.pdf");

Hi,
Sorry as requested, will you be able to provide a .NET 3.5 version of Aspose 18.4.3