vb.net 对excel文件进行操作

Imports excel = Microsoft.Office.Interop.Excel
Public Class Form1
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim xlapp As excel.Application 
        Dim xlbook As excel.Workbook '工作表
        Dim xlsheet As excel.Worksheet '工作簿
        Dim sheetname As String
        xlapp = CreateObject("Excel.Application")
        xlbook = xlapp.Workbooks.Open("C:\Users\Administrator\Desktop\xxx.xls") '打开已经存在的EXCEL文件
        xlapp.Visible = False '设置EXCEL对象可见(或不可见)
        xlapp.DisplayAlerts = False

        sheetname = xlbook.Worksheets(1).Name
        Dim x = xlapp.Workbooks(1).Sheets(sheetname).range("K" + (8).ToString, Type.Missing).Text.ToString()
        '按照回车进行分割
        Dim s() = Split(x, vbLf)
        For i = 0 To UBound(s)
            MsgBox(s(i))
        Next

    End Sub
End Class

你可能感兴趣的:(.net,dba,microsoft)