El vie, 21-04-2006 a las 09:14, Jancs escribió:
> Hi!
> 
> Can i ask someone to help me out with the design of the OO macro having the 
> following functionality:
> 
> it checks opened document (word by word, f.e.) against the dic of document
> language and writes words, which are not found in the dic, to the separate
> file.
> 
> With MSWord it was quiet easy..

Jancs:

I have this macro you need. I developed it for a primary school teacher,
that wanted a fast way to obtain a list of bad spelled words from his
students homeworks.

Try it, and modify it at will, if you need so.

Best regards,

Santiago Bosio
Native-Lang ES colaborator

REM  *****  BASIC  *****

Sub ListarPalabrasIncorrectas

    Dim oDocModel as Variant
    Dim oTextCursor as Variant
    Dim oLinguSvcMgr as Variant
    Dim oSpellChk as Variant
    Dim oListDocFrame as Variant
    Dim oListDocModel as Variant
    Dim sListaPalabras as String
    Dim aProp(0) As New com.sun.star.beans.PropertyValue

    ' Obtener acceso al documento actual
    oDocModel = StarDesktop.CurrentFrame.Controller.getModel()
    If IsNull(oDocModel) Then
        MsgBox("No hay ningún documento activo." + Chr(13) + _
               "Abra un documento de Writer antes de activar esta macro.")
        Exit Sub
    End If

    ' Verificar que este sea un documento de texto
    If Not HasUnoInterfaces (oDocModel, "com.sun.star.text.XTextDocument") Then
        MsgBox("Este documento no soporta la interfaz 'XTextDocument'." + 
Chr(13) + _
               "Utilice esta macro únicamente con documentos de Writer.")
        Exit Sub
    End If

    ' Obtener un cursor de texto y posicionarlo al principio del documento
    oTextCursor = oDocModel.Text.createTextCursor()
    oTextCursor.gotoStart(False)

    ' Obtener una referencia al corrector ortográfico o morir en el intento
    oLinguSvcMgr = 
createUnoService("com.sun.star.linguistic2.LinguServiceManager")
    If Not IsNull(oLinguSvcMgr) Then
        oSpellChk = oLinguSvcMgr.getSpellChecker()
    End If
    If IsNull (oSpellChk) Then
        MsgBox("No se pudo acceder a un corrector ortográfico." + Chr(13) + _
               "Verifique las opciones de lingüística de su instalación.")
        Exit Sub
    End If
       
    ' Iterar sobre todas las palabras que contiene el documento
    Do
        If oTextCursor.isStartOfWord() Then
            oTextCursor.gotoEndOfWord(True)
            ' Verificar si la palabra está bien escrita
            If Not oSpellChk.isValid(oTextCursor.getString(), 
oTextCursor.getPropertyValue("CharLocale"), aProp()) Then
                sListaPalabras = sListaPalabras + oTextCursor.getString() + 
Chr(13)
            End If
            oTextCursor.collapseToEnd()
        End If
    Loop While oTextCursor.gotoNextWord(False)
        
    If Len(sListaPalabras) = 0 Then
        MsgBox("No hay errores ortográficos en el documento.")
        Exit Sub
    End If

    ' Buscar el frame que contiene la lista (o crearlo)
    oListDocFrame = StarDesktop.findFrame("fListarPalabrasIncorrectas", 
com.sun.star.frame.FrameSearchFlag.ALL)
    If IsNull(oListDocFrame) Then
        oListDocModel = 
StarDesktop.loadComponentFromURL("private:factory/swriter", 
"fListarPalabrasIncorrectas", com.sun.star.frame.FrameSearchFlag.CREATE, 
aProp())
        oListDocFrame = oListDocModel.CurrentController.getFrame()
    Else
        oListDocModel = oListDocFrame.Controller.getModel()
    End If

    ' Obtener un cursor de texto para este documento
    oTextCursor = oListDocModel.Text.createTextCursor()
    oTextCursor.gotoEnd(False)

    ' Escribir la lista
    oListDocModel.Text.insertString (oTextCursor, sListaPalabras, False)

    ' Activar este frame
    oListDocFrame.activate()

    ' ¡Y ya terminamos!

End Sub

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to