2011-04-19 33 views
4

我有一個使用了一個名爲spreadsheetgear.dllC#到PowerShell的

DLL在Visual Studio C#程序我做了以下內容:

Reference the spreadsheetgear.dll 
SpreadsheetGear.IWorkbook workbook1 = 
    SpreadsheetGear.Factory.GetWorkbook("C:\text.xls"); 

這工作正常,在C#和Visual Studio

在PowerShell中,我創建了類似的邏輯是:

Add-Type -Path "C:\spreadsheetgear.dll" 
$workbook1 = New-Object SpreadsheetGear.Factory.GetWorkbook("c:\test.xls") 

但是PowerShell的給了我一個犯錯或說.... 新對象:找不到類型[SpreadsheetGear.Factory.GetWorkbook]:確保包含此類型的程序集已加載。

我在做什麼錯...請協助。

謝謝。

+0

澄清 - 這是powershell 1或2? [Reflection.Assembly] :: LoadFile需要返回1. – sclarson 2011-04-19 20:29:38

回答

4

您並未創建新對象 - 您正在調用靜態方法。嘗試:

[SpreadsheetGear.Factory]::GetWorkbook("c:\test.xls") 

GetWorkbook實際上是對SpreadsheetGear.Factory類型的方法 - 錯誤信息是完全正確的。

+0

謝謝 - 它按照你的建議工作! – Coder 2011-04-19 20:40:32