0

我正在尝试使用 IronPython 中的 EPPlus Dot Net 库来打开和更新 Excel 电子表格,但我无法建立对该库的引用。我不确定问题是否出在我的代码中,我对引用 Dot net 库的理解(这是非常基本的),我下载和“安装”dll 的方式,或者它是否与 IronPython 不兼容。

有人可以建议我如何从 IronPython 引用这个库吗?

这是我的python代码:

import sys
from collections import OrderedDict
sys.path.append(r'C:\EPPlus')
import clr
clr.AddReference('WindowsBase')
clr.AddReferenceToFile('EPPlus.dll')  # Fails here.

代码失败clr.AddReferenceToFile('EPPlus.dll')

Traceback (most recent call last):
  File "auction_support_epp.py", line 6, in <module>
IOError: System.IO.IOException: Could not add reference to assembly EPPlus.dll
   at IronPython.Runtime.ClrModule.AddReferenceToFile(CodeContext context, Strin
g file)
. . .

这是 C:\EPPlus 的目录列表:

 Directory of c:\EPPlus

10/11/2012  12:50 PM    <DIR>          .
10/11/2012  12:50 PM    <DIR>          ..
10/11/2012  12:35 PM           608,256 EPPlus.dll
               1 File(s)        608,256 bytes
               2 Dir(s)  137,501,888,512 bytes free

我通过下载库的分发 zip 并将文件剪切并粘贴到我使用 Windows 资源管理器创建的 EPPlus 文件夹中来创建 EPPlus.dll。

4

1 回答 1

1

通过在 Windows 资源管理器中检查 EPPlus.dll 文件的属性,我发现该文件已被操作系统“阻止”,因为它知道它来自另一台计算机,因此具有潜在危险。单击“取消阻止”按钮使 IronPython 可以访问该文件。

谢谢,微软!

于 2012-10-11T17:30:53.173 回答