关于VB.NET调用excel的问题
用建了个窗体,并将窗体上一些文本框内的数据存储在excel,这一步我能解决。但是要怎么调用之前保存的excel并将其内部的数据重新赋给窗体上其他文本框内? 求真相!!
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim fileName As String '打开文件 OpenFileDialog1.InitialDirectory = Application.StartupPath OpenFileDialog1.ShowDialog() fileName = OpenFileDialog1.FileName() '调用excel xlWorkBook = xlApp.Workbooks.Open(fileName) xlWorkSheet = xlWorkBook.Sheets("sheet1") With xlWorkSheet Dim a(.UsedRange.Rows.Count - 1, .UsedRange.Columns.Count - 1) As String'定义一个数组存储单元格的值 For i As Integer = 1 To .UsedRange.Rows.Count - 1 For j As Integer = 1 To .UsedRange.Columns.Count - 1 a(i, j) = .Cells(i, j).Value'将单元格的值赋值给数组 Console.Write(a(i, j))'在立即窗口输出读取的值 Next Next End With '关闭文件 'xlWorkBook.Close() xlApp.Quit() '排错 'releaseObject(xlApp) 'releaseObject(xlWorkBook) 'releaseObject(xlWorkSheet) End Sub