保护code在Excel工作簿? [英] Protecting Code in an Excel Workbook?

查看:119
本文介绍了保护code在Excel工作簿?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要产生一个Excel工作簿将包含专有公式和其他知识产权。我将最有可能产生这种工作簿在Visual Studio 2010中使用C#。

I want to produce an Excel workbook that will contain proprietary formulas and other intellectual property. I will most likely produce this workbook in Visual Studio 2010 with C#.

如何保护是这些项目中的code?不要在C#中反射着同样的问题仍然适用于这些工作簿的项目?如果是这样,是否有混淆工具专为这些类型的工作簿?

How protected is the code within these projects? Do the same problems with reflection in C# still apply to these workbook projects? If so, are there obfuscation tools specifically for these types of workbooks?

要加入到这个问题 - 怎么样好OLE VBA?是否有保护code太多,如果我们走的路线VBA的方式?

To add to this question - what about good 'ole VBA? Is there a way to protect that code too if we were to go the VBA route?

推荐答案

至于其他的答案都建议,在Excel 2003(.xls的)VBA的安全性是有缺陷的;密码是只有一点点的烦扰,最多比不为developper本人。恕我直言,你就要去与VSTO绝对更好,即使在Excel VBA安全2007+(.xlsx)格式要好很多,更不用说VBA IDE已经没有看到改善世纪(虽然没有真真切切的与正确的VBE加载... )。

As other answers have suggested, VBA security in Excel 2003 (.xls) is flawed; a password is only a little annoyance, most often than not for the developper himself. IMHO you're absolutely better off with VSTO, even if VBA security in Excel 2007+ (.xlsx) is much better, not to mention the VBA IDE which hasn't seen improvements in centuries (although no so true with the right VBE add-in...).

一个解决办法是写在你的VSTO的项目需要一个单独的库懂事code;而不是复杂的公式的你可以公开的功能的这将显示为黑盒子(即公式的功能的抽象);它是如何实现的是不提供给任何人没有源$ C ​​$ C),没有工作簿无法计算的DLL(将#NAME?遍的地方)。

A solution could be to write the sensible code in a separate library which your VSTO project calls; instead of intricate formulas you could expose functions which would appear as "black boxes" (i.e. an abstraction of the formula's functionality); how it's implemented is just not available to anyone without the source code), and without the dll the workbook couldn't be calculated (would be #NAME? all over the place).

例如,而不是 =一些专有的公式返回一个蓝精灵,用户将看到 =蓝精灵(SomeTableColumnName,SomeRangeName,SomeRangeReference,SomeCellReference)。当然,这是以性能为代价,所以我只能这样做的东西,是的真正的重要保障。

For example, instead of =some proprietary formula returning a Smurf, users would see =Smurf(SomeTableColumnName, SomeRangeName, SomeRangeReference, SomeCellReference). Of course this comes at a performance cost, so I would only do this for stuff that's really important to protect.

我认为,设法从这样一个上的边库的专有配方用户,值得与他们离开 - 这和Alt + F11之间,有相当的步骤;专有code是为受保护为任何其他.NET程序集。

I think a user that manages to extract the proprietary formulas from such an on-the-side library, deserves to leave with them - between that and Alt+F11, there's quite a step; the proprietary code is as "protected" as any other .net assembly is.

更新

仍然没有使用任何第三方库,如果的专有code 的不的需求的Excel中的互操作性,一个也许是更好的解决方案可能是创建的功能的在VBA(即离开的 Excel的互操作的在Excel中的一部分),只有通过原始类型(VBA 整数 => .NET 的Int16 ; VBA => .NET 的Int32 ,字符串等)到甚至不需要使用Excel互操作一个COM可见库;这将是COM互操作代替Excel互操作和性能损失会显著减少,但仍present(它仍然.NET托管code会说话的非托管COM)。

Still without using any 3rd-party libraries, if the proprietary code does not need Excel interoperability, a perhaps better solution could be to create the function in VBA (i.e. leave the Excel interop part within Excel) and only pass primitive types (VBA Integer => .net Int16; VBA Long => .net Int32, strings, etc.) to a COM-visible library which doesn't even need to use Excel interop; it will be COM interop instead of Excel interop and the performance hit would be significantly reduced, though still present (it remains .net managed code "talking" to unmanaged COM).

在VBA code的职责是读取和工作表写入/,和COM可见图书馆的作用是落实造出来的VBA code传递的值的计算;当然VBA code是很容易接触到用户(Alt + F11),但他们又无法访问实际计算的实现。然后VBA code可能是密码保护,以及计算结果没有DLL是,要么 0 的或#VALUE! ,这取决于如何在VBA code实现的。

The VBA code's responsibility would be to read and write to/from the worksheets, and the COM-visible library's role would be to implement the calculations to be made out of the values passed by the VBA code; of course the VBA code would be easily accessible to the user (Alt+F11), but again they couldn't access the actual calculation implementation. And then the VBA code could be password-protected, and the calculation results without the DLL would be either 0's or #VALUE!, depending on how the VBA code is implemented.

关键是要的在Excel离开Excel的细节的和具有.net库拿起它不必引用的Excel互操作程序集 - 例如,VBA函数会采取一个单元格引用,抢它的价值(或许验证它),并把它传递给.NET程序集,这将返回另一个基本类型的VBA将返回到Excel。

The key is to leave Excel-specifics in Excel and have the .net library pick up where it can without referencing Excel interop assemblies - for example, the VBA function would take a cell reference, grab its value (perhaps validate it) and pass it to the .net assembly, which would return another primitive type that VBA would return to Excel.

另一个好处是,与专有的计算库code,可以重复使用,如果你是转换Excel工作簿到,比方说,一个Web应用程序。

Another plus is that the library code with the proprietary calculations could be reused, if you ever were to "convert" the Excel workbook into, say, a Web application.

这篇关于保护code在Excel工作簿?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