我正在使用 VB 从文本文件中搜索一些数据,然后填充到 excel 中。它正在工作。问题是 xl.visible=true 使 excel 工作表立即可见,然后值继续填充。我想隐藏 excel 直到数据填充完成。然后在表单上出现一个按钮,单击该按钮将显示excel文件。
请帮忙。这是我正在使用的代码:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' create an excel instance
Dim xl = Microsoft.VisualBasic.CreateObject("Excel.Application")
xl.Visible = False
Dim wb = xl.Workbooks.Add()
Dim sheet = wb.ActiveSheet
' find lines starting with any whitepace followed by MTV or MTB and capture
' the text after =
Dim pattern = "(?<=\s*(MTV).*=).*"
Dim i = 1
Dim arg = {Microsoft.VisualBasic.ControlChars.CrLf, Microsoft.VisualBasic.ControlChars.Lf}
If RichTextBox3.Text = "" Then
MsgBox("No input. What will I process??")
Else
Timer1.Start()
For Each line In File.ReadLines(RichTextBox3.Text)
Dim match = Regex.Match(line, pattern)
' check each line and fill sheet
If match.Success Then
sheet.Cells(i, 1).Value = match.Value
i += 1
End If
Next
End If
xl.Visible = True
End Sub