vbaccess转excel文件|VB 连接的access数据库如何导出到Excel中

vbaccess转excel文件|VB 连接的access数据库如何导出到Excel中的第1张示图

㈠ 将ACCESS表中的数据记录导入到EXCEL文件中,用VB2005如何实现

读取DataGridView里的每一个单元格,对应写到EXCEL里。我这里有个模块myDVW是你要导出Datrgrivview控件JDT是窗口下方状态上的一个进度条控件xlspath是EXCEL的放置路径(我导出的是xlt的模板文件)startrow是EXCEL模板里,要从哪一行开始写数据EndColumn是Datrgridview控件里的列数如果有问题就加我QQ吧:20963389Public Sub ToExcel(ByVal myDVW As DataGridView, ByVal JDT As ToolStripProgressBar, ByVal xlsPath As String, ByVal StartRow As Integer, ByVal EndColumn As Integer) If myDVW.Rows.Count <= 0 Then '如果没有记录就退出 Exit Sub End IfIf MsgBox("导出EXCEL将要耗费较多的时间,是否继续?", MsgBoxStyle.YesNo + MsgBoxStyle.Information, "提示") = MsgBoxResult.No Then Exit Sub End IfDim ExApp As Excel.Application '定义EXCEL对象 Dim ExBook As Excel.Workbook '定义工作簿 Dim ExSheet As Excel.Worksheet '定主工作表 ExApp = CreateObject("Excel.Application") '创建EXCEL应用类 'ExBook = ExApp.Workbooks.Open(Application.StartupPath & "\ExJL.xlt") '打开EXCEL工作簿 ExBook = ExApp.Workbooks.Open(xlsPath) ExSheet = ExBook.Worksheets(1) '打开EXCEL工作表 JDT.Visible = True '进度条 For i As Integer = 0 To myDVW.Rows.Count – 1 JDT.Value = (i / myDVW.Rows.Count) * 100 For j As Integer = 1 To EndColumn ExSheet.Cells(i + StartRow, j) = myDVW.Rows(i).Cells(j).Value.ToString Application.DoEvents() '释放控制 Next Next JDT.Visible = False ExApp.Visible = True '可见 ExBook = Nothing ExSheet = Nothing ExApp = NothingEnd Sub

㈡ vb从access数据库中查询到的数据如何导出到EXCEL中

引用Excel后,看看这串代码,按自己的意思改改。Dim xlApp As New Excel.Application Dim xlBook As Excel.Workbook Dim xlsheet As Excel.Worksheet Set xlBook = xlApp.Workbooks.Add("路径\名称.XLS") '你新建一个Excel保存,然后打开 Set xlsheet = xlBook.Worksheets(1) 't1 = Text0(1).Text 这些Text里的东西,你可以这样处理't2 = Text1(0).Text sheet1里面cells(1,1)就是A1't3 = Text2(2).Text cells(1,2)是A2,cells(2,1)是A2't4 = Text3(1).Text 依次类推,可以用 i , j。把它们放到sheet1.cells()里面 Sheet.Cells(2,1)=Text0(1).Text Sheet.Cells(2,2)=Text1(0).Text Sheet.Cells(i , j)=Text1( i ).Text '如果想要多次保存,可以:() Sheet1.Range("A1").End(xlDown).Offset(1,0).Select '到使用过的单元格底部,需要两行以上,你可以从第二行(2, j)开始记录 xlBook.Close SaveChanges :=True '以下代码为关闭Excel xlApp.Quit '其实前面Dim过后可以 xlApp.Visible = False Set xlApp = Nothing O(∩_∩)O~

㈢ 如何在VB里面实现导出ACCESS到EXCEL

