【问题标题】:How to search a string in an Excel using Powershell如何使用 Powershell 在 Excel 中搜索字符串
【发布时间】:2021-03-09 01:33:35
【问题描述】:

我有一个包含多个 Excel 文件的文件夹。我想搜索一个像“2501”这样的字符串,并找到我的哪个文件包含这个字符串,然后将它的文件名输出到一个文件(或显示它)。我写了一些脚本并用谷歌搜索但没有找到答案。

这是我写的:

$Location = "C:\1.xlsx"
$SearchStr = "Mike"
$Sel = Select-String  -pattern $SearchStr -path $Location  
If ($Sel -eq $null)
{
write-host "$Location does not contain $SearchStr" -ForegroundColor Cyan
}
 Else 
{
    write-host "Found  $SearchStr  `n$Se in $Location"
}

 Write-host "end" -ForegroundColor Yellow

这只有在我指定一个 txt 文件时才有效,它不适用于 Excel。

【问题讨论】:

标签: excel powershell


【解决方案1】:

这可能对https://gallery.technet.microsoft.com/office/How-to-search-text-in-e16373b8有帮助

您可能还需要循环文件夹以在每个 excel 文件中进行搜索

【讨论】:

  • 我用过这个:$str="26123" GET-CHILDITEM -recurse C:\txt*.txt | SELECT-STRING -pattern "\b$str\b" >>F:\Final.txt Write-Host Done -ForegroundColor Cyan ---------但我首先将 xlsx 文件转换为 txt-tab 分隔文件
  • 不客气 :) 我按照我发送给您的链接进行操作,无需将 excel 文件转换为 txt
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-02-14
  • 2020-05-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多