powershell-scriptからCorruptLoad
パラメーターでexcelファイルを開く必要があります。しかし、私がそれをしようとすると、私はエラーException calling "Open" with "15" argument(s): "open method workbooks class failed"
を取得します。このエラーはとなり、私はOpen
と15個の引数をすべて呼び出します。そして、私が15の引数を持つVB.net
プログラムで同じエクセルファイルを開こうとすると、または名前付き引数の値を指定してCorruptLoad
、問題はありません!powershellでエラーを開くときにエラーが発生する
私はpowershell v 4.0
、Office 2010 SP2および.NET Framework 4.5.2
を使用しています。エラーが発生した理由を、私は考えていない
$excel = New-Object -ComObject Excel.Application
$excel.Visible = $false
try
{
$missing = [System.Type]::Missing
# $wb = $excel.Workbooks.Open("d:\temp\start_instrument.xls", $missing, $missing, $missing, $missing,
# $missing, $missing, $missing, $missing, $missing,
# $missing, $missing, $missing, $missing, $missing)
# $wb = $excel.Workbooks.Open("d:\temp\start_instrument.xls", $missing, $missing, $missing, $missing,
# $missing, $missing, $missing, $missing, $missing,
# $missing, $missing, $missing, $missing, 1)
$XlCorruptLoad = "Microsoft.Office.Interop.Excel.XlCorruptLoad" -as [type]
$wb = $excel.Workbooks.Open("d:\temp\start_instrument.xls", $missing, $missing, $missing, $missing,
$missing, $missing, $missing, $missing, $missing,
$missing, $missing, $missing, $missing, $XlCorruptLoad::xlRepairFile)
}
catch
{
Write $Error[0].ToString()
}
# some stuff
if ($excel -ne $null)
{
$excel.Quit()
[System.Runtime.InteropServices.Marshal]::ReleaseComObject($excel) | Out-Null
$excel = $null
}
[System.GC]::Collect() | Out-Null
[System.GC]::WaitForPendingFinalizers() | Out-Null
:
は、ここに私のpowershell
コードです。私はどんなアドバイスや前提にもうれしく思います!
を参照してください?あなたは '$ missing'としてそれを持っていますか? https://msdn.microsoft.com/en-us/library/office/ff193596.aspx。 – Matt
@Matt、私は 'Open'関数を呼び出すすべての変種を試しました。コードサンプルを変更して表示しました。 – Indian
清算していただきありがとうございます。 – Matt