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 !

ProgrammingLlama
  • 36,677
  • 7
  • 67
  • 86
Jayant Sharma
  • 11
  • 1
  • 2
  • 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. – ckuri Aug 21 '18 at 07:21

1 Answers1

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.

Hossein
  • 3,083
  • 3
  • 16
  • 33
  • Thanks for reply Mr. Hossein, I have tried that also but this is not working for me. – Jayant Sharma Aug 21 '18 at 06:20
  • @JayantSharma See this. https://www.c-sharpcorner.com/blogs/protecting-excel-files-programmatically – Hossein Aug 21 '18 at 06:22
  • *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 – Jayant Sharma Aug 21 '18 at 06:24
  • When I am creating a instance as Workbook workbook = new Workbook(); then system is through error – Jayant Sharma Aug 21 '18 at 06:26
  • @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 – Hossein Aug 21 '18 at 06:28
  • Some times through this error *Microsoft Office Excel cannot open or save any more documents because there is not enough available memory or disk space. • To make more memory available, close workbooks or programs you no longer need. • To free disk space, delete files you no longer need from the disk you are saving to.* – Jayant Sharma Aug 21 '18 at 06:30
  • @JayantSharma https://stackoverflow.com/questions/12415690/how-to-fix-microsoft-excel-cannot-open-or-save-any-more-documents?answertab=active#tab-top – Hossein Aug 21 '18 at 06:37
  • Do you have any-other solution or any other third party library? – Jayant Sharma Aug 21 '18 at 06:50
  • @JayantSharma Spire.XLS for .NET https://www.e-iceblue.com/Tutorials/Spire.XLS/Spire.XLS-Program-Guide/NET-Protect-Excel-Protect-Excel-Workbook-and-Worksheet.html – Hossein Aug 21 '18 at 07:38
  • @JayantSharma https://stackoverflow.com/questions/151005/create-excel-xls-and-xlsx-file-from-c-sharp?answertab=active#tab-top – Hossein Aug 21 '18 at 07:40