老师好!
下面的代码是循环操作Word文档中的行,行数多的话,就卡住了似的,怎样采用多线程处理?
谢谢!
Dim rgx As New RegularExpressions.Regex("'[\u4e00-\u9fa5].*")
Dim dlg As new OpenFileDialog
dlg.Filter = "word|*.doc;*.docx"
If dlg.ShowDialog = DialogResult.OK Then
Dim app As New MSWord.Application
try
Dim doc = app.Documents.Open(dlg.FileName)
For Each k As object In doc.Paragraphs
If Len(Trim(k.Range.text)) = 1 Then
k.Range.Delete '删除空行
ElseIf Trim(k.Range.text).StartsWith(chr(39)) Then
k.Range.Delete '删除段落的开头字符是单引号
ElseIf rgx.IsMatch(k.Range.text) = True Then
k.Range.text = rgx.Replace(k.Range.text,"") & vbcrlf
End If
Next
doc.save
app.quit
catch ex As exception
msgbox(ex.message)
app.quit
End try
End If
msgbox("OK")