2017-07-16 26 views
0

我有一个文件夹包含多个excell文件,我想搜索一个字符串,如“2501”和anf find文件有这个,然后输出它的文件名称到一个文件或显示)。我写了一些脚本并搜索了一些,但没有找到答案。如何在excell中使用powershell搜索字符串

我写了这个:

$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工作。

我会感谢所有帮助我的人。

+0

另一个例子,与txt文件的工作原理>>获取内容C:\脚本\ test.txt的|选择字符串“失败” – PouriaJalilian

+1

https://stackoverflow.com/questions/30200920/finding-content-of-excel-file-in-powershell –

回答

0

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

你也可能需要循环的文件夹中的每个搜索excel文件

+0

谢谢我的朋友 – PouriaJalilian

+0

我用这个:$ 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分隔文件 – PouriaJalilian

+0

不客气:) 我跟着我发给你的链接,它没有把excel文件转换成txt –

相关问题