分享

excel数据导入VB Text控件中

 网络摘记 2014-04-04
 vb导入EXCEL                                        

Debug.Print xlSheet.Range("A1")'在立即窗口中显示第1张工作表中A1的内容,如果你想赋值给某个变量就在这里赋值,=xlSheet.Range("A1")就是你想要的东西

Dim i As Integer
Dim 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 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多