Free Support Forum - aspose.com

Excel Password in Opening the File

Hi,

Is there a possibility of setting the excel password in opening the file so that it will prompt the user.Right now there is a option of ProtectionType.MODIFY_FILE but the problem is it has a read only Option while prompting the user.

Could you please tell me,is it possible to protect the file without any readonly option granted.

Regards

Joe

Hi Joe,

Thanks for considering Aspose.

For java version of Aspose.Cells, you may use ProtectionType.OPEN_FILE option and for .NET version you may utilize Workbook.Password property.

May the following code help you for your need, kindly consult it.

i).(java) Workbook workbook = new Workbook();
workbook.protectFile(ProtectionType.OPEN_FILE,"009");
workbook.save("e:\\Files\\testprotect.xls");


ii).(C#) Workbook workbook = new Workbook();
workbook.Password = "1234";
workbook.Worksheets[0].Cells["A1"].PutValue("Hello World!");
workbook.Save("e:\\Files\\protectionfiletest.xls");

Thank you.

Hi,

Thanks for the reply.But the exception that i am getting is this.

Exception in thread "main" com.aspose.cells.CellsException: Unsupports to set the opening file password.

at com.aspose.cells.r.a(Unknown Source)

at com.aspose.cells.Workbook.protectFile(Unknown Source)

at com.source.TestAspose.main(TestAspose.java:18)

When i try to set the password to the workbook it doesn't allow for it.Could you please give some highlight on it.I am using the Java version.

Thanks

Joe

Hi,

Did you try my java code, it works fine here. And which version of Aspose.Cells for java you are using, please try the attached version.

If you still find some problem, post your sample code here.

Thank you.

Hi,

This is the code snippet which i am using.I am using the evaluation version of Aspose 1.9 Java version.Please let me know.I am using the same code which u have sent.Attaching my code here

package com.source;

import java.io.BufferedOutputStream;

import java.io.File;

import java.io.FileOutputStream;

import java.io.OutputStream;

import com.aspose.cells.ProtectionType;

import com.aspose.cells.Workbook;

import com.aspose.cells.Worksheet;

public class TestAspose {

public static void main(String[] args) throws Exception {

Workbook book = new Workbook();

Worksheet s = book.getWorksheets().addSheet("Test");

s.getCells().getCell(1, 1).setValue("Cell Contents");

book.protectFile(ProtectionType.OPEN_FILE, "myPassword");

File f = new File("output.xls");

OutputStream out = new BufferedOutputStream(new FileOutputStream(f));

book.save(out);

out.flush();

out.close();

}

}

Please let me know what is the issue.

Thanks

Joe

Hi Joe,

I tested your code, it worked fine and give the correct result, an excel file with password protected when openning. In my test, i use Aspose 1.9.0.3 for java and jdk1.4.

Hi,

Thanks for your quick reply.Could you please direct me to download the package that your using for testing.

Because i could not see the version that you have mentioned.Please send me the link.I really appreciate your help.

Thanks

Joe

Hi,

Please try the version which I attached in my previous post in this thread. I tried your code using the version and it works fine.

Thank you.

Hi,

I could not see the version in download section.I am able to see only Aspose 1.9.0 in the evaluation downloads section which is the latest.Please give me the link which i need to use to download the appropriate version(1.9.3) .Otherwise clarify is it because i am using the evaluation version.

Thanks

Joe

Hi Joe,

I tested the latest version Aspose 1.9.0 in the evaluation downloads section, it do give an error. Please use the version Amjad has given in the reply at 11-06-2007, 10:59 AM for this topic by download the attachment, it works right. see http://www.aspose.com/Community/Forums/permalink/101658/101428/ShowThread.aspx#101428

Hi Joe,

And to check the version no (which version you are using) at runtime you may use the api a line of code in your class as well.

E.g.,

System.out.println(CellsHelper.getReleaseVersion());

Thank you.