2017-07-16 61 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 –