1

I have a list type of object and i need to create a excel file which should required password to open that excel file in ASP.NET C#.

I have tried ClosedXML package but that is not working well. And also I have tried much more example but I didn't found any good example.

Please, If any one have done these type of example then please let me know.

Much Appreciation !

1
  • If it's an .xslx file - which is just a zip of xml files - you could try to unzip and then rezip it with a password. You should check if Excel supports this. Commented Aug 21, 2018 at 7:21

1 Answer 1

2

If you want an Excel password all you need is something like this:

using Microsoft.Office.Interop.Excel

//create your spreadsheet here...

WorkbookObject.Password = password;
WorkbookObject.SaveAs("spreadsheet.xls")

This requires Excel to be installed.

Sign up to request clarification or add additional context in comments.

10 Comments

Thanks for reply Mr. Hossein, I have tried that also but this is not working for me.
An exception of type 'System.Runtime.InteropServices.COMException' occurred in App_Web_x0oyenfd.dll but was not handled in user code this is the error when I am using Microsoft.Office.Interop.Excel
When I am creating a instance as Workbook workbook = new Workbook(); then system is through error
@JayantSharma This issue isn't caused by your code. Maybe your pc had both Office version on it, and after uninstalling once and rebooting, the issue was fixed
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.