Excel 来自HRESULT的PowerShell异常:0x800A03EC
欢迎任何帮助。 我正在使用PowerShell操作Excel工作表。出于某种原因,这是可行的Excel 来自HRESULT的PowerShell异常:0x800A03EC,excel,powershell,Excel,Powershell,欢迎任何帮助。 我正在使用PowerShell操作Excel工作表。出于某种原因,这是可行的 for($o = 1; $o -le $firstRowMes.Length + $dagenInDeMaand; $o++){ if($o -ne $exception) { $ws.Cells.Item($o, 3) = $firstRowMes[$index] $ws.Cells.Item($o, 4) = $betweenMes[$index] $ws.Cell
for($o = 1; $o -le $firstRowMes.Length + $dagenInDeMaand; $o++){
if($o -ne $exception)
{
$ws.Cells.Item($o, 3) = $firstRowMes[$index]
$ws.Cells.Item($o, 4) = $betweenMes[$index]
$ws.Cells.Item($o, 5) = $Lastmes[$index]
$ws.Cells.Item($o, 7) = "=C" + $o + "/F" + $o
$ws.Cells.Item($o, 6) = "=SUM(C" + $o + ":E" + $o + ")"
$index++
}
else
{
$exception = ($exception + $applicationArray.Length +1)
}
}
但事实并非如此
for($g = 1; $g -le $applicationArray.Length;$g++){
$index = 2
$begintrendGetallen = ""
for($i = 0; $i -le $eerstePeriode-1; $i++){
$begintrendGetallen = $begintrendGetallen + "G" + (1+$g+(9*$i)).ToString() + ";"
}
$ws.Cells.Item($index, 11).Formula = "=AVERAGE(" + $begintrendGetallen + ")"
$index++
}
如果我直接将输出插入excel,效果很好。
我得到的全部错误是:
HRESULT异常:0x800A03EC AtC:\Users\yniasr\Documents\Argenta\Autoreportdagen.ps1:202字符:5
+$ws.Cells.Item($index,11).Formula=“=AVERAGE(“+$begintrendGet…
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~br> +类别信息:操作停止:(:)[],COMException
+FullyQualifiedErrorId:System.Runtime.InteropServices.COMException 我在这里看到了一些关于它的帖子,但是他们的解决方案都不适用于我的代码
非常感谢!我怀疑是由于公式中的拖尾
;
造成的。请尝试使用$begintrendGetallen.trim(;”)
索引初始化应该在循环之外。否则,每当循环运行时,它都会被重新设置为2
$index = 2
for($g = 1; $g -le $applicationArray.Length;$g++){
$begintrendGetallen = ""
for($i = 0; $i -le $eerstePeriode-1; $i++){
$begintrendGetallen = $begintrendGetallen + "G" + (1+$g+(9*$i)).ToString() + ";"
}
$begintrendGetallen = $begintrendGetallen.trim(";")
$ws.Cells.Item($index, 11).Formula = "=AVERAGE(" + $begintrendGetallen + ")"
$index++
}
$i=0
在处理PowerShell/Excel时会产生不和谐,因为Excel使用非零数组时经常会遇到问题。不过,我认为这不会导致代码中出现任何问题