vb导入EXCEL
Debug.Print xlSheet.Range("A1")'在立即窗口中显示第1张工作表中A1的内容,如果你想赋值给某个变量就在这里赋值,=xlSheet.Range("A1")就是你想要的东西 Dim i As IntegerDim j As Integer Dim xlApp As New Excel.Application Dim xlBook As New Excel.Workbook Dim xlSheet As New Excel.Worksheet Set xlApp = CreateObject("Excel.Application") xlApp.Visible = True Set xlBook = xlApp.Workbooks.Add On Error Resume Next Set xlBook = xlApp.Workbooks.Open("d:\text2.xls") Set xlSheet = xlBook.Worksheets(1) For j = 0 To mgrid.Columns.Count - 1 xlSheet.Cells(1, j + 1) = mgrid.Columns.Item(j).Caption Next j xlSheet.Cells(6, 1) = "i" Adodc1.Recordset.MoveFirst For i = 0 To Adodc1.Recordset.RecordCount - 1 mgrid.Row = i For j = 0 To mgrid.Columns.Count - 1 mgrid.Col = j 'MsgBox DataGrid1.Text If IsNull(mgrid.Text) = False Then xlSheet.Cells(i + 2, j + 1) = mgrid.Text End If Next j Next i 内容来自:http://publishblog.blogchina.com/blog/tb.b?diaryID=5716918 |
|
来自: 网络摘记 > 《VB-EXCEL知识》