[英]Powershell script not working (Misspelling Project)
$app = New - Object - ComObject 'Word.Application'
$app.visible = $true
$doc = $app.Documents.Add(
}
$doc.Content.text = 'Here's an exmple of mispeled txt."
$selection = $app.Selection
$report = @(
}
foreach($word in ($doc.Words | Select - ExpandProperty Text)) {
if (!($app.CheckSpelling($word))) {
$result = New - Object - TypeName psobject - Property @(Mispelled = $word)
$sug = $app.GetSpellingSuggestions($word) | Select - ExpandProperty name
if ($sug) {
$report += New - Object psobject - Property @ {
Misspelled = $word;
Suggestions = $sug
}
} else {
$report += New - Object - TypeName psobject - Property @ {
Misspelled $word; =
Suggestions "No Suggestion"
}
}
}
}
$Sreport | Select - Property Misspelled, Suggestions
Hello.你好。 I found this script online, from which I'm trying to output a list of misspelled English words together with their spelling recommendations, using MS Word's spelling corrections via Powershell.
我在网上找到了这个脚本,我试图通过 Powershell 使用 MS Word 的拼写更正输出一个拼写错误的英语单词列表及其拼写建议。 I don't have coding knowledge, so I don't know why isn't the script working.
我没有编码知识,所以我不知道为什么脚本不起作用。 Could someone help me out?
有人可以帮我吗? Thanks!
谢谢!
This works, i think!这行得通,我想! You didnt mention the output you wanted so hope this is ok.
你没有提到你想要的输出,所以希望这没问题。
You were on the right track but had some syntax and bracket issues你在正确的轨道上,但有一些语法和括号问题
$app = New-Object -ComObject 'Word.Application'
$app.visible = $false
$doc = $app.Documents.Add()
$doc.Content.text = Get-Content "C:\Temp\TestFile.txt" # This will get the text of the file specified
$selection = $app.Selection
$report = @() # an empty array which we will fill with spelling mistakes
foreach($word in ($doc.Words | Select -ExpandProperty Text)) { # loop through each word in the text
# if the word is misspelled then process it
if (!($app.CheckSpelling($word))) {
# get list of correction suggestions for this word
$suggestion = $app.GetSpellingSuggestions($word) | Select -ExpandProperty name
# if there are suggestions then add it to the report
if ($suggestion) {
$report += New-Object psobject -Property @{
Misspelled = $word;
Suggestions = $suggestion
}
}
# else if there are no suggestions then add an entry saying just that
else {
$report += New-Object -TypeName psobject -Property @{
Misspelled = $word;
Suggestions = "No Suggestion"
}
}
}
}
# push the results to a file
$report | Out-File "C:\Temp\results.txt"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.