我这里有个从ORACLE导出到EXCEL的例子,希望有帮助Private Function ExportDetail(strFileName As String) As Boolean Dim iRow As Long Dim myExcel As Excel.Application Dim xlBook As Excel.Workbook Dim xlSheet As Excel.Worksheet On Error GoTo ErrAction ExportDetail = False Set myExcel = New Excel.Application myExcel.Visible = False myExcel.SheetsInNewWorkbook = 1 Set xlBook = myExcel.Workbooks.Add Set xlSheet = xlBook.Worksheets(1) xlSheet.Columns.ClearFormats xlSheet.Cells(1, 1) = "物料BOM【" & TreeFile.SelectedItem.Text & "】" xlSheet.Range("A1:T1").MergeCells = True xlSheet.Cells(2, 1) = "标题项" xlSheet.Cells(2, 2) = "中文名称" xlSheet.Cells(2, 3) = "英文名称" xlSheet.Cells(2, 4) = "文档号" xlSheet.Cells(2, 5) = "物料号" xlSheet.Cells(2, 6) = "数量" xlSheet.Cells(2, 7) = "总数量" xlSheet.Cells(2, 8) = "单位" xlSheet.Cells(2, 9) = "物料关联文档1" xlSheet.Cells(2, 10) = "物料关联文档2" xlSheet.Cells(2, 11) = "所属装配文档号" xlSheet.Cells(2, 12) = "所属装配物料号" xlSheet.Cells(2, 13) = "装配物料关联文档1" xlSheet.Cells(2, 14) = "装配物料关联文档2" xlSheet.Cells(2, 15) = "物料技术参数" xlSheet.Cells(2, 16) = "物料类型" xlSheet.Cells(2, 17) = "物料备注" xlSheet.Cells(2, 18) = "重量" xlSheet.Cells(2, 19) = "备注" xlSheet.Cells(2, 20) = "清单文档号" For iRow = 1 To DocList.ListItems.Count xlSheet.Cells(iRow + 2, 1) = DocList.ListItems(iRow).ListSubItems(1) xlSheet.Cells(iRow + 2, 2) = DocList.ListItems(iRow).ListSubItems(2) xlSheet.Cells(iRow + 2, 3) = DocList.ListItems(iRow).ListSubItems(3) xlSheet.Cells(iRow + 2, 4) = DocList.ListItems(iRow).ListSubItems(4) xlSheet.Cells(iRow + 2, 5) = DocList.ListItems(iRow).ListSubItems(5) xlSheet.Cells(iRow + 2, 6) = DocList.ListItems(iRow).ListSubItems(6) xlSheet.Cells(iRow + 2, 7) = DocList.ListItems(iRow).ListSubItems(7) xlSheet.Cells(iRow + 2, 8) = DocList.ListItems(iRow).ListSubItems(8) xlSheet.Cells(iRow + 2, 9) = DocList.ListItems(iRow).ListSubItems(9) xlSheet.Cells(iRow + 2, 10) = DocList.ListItems(iRow).ListSubItems(10) xlSheet.Cells(iRow + 2, 11) = DocList.ListItems(iRow).ListSubItems(11) xlSheet.Cells(iRow + 2, 12) = DocList.ListItems(iRow).ListSubItems(12) xlSheet.Cells(iRow + 2, 13) = DocList.ListItems(iRow).ListSubItems(13) xlSheet.Cells(iRow + 2, 14) = DocList.ListItems(iRow).ListSubItems(14) xlSheet.Cells(iRow + 2, 15) = DocList.ListItems(iRow).ListSubItems(15) xlSheet.Cells(iRow + 2, 16) = DocList.ListItems(iRow).ListSubItems(16) xlSheet.Cells(iRow + 2, 17) = DocList.ListItems(iRow).ListSubItems(17) xlSheet.Cells(iRow + 2, 18) = DocList.ListItems(iRow).ListSubItems(18) xlSheet.Cells(iRow + 2, 19) = DocList.ListItems(iRow).ListSubItems(19) xlSheet.Cells(iRow + 2, 20) = DocList.ListItems(iRow).ListSubItems(20) Next xlSheet.Columns.AutoFit xlSheet.Rows(2).Font.Bold = True xlBook.SaveAs strFileName myExcel.Quit Set myExcel = Nothing ExportDetail = True Exit Function ErrAction: ExportDetail = False MsgBox "导出失败:" & Err.Description, vbCritical, "导出到EXCEL"End Function

㈣ VB将access数据库数据导出至excel的问题,求高手进呀!!

