如何使用Microsoft.Office.Interop.Excel从excel vb导入数据

时间:2015-07-08 13:26:34

标签: vb.net excel

抱歉英语不好 我可以将数据导出到excel文件这段代码

    Imports Excel = Microsoft.Office.Interop.Excel
        Dim xlApp As New Excel.Application
        Dim xlWorkBook As Excel.Workbook
        Dim xlWorkSheet As Excel.Worksheet    
        xlWorkBook = xlApp.Workbooks.Open("MY EXCEL PATH")
        xlWorkSheet = xlWorkBook.Sheets("SHEET1")
        With xlWorkSheet
           .Range("D8").Value = "1"
           .Range("D9").Value = "2"
        End With
        xlApp.Visible = True

我想将数据(D8,D9)从excel文件导入到任何文本框。你能帮我吗?感谢

1 个答案:

答案 0 :(得分:0)

我不确定您要在哪里导入数据,但这应该有效并为您提供价值。

Imports Excel = Microsoft.Office.Interop.Excel
Dim xlApp As New Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet    

Dim strOne As String    
Dim strTwo As String    

xlWorkBook = xlApp.Workbooks.Open("MY EXCEL PATH")
xlWorkSheet = xlWorkBook.Sheets("SHEET1")
With xlWorkSheet
   strOne = .Range("D8").Value  'This will give you the value of cell D8 in strOne
   strTwo = .Range("D9").Value  'This will give you the value of cell D9 in strTwo
End With

MsgBox strOne
MsgBox strTwo

'your code continue...