{
Private Sub Button4_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button4.Click
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
}
答案 0 :(得分:0)
'格式化字符串以包含检测到的错误的报告
不在代码中
[ Private Sub Button4_Click(ByVal sender As System.Object,ByVal e As System.EventArgs)Handles Button4.Click
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
结束课程 ]