Private Sub Command5_Click()Dim rs As DAO.RecordsetDim Filnum As LongDim Recnum As LongDim xlapp As ObjectSet rs = Me.打印价签导出子窗体.Form.RecordsetSet xlapp = CreateObject("excel.application")xlapp.Visible = Truexlapp.Workbooks.Open ("D:\购好超市\促销及价格管理\标签格式\促销标签打印格式–特价.xlsx")Dim sheet As ObjectSet sheet = xlapp.sheets("内容")rs.MoveFirstRecnum = 2Do Until rs.EOFFor Filnum = 0 To rs.Fields.Count – 1sheet.cells(Recnum, Filnum + 1) = rs.Fields(Filnum)NextRecnum = Recnum + 1rs.MoveNextLoopSet sheet = xlapp.sheets("格式1")sheet.cells(3, 3) = "12345678"End Sub这是从ACCESS里导出数据到EXCEL文件里,导出完成后,如何用代码关闭这个Excel文件?代码怎么写? 问题补充:xlapp.ActiveWorkbook.Close savechanges:=True这样可以,但是这样仅仅关闭了这个EXCEL文件,EXCEL程序还没有关闭,就是那种没有打开任何一个工作薄的界面,所以如果这样重复导出很多次数据以后,就会出现很多没有打开任何工作薄的Excel程序!如何关闭工作簿的同时也关闭应用程序呢xlapp.quitset xlapp=nothing

㈤ vb从access数据库中查询到的数据如何导出到EXCEL中

引用Excel后,看看这串代码,按自己的意思改改。 Dim xlApp As New Excel.Application Dim xlBook As Excel.Workbook Dim xlsheet As Excel.Worksheet Set xlBook = xlApp.Workbooks.Add("路径\名称.XLS") '你新建一个Excel保存,然后打开 Set xlsheet = xlBook.Worksheets(1) 't1 = Text0(1).Text 这些Text里的东西,你可以这样处理 't2 = Text1(0).Text sheet1里面cells(1,1)就是A1 't3 = Text2(2).Text cells(1,2)是A2,cells(2,1)是A2 't4 = Text3(1).Text 依次类推,可以用 i , j。把它们放到sheet1.cells()里面 Sheet.Cells(2,1)=Text0(1).Text Sheet.Cells(2,2)=Text1(0).Text Sheet.Cells(i , j)=Text1( i ).Text '如果想要多次保存,可以:() Sheet1.Range("A1").End(xlDown).Offset(1,0).Select '到使用过的单元格底部,需要两行以上,你可以从第二行(2, j)开始记录 xlBook.Close SaveChanges :=True '以下代码为关闭Excel xlApp.Quit '其实前面Dim过后可以 xlApp.Visible = False Set xlApp = Nothing O(∩_∩)O~

㈥ VB 连接的access数据库如何导出到Excel中

select * into table1 from [Excel 8.0;Database=C:\tmp.xls].[''Sheet1$'']这条sql可以让ADO直接从Excel里面查询数据并写到access的表格中

㈦ 利用VBA将access中的所有数据导入到指定的excel中

启动excel1)菜单-》工具-》宏-》录制新宏2)菜单-》数据-》导入外部数据-》导入数据3)选择你的mdb文件,然后按提示导入4)点“结束录制”按钮,菜单-》工具-》宏-》vb编辑器,检查vba代码5)回工作簿,清空所有数据,在适当位置添加按钮,在按钮的click事件里调用宏所对应的方法

㈧ vb把access中数据导入excel中

Option ExplicitPublic appdisk As StringPublic conn As New ADODB.ConnectionPublic rs As New ADODB.RecordsetPublic db As StringPrivate Sub Form_Load() appdisk = Trim(App.Path) If Right(appdisk, 1) <> "\" Then appdisk = appdisk & "\" db = appdisk db = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=False;Data Source=" & db & "alex.mdb" conn.CursorLocation = adUseClient conn.Open db rs.Open "aaa", conn, adOpenKeyset, adLockPessimisticEnd SubPrivate Sub Command1_Click() Dim lRow As Long Dim sXLSPath As String Dim MyExcel As New Excel.Application Dim MyBook As Excel.Workbook Dim MySheet As Excel.Worksheet Screen.MousePointer = 11 sXLSPath = appdisk & "maindata.xls" Open sXLSPath For Output As #1 Close #1 Set MyExcel = CreateObject("excel.application") Set MyBook = MyExcel.Workbooks.Open(sXLSPath) Set MySheet = MyExcel.ActiveSheet MySheet.Range("A1:O1").Select With MyExcel.Selection.Interior .ColorIndex = 15 .Pattern = xlSolid End With MySheet.Columns("A:C").NumberFormat = "0_ " MySheet.Columns(1).ColumnWidth = 5 MySheet.Columns(2).ColumnWidth = 10 MySheet.Columns(3).ColumnWidth = 10 MySheet.Columns(4).ColumnWidth = 10 MySheet.Columns(5).ColumnWidth = 10 MySheet.Columns(6).ColumnWidth = 10 MySheet.Columns(7).ColumnWidth = 10 MySheet.Columns(8).ColumnWidth = 10 MySheet.Columns(9).ColumnWidth = 10 MySheet.Cells(1, 1) = "proid" MySheet.Cells(1, 2) = "proct" MySheet.Cells(1, 3) = "batchno" MySheet.Cells(1, 4) = "seqno" If rs.EOF = True Then rs.Close: Set rs = Nothing Screen.MousePointer = 0 Exit Sub End If Do While rs.EOF = False lRow = lRow + 1 MySheet.Cells(lRow + 1, 1) = rs.Fields("seqno") MySheet.Cells(lRow + 1, 2) = rs.Fields("weight") MySheet.Cells(lRow + 1, 3) = rs.Fields("unitprc") MySheet.Cells(lRow + 1, 4) = rs.Fields("account") rs.MoveNext Loop rs.Close: Set rs = Nothing MyExcel.DisplayAlerts = False MyBook.SaveAs FileName:=appdisk & "maindata.xls", FileFormat:=xlNormal, Password:="", writerespassword:="", ReadOnlyRecommended:=False, CreateBackup:=False MyBook.Application.Quit MyExcel.Application.Quit Set MySheet = Nothing Set MyBook = Nothing Set MyExcel = Nothing Screen.MousePointer = 0 MsgBox "Successful Established Excell File Maindata.xls", vbOKOnly, "Bawang Electronic Price Scale"End Sub

㈨ 如何用VB6把ACCESS数据库导出成EXCEL表

VB本身提自动化功能可以读写EXCEL表,其方法如下:1、在工程中引用Microsoft Excel类型库:从"工程"菜单中选择"引用"栏;选择Microsoft Excel 9.0 Object Library(EXCEL2000),然后选择"确定"。表示在工程中要引用EXCEL类型库。2、在通用对象的声明过程中定义EXCEL对象:Dim xlApp As Excel.ApplicationDim xlBook As Excel.WorkBookDim xlSheet As Excel.Worksheet 3、在程序中操作EXCEL表常用命令:Set xlApp = CreateObject("Excel.Application") '创建EXCEL对象Set xlBook = xlApp.Workbooks.Open("文件名") '打开已经存在的EXCEL工件簿文件xlApp.Visible = True '设置EXCEL对象可见(或不可见)Set xlSheet = xlBook.Worksheets("表名") '设置活动工作表xlSheet.Cells(row, col) =值 '给单元格(row,col)赋值xlSheet.PrintOut '打印工作表xlBook.Close (True) '关闭工作簿xlApp.Quit '结束EXCEL对象Set xlApp = Nothing '释放xlApp对象xlBook.RunAutoMacros (xlAutoOpen) '运行EXCEL启动宏xlBook.RunAutoMacros (xlAutoClose) '运行EXCEL关闭宏 4、在运用以上VB命令操作EXCEL表时,除非设置EXCEL对象不可见,否则VB程序可继续执行其它操作,也能够关闭EXCEL,同时也可对EXCEL进行操作。但在EXCEL操作过程中关闭EXCEL对象时,VB程序无法知道,如果此时使用EXCEL对象,则VB程序会产生自动化错误。形成VB程序无法完全控制EXCEL的状况,使得VB与EXCEL脱节。

㈩ 如何用Vb将access导到excel中

不需要你这么麻烦,只需一个SQL语句即可。代码在公司电脑上,你去网络SO一下。

未经允许不得转载:山九号 » vbaccess转excel文件|VB 连接的access数据库如何导出到Excel中

赞 (0)