【发布时间】:2018-12-28 22:22:42
【问题描述】:
我希望在对另一列中的单元格值执行计算后更新我的 Excel 文件中的列。基本上,我会首先提示用户询问他们“是”或“否”的答案。如果他们说“是”,我需要向 Y 列中的所有单元格添加 100,并将输出放在 Z 列中。仅供参考,Y 列已经包含预填充的值。我目前正在生成错误
方法调用失败,因为 [System.DBNull] 不包含方法 命名为“op_Addition”。 在行:40 字符:13 + $cell.Value2 = $cell + $adjustment + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (op_Addition:String) [], RuntimeException + FullyQualifiedErrorId : MethodNotFound$adjustment = 100
$Question = Read-Host "Do you have money? "
while ($worksheet.Range("Y9:Y705") -ne $null) {
if ($Question -eq 'Yes' -or $Question -eq 'yes') {
foreach ($cell in $worksheet.Range("Y9:Y705").Text) {
$cell.Value2 = $cell + $adjustment
$row = 1
$column = 1
Write-Host $worksheet.Range("Z9:Z705").Item($cell.Value2).value()
}
}
}
【问题讨论】:
-
引用
Get-Help about_comparison_operators:By default, all comparison operators are case-insensitive. To make a comparison operator case-sensitive, precede the operator name with a "c".所以不需要区分是和是。 -
@LotPings 我明白了。我已经从我的代码中删除了比较。谢谢。但是,我想知道为什么我的计算会产生上述错误。谢谢
标签: excel powershell