首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VBA >

vb.net操作EXCEL,为啥设置了excelApp.Visible = False,excel仍然出现

2012-09-13 
vb.net操作EXCEL,为什么设置了excelApp.Visible False,excel仍然出现在我读取excel中的值之后,过一段时

vb.net操作EXCEL,为什么设置了excelApp.Visible = False,excel仍然出现
在我读取excel中的值之后,过一段时间才显示,不是立刻出来,大约5秒左右.



以下是我的所有代码了.

VB.NET code
Private Sub BtOpenFile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles BtOpenFile.Click        Dim myStream As Stream = Nothing        Try            OpenFileDialog1.InitialDirectory = "c:\"            OpenFileDialog1.Filter = "Excel files (*.xls;*.xlsx)|*.xls;*.xlsx|Csv files(*.csv)|*.csv|All files (*.*)|*.*"            OpenFileDialog1.FilterIndex = 1            OpenFileDialog1.RestoreDirectory = True            If OpenFileDialog1.ShowDialog() = System.Windows.Forms.DialogResult.OK Then                Try                    myStream = OpenFileDialog1.OpenFile()                    If (myStream IsNot Nothing) Then                        Dim excelApp As Excel.Application = New Excel.Application ' CreateObject("Excel.Application")                        excelApp.Visible = False                        Dim excelWorkbook As Excel.Workbook                        Dim excelSheet As Excel.Worksheet                        Dim excelRange As Excel.Range   '定义工作区域                        excelWorkbook = excelApp.Workbooks.Open(OpenFileDialog1.FileName)                        excelApp.Workbooks.Add(True)                        excelSheet = excelWorkbook.Worksheets(1)                        excelSheet.Activate()                        MsgBox(excelSheet.Cells(3, 1).value.ToString, MsgBoxStyle.Information, "xs")                    End If                Catch Ex As Exception                    MessageBox.Show("Cannot read file from disk. Original error: " & Ex.Message)                    Return                Finally                    ' Check this again, since we need to make sure we didn't throw an exception on open.                    If (myStream IsNot Nothing) Then                        myStream.Close()                    End If                End Try            End If        Catch ex As Exception            MsgBox(ex.Message)            Return        End Try    End Sub


[解决办法]
谢谢楼主分享解决办法。

热点排行