我正在尝试删除xls文件的一列中的行,该行不包含特定数字:
before:
a | b | c
1 2 3
1 3 5
2 6 4
1 2 5
after:
a | b | c
2 6 4
我以前一直在寻找解决方案,但是我看到的所有解决方案都是针对csv文件的。
我尝试的解决方案是:
$needle = '1'
$caseSensitive = 'false'
$column = $excel.Range('M').EntireColumn.Cells
$deleteRange = $null
$found = $column.Find($needle, [type]::Missing, [type]::Missing, [type]::Missing, [type]::Missing, [type]::Missing, $caseSensitive)
$firstAddress = $found.Address()
if (-not $found) {
do {
if ($deleteRange) {
$deleteRange = $excel.Application.Union($deleteRange, $found.EntireRow.Cells)
} else {
$deleteRange = $found.EntireRow.Cells
}
$found = $column.FindNext($found)
} while ($found -and ($found.Address() -ne $firstAddress))
}
但这不会按照我的想法过滤列。