VB中Excel 2010的导入导出操作
编写人:左丘文
2015-4-11
近来这已是第二篇在讨论VB的相关问题,今天在这里,我想与大家一起分享一下在VB中如何从Excel中导入数据和导出数据到Excel(程序支持excel2010),在此做个小结,以供参考。有兴趣的同学,可以一同探讨与学习一下,否则就略过吧。
1、 程序导入导出操作介面:
2、 从excel导入数据代码:
, ) = , ) = , ) = Then
).Value =
To rs.Fields.count
) =
To rs.Fields.count
Next
xlsheet.Cells(j, rs.Fields.count + ) =
i = i -
End If
rs.MoveNext
Loop
ConGamma.CommitTrans
rs.MoveFirst
btrans = False
Call UnloadInforDlg
If rs.RecordCount > Then
MsgBox End If
End If
Dim ssfile() As String
Dim ssfile2 As String
ssfile = Split(sFile, To UBound(ssfile) -
ssfile2 = ssfile2 & ssfile(i) & ssfile2 = ssfile2 & xlBook.SaveAs (ssfile2)
xlBook.Close (True) Set rs = Nothing
If Trim(txtYEAR.Text) <> Call frmMDI.ITMDIAdminX.ControlSearch
Exit Sub
End If
checkgetexcel:
MsgBox If ERR.Number <> Then
MsgBox ERR.Description
End If
Exit Sub
End Sub
3、 导出到excel代码:
Else Exit Sub
End If
If FileExists(sFile) Then
If MsgBox( End If
Screen.MousePointer = vbHourglass
On Error GoTo Err_Proc
j =
Set xlBook = xlApp.Workbooks.Add
Set xlsheet = xlBook.WorkSheets(
xlsheet.Cells(, ) = , ) = , ) = , ) = For z = To rs.RecordCount
For k = To rs.Fields.count
Next
j = j +
Next
xlBook.SaveAs (sFile)
xlBook.Close (True) rs.Close
Set rs = Nothing
Screen.MousePointer = vbDefault
Exit Sub
Err_Proc:
Screen.MousePointer = vbDefault
MsgBox
End Sub
有关更多的技术分享,大家可以加入我们的技术群,进行源码的分享。
欢迎加入技术分享群:238916811