datagridview在vs2005 vb.net中选择了列每行的拼写检查

本文关键字:检查 vs2005 vb net 选择 datagridview | 更新日期: 2024-10-22 14:33:38

如何从应用程序访问此表单的控件。我的代码正在工作,但我无法在检查单元格之间停止它。

Private Sub Button4_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理按钮4.单击

    Dim emptyItem As Object = System.Reflection.Missing.Value
    Dim oNothing As Object = Nothing
    Dim oTrue As Object = True
    Dim oFalse As Object = False
    Dim Loopbreak As Object = False
    Dim oAlwaysSuggest As Object = True
    Dim oIgnoreUpperCase As Object = False
    Dim SpellingErrors As Integer = 0
    Dim ErrorCountMessage As String = String.Empty
    Dim WordApp As Microsoft.Office.Interop.Word.Application = _
       New Microsoft.Office.Interop.Word.Application()
    WordApp.Visible = False
    Dim ActualValue As String = ""
    Dim WordDoc As Word.Document
    For rowCnt As Integer = 0 To DataGridView1.Rows.Count - 1

        Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("winword")
        If Loopbreak = False Then
            For Each p As Process In pProcess
                If p.HasExited Then
                    p.Kill()
                End If
            Next
        WordDoc = WordApp.Documents.Add
        WordDoc.Words.First.InsertBefore(DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Value)
        Dim docErrors As Microsoft.Office.Interop.Word.ProofreadingErrors = WordDoc.SpellingErrors
        SpellingErrors = docErrors.Count
        If SpellingErrors > 0 Then
            DataGridView1.Rows(rowCnt).Selected = True
                WordDoc.CheckSpelling(oNothing, oIgnoreUpperCase, oAlwaysSuggest, oNothing, oNothing, oNothing, oNothing, oNothing, oNothing, oNothing, oNothing, oNothing)
                ' format a string to contain a report of the errors detected
            ErrorCountMessage = "Spell check complete; errors detected: " + SpellingErrors.ToString()

            Dim first As Object = 0
            Dim last As Object = WordDoc.Characters.Count - 1
            ActualValue = DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Value
            DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Value = WordDoc.Range(first, last).Text

            If ActualValue = DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Value Then
                DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Style.ForeColor = Color.Red
                Loopbreak = True
            End If
            End If

            WordDoc.Activate()
            DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Style.ForeColor = Color.Red
        Else
        End If
        SpellingErrors = 0
    Next

    WordApp.Quit(oFalse, emptyItem, emptyItem)

    MsgBox("Spell Check Completed")


End Sub

}

datagridview在vs2005 vb.net中选择了列每行的拼写检查

'格式化字符串以包含检测到的错误报告

不在代码中

[Private Sub Button4_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)处理按钮4.单击

    Dim emptyItem As Object = System.Reflection.Missing.Value
    Dim oNothing As Object = Nothing
    Dim oTrue As Object = True
    Dim oFalse As Object = False
    Dim Loopbreak As Object = False
    Dim oAlwaysSuggest As Object = True
    Dim oIgnoreUpperCase As Object = False
    Dim SpellingErrors As Integer = 0
    Dim ErrorCountMessage As String = String.Empty
    Dim WordApp As Microsoft.Office.Interop.Word.Application = _
       New Microsoft.Office.Interop.Word.Application()
    WordApp.Visible = False
    Dim ActualValue As String = ""
    Dim WordDoc As Word.Document
    For rowCnt As Integer = 0 To DataGridView1.Rows.Count - 1

        Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("winword")
        If Loopbreak = False Then
            For Each p As Process In pProcess
                If p.HasExited Then
                    p.Kill()
                End If
            Next
        WordDoc = WordApp.Documents.Add
        WordDoc.Words.First.InsertBefore(DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Value)
        Dim docErrors As Microsoft.Office.Interop.Word.ProofreadingErrors = WordDoc.SpellingErrors
        SpellingErrors = docErrors.Count
        If SpellingErrors > 0 Then
            DataGridView1.Rows(rowCnt).Selected = True
                WordDoc.CheckSpelling(oNothing, oIgnoreUpperCase, oAlwaysSuggest, oNothing, oNothing, oNothing, oNothing, oNothing, oNothing, oNothing, oNothing, oNothing)
            ErrorCountMessage = "Spell check complete; errors detected: " + SpellingErrors.ToString()

            Dim first As Object = 0
            Dim last As Object = WordDoc.Characters.Count - 1
            ActualValue = DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Value
            DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Value = WordDoc.Range(first, last).Text

            If ActualValue = DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Value Then
                DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Style.ForeColor = Color.Red
                Loopbreak = True
            End If
            End If

            WordDoc.Activate()
            DataGridView1.Rows(rowCnt).Cells(cmbSortColumns.SelectedValue).Style.ForeColor = Color.Red
        Else
        End If
        SpellingErrors = 0
    Next

    WordApp.Quit(oFalse, emptyItem, emptyItem)

    MsgBox("Spell Check Completed")


End Sub

结束类]