Visual Basic - Ayuda creando corrector ortografico con CheckSpelling

Life is soft - evento anual de software empresarial
 
Vista:

Ayuda creando corrector ortografico con CheckSpelling

Publicado por David (2 intervenciones) el 23/02/2021 14:20:57
Buenos dias chicos. Estoy teniendo problemas al crear un corrector ortografico con CheckSpelling dentro de un proyecto en WindowsForm Framework. Resulta que cargo el contenido de un textbox en un documento de Word para pasarle el corrector, con el siguienbte código:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
Dim wordapp As New Word.Application
wordapp.Visible = False
 
Dim doc As Word.Document = wordapp.Documents.Add()
 
Dim range As Word.Range
range = doc.Range()
range.Text = Novedades.txtresumen.Text
 
 
doc.Activate()
doc.CheckSpelling()
 
Dim chars() As Char = {CType(vbLf, Char), CType(vbCr, Char)}
 
Novedades.txtresumen.Text = doc.Range.Text.Trim(chars)
doc.Close(SaveChanges:=False)
wordapp.Quit()

EL problema viene cuando el textbox (txtresumen) tiene varias líneas, al volver a copiar el texto corregido dentro del textbox, este lo hace todo en la misma línea. Hay alguna forma de controlar los retornos de carro? He probado obviando la propiedad trim pero el resultado es el mismo.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

Resuelto

Publicado por David (2 intervenciones) el 26/02/2021 15:27:21
Encontre una solución. La dejo aqui por si a alguien le sirve de ayuda:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
Public Class Form1
 
    Inherits System.Windows.Forms.Form
    Dim a As Integer
 
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim speller As Object
        Dim txt As String
        Dim new_txt As String
        Dim pos As Integer
        Dim pos2 As Integer
 
        speller = CreateObject("Word.Basic")
 
        speller.FileNew()
        speller.Insert(TextBox1.Text)
        speller.ToolsSpelling()
        speller.EditSelectAll()
        txt = speller.Selection()
        speller.FileExit(2)
 
        If RSet(txt, 1) = vbCr Then
            txt = LSet(txt, Len(txt) - 1)
        End If
        new_txt = ""
        pos = InStr(txt, vbCr)
        Do While pos > 0
            new_txt = new_txt & Strings.Left(txt, pos - 1) & vbCrLf
            pos2 = Len(txt)
            txt = Strings.Right(txt, pos2 - pos) ' Devuelve la cadena desde la derecha con la longitud especificada
            pos = InStr(txt, vbCr)
        Loop
        new_txt = new_txt & txt
 
        TextBox1.Text = new_txt
 
 
    End Sub
End Class
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
1
Comentar