首页 > 解决方案 > GetValueInvocationException 从 Excel 电子表格中读取单元格

问题描述

这是我遇到的一个非常奇怪的错误。我正在从 Excel 电子表格中读取字段,一切正常。然后我添加了另一列来阅读,但它不再起作用了。

$columnIn = 8
$columnHa = 7
$ExcelSheet.Cells.Item($row,$columnIn).text
$ExcelSheet.Cells.Item($row,$columnHa).text
# These are working quite fine, but when I add
$columnRe = 5
$ExcelSheet.Cells.Item($row, $columnRe).text
# This is the annoying error: GetValueInvocationException

这已经很奇怪了,然后我$columnRe在调用中而不是值 5Item($row,5).text并且它起作用了!之后,我将作业更改为演员表:

[int] $ColumnInsight = 6
[int] $ColumnHashtag = 7
[int] $ColumnTypeOfReporter = 5 

这也很好用。最后我取消了演员阵容,转身回到

$ColumnInsight = 6
$ColumnHashtag = 7
$ColumnTypeOfReporter = 5

并且......现在它起作用了。为什么?

我什至关闭了 PowerShell ISE 并重新打开它,重新加载了应用程序,但现在它继续正常工作。和以前一样的代码。

标签: excelpowershell

解决方案


推荐阅读