[英]Protect Excel With Allow Sort and Allow Auto Filter C#
I'm using EPPLUS.dll for doing my excel works I tried to protect the worksheet using AllowSort and AllowAutoFilter Properties but it's not working.我正在使用EPPLUS.dll做我的 excel 工作我试图使用AllowSort和AllowAutoFilter属性保护工作表,但它不起作用。
worksheet.Protection.AllowSort = true;
worksheet.Protection.AllowAutoFilter = true;
worksheet.Protection.SetPassword("password");
worksheet.Protection.IsProtected = true;
I tried Below Code too but i didn't get my desired result我也试过下面的代码,但我没有得到我想要的结果
worksheet.Column(1).Style.Locked = true;
Epplus Lock Cells By default and Locking Cells will not Fix my Problem;默认情况下,Epplus Lock Cells 和 Locking Cells 不会解决我的问题; the only thing I need is a protected or read-only cell while sorting and Filtering Allowed
我唯一需要的是一个受保护或只读的单元格,同时允许排序和过滤
any help would be greatly appreciated.任何帮助将不胜感激。
Have you tried moving the worksheet.Protection.IsProtected = true;
您是否尝试过移动
worksheet.Protection.IsProtected = true;
to be the first statement in your block of code.成为代码块中的第一条语句。 Perhaps this is overriding your previous statements.
也许这覆盖了您之前的陈述。
https://github.com/pruiz/EPPlus/blob/master/EPPlus/ExcelSheetProtection.cs https://github.com/pruiz/EPPlus/blob/master/EPPlus/ExcelSheetProtection.cs
The below has worked for me in the past, as in it will protect the worksheet, ie make it read only以下内容过去对我有用,因为它将保护工作表,即使其只读
worksheet.Cells[worksheet.Dimension.Address].AutoFitColumns();
worksheet.Protection.IsProtected = true;
worksheet.View.FreezePanes(2, 1); // freeze header row
worksheet.Protection.AllowSort = true;
worksheet.Cells[worksheet.Dimension.Address].AutoFilter = true;
worksheet.Protection.AllowAutoFilter = true;
I think to password protect it, it has to be against the package not the worksheet.我认为密码保护它,它必须针对包而不是工作表。
So use the .Save overload if saving the package.因此,如果保存包,请使用 .Save 重载。
package.Save("password");
Or if you're saving as a ByteArray then或者,如果您要保存为 ByteArray,则
package.GetAsByteArray("password");
The only way i Found was, using Visual Basic Code inside of that Excel Document which locked right-click and copy-paste options.我发现的唯一方法是在 Excel 文档中使用 Visual Basic 代码,该代码锁定了右键单击和复制粘贴选项。 unfortunately before excel opens the documents, that asks something about dangerous scripts and offer to disable running scripts.
不幸的是,在 excel 打开文档之前,它会询问有关危险脚本的信息并提供禁用正在运行的脚本。 at last i was impossible in my case.
最后,在我的情况下,我是不可能的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.