Jump to content

A Simple Spell Check


John117
 Share

Recommended Posts

0 = No Spelling Error

1 = Spelling Error

Just something I needed last night. Posting for the good of others. Needs work :-)

#Region ;Includes
#include <Word.au3>
#include <String.au3>
#include <Array.au3>
#EndRegion 
$oWordApp = _WordCreate("", 0, 0, 0)
$sString = "David Davidsdf 123 ?><"
_SpellCheck()
Func _SpellCheck()
    $SpellCheck = StringRegExpReplace($sString, "[0-9!@#$%^&*()?/<>,:;+-]", "")
    $SpellCheck2 = _StringExplode($SpellCheck, " ")
    _ArrayDisplay($SpellCheck2)
    For $s = 0 To UBound($SpellCheck2) - 1
        $oWordApp.Selection.TypeText($SpellCheck2[$s])
        $oWordApp.Selection.WholeStory
        ;$oWordApp.Selection.Range.SpellingErrors
        $Test = $oWordApp.Selection.Range.SpellingErrors
        If $Test.Count > 0 Then ConsoleWrite($SpellCheck2[$s] & " Appears to be mispelled" & @CRLF)
        $oWordApp.Selection.Delete
    Next
EndFunc   ;==>_SpellCheck
_WordQuit($oWordApp, 0)
Edited by Hatcheda
Link to comment
Share on other sites

It looks good but there is a potential for failure in the regexp replace. I'm assuming that uou want to catch the question mark. In that case it should be escaped. Better yet might be to use

$SpellCheck = StringRegExpReplace($sString, "[0-9[:punct:]]", "")

EDIT: The same thing applies to the "(" , ")" and "$", They need to be escaped. Try the code I have above.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Developers

Jos made a simple one with MS I believe then Big Daddy made an extensive one here

http://www.autoitscript.com/forum/index.ph...st&p=219029

It appears Jos's code is not available. But the one above might help here...???

8)

Not sure I ever updated it to the internal Com functionality and haven't ran it for ages.

This version is still using a VBS script which is generated on the fly. (yea thats how old this one is ^_^ )

; ----------------------------------------------------------------------------
;
; AutoIt Version: 3.0
; Language:    English
; Platform:    Win9x / NT
; Author:        Jos van der Zande 
;
; Script Function:
;   Spell checks the Selected text with the Word spellchecker and 
; Paste it back if updated.;
; ----------------------------------------------------------------------------
; set to the MS language number you want 
Global $Language = "1033" ; English
$S = ClipGet()    ; save clip content
ClipPut("")      ; empty clipboard
Send("^{INSERT}")   ; get selection to clipboard
$ORG_SELECTION=ClipGet(); Get current selection
If $ORG_SELECTION = "" Then 
   TrayTip('SpellCheck','No text Selected !!',3)
   Sleep(3000)
Else
  ; get active window title and minimise
   $WINTITLE = WinGetTitle("")
  ; hide the window to ensure its not changed during spellcheck
   WinSetState($WINTITLE,'',@SW_MINIMIZE)
  ; find number of leading spaces
   For $SS = 0 To StringLen($ORG_SELECTION) - 1
      If StringMid($ORG_SELECTION,$SS+1,1) <> " " Then ExitLoop
   Next 
  ; find number of trailing spaces
   For $ST = 0 To StringLen($ORG_SELECTION) - 1
      If StringMid($ORG_SELECTION,StringLen($ORG_SELECTION) - $ST,1) <> " " Then ExitLoop
   Next 
  ; set traytip and Create/Run spellcheck vbs 
   TrayTip('Running SpellCheck for',StringLeft($ORG_SELECTION,30) & "...",5)
   CreateVBScript()
   $RC=RunWait(@ComSpec & ' /c Wscript.exe "' & @ScriptDir & '\TextSpellCheck.vbs" 1033',"",@SW_HIDE)
  ; restore window
   WinSetState($WINTITLE,'',@SW_RESTORE)
   WinActivate($WINTITLE,'')
  ; strip spaces and add original number of leading/trailing spaves
   $SELECTION=StringStripWS(ClipGet(),3); Get current selection
   If $SELECTION<>StringStripWS($ORG_SELECTION,3) Then
      For $X = 1 To $SS
         $SELECTION = " " & $SELECTION
      Next
      For $X = 1 To $ST
         $SELECTION = $SELECTION & " "
      Next
     ; update clipboard
      ClipPut($SELECTION)
     ; paste updated text
      Send("+{INSERT}")
      TrayTip('SpellCheck','Text updated.',4)
   Else
      TrayTip('SpellCheck','Text ok, no updates.',4)
   EndIf
EndIf
; restore orignal clipboard contents
ClipPut($S)
sleep(4000)
FileDelete(@ScriptDir & '\TextSpellCheck.vbs')

Func CreateVBScript()
   FileDelete(@ScriptDir & '\TextSpellCheck.vbs')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','On error resume next')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Set Word = CreateObject("word.Application")')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Word.WindowState = 2')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Word.Visible = False')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Set Doc = Word.Documents.Add( , , 1, True)')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Word.Selection.Paste')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','If err = 0 then')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  Word.Selection.LanguageID = ' & $Language)
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  ''Doc.CheckSpelling  '' Spellcheck function')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  Doc.CheckGrammar '' Spelling And Grammer check function')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  Word.Selection.WholeStory')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','  Word.Selection.Copy')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','End If')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Doc.Close False')
   FileWriteLine(@ScriptDir & '\TextSpellCheck.vbs','Word.Application.Quit True')
EndFunc  ;==>CreateVBScript

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

It looks good but there is a potential for failure in the regexp replace. I'm assuming that uou want to catch the question mark. In that case it should be escaped. Better yet might be to use

$SpellCheck = StringRegExpReplace($sString, "[0-9[:punct:]]", "")

EDIT: The same thing applies to the "(" , ")" and "$", They need to be escaped. Try the code I have above.

That looks/works nice! :-) Thanks!

Jos made a simple one with MS I believe then Big Daddy made an extensive one here

Reviewing now . . . Thanks!
Link to comment
Share on other sites

Not sure I ever updated it to the internal Com functionality and haven't ran it for ages.

This version is still using a VBS script which is generated on the fly. (yea thats how old this one is ^_^ )

I still have that and on occasion still use a compiled version of it. Started to modify it one day and then forgot all about what I wanted to change.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Not sure I ever updated it to the internal Com functionality and haven't ran it for ages.

This version is still using a VBS script which is generated on the fly. (yea thats how old this one is ^_^ )

Vista64/office 07

Works nicely! -Thanks!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...