vb从access数据库中查询到的数据如何导出到EXCEL中
PrivateSubCommand1_Click()DimcnAsNewADODB.ConnectionDimrsAsNewADODB.RecordsetDimstrCn...
Private Sub Command1_Click()Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim strCn As String
Dim sql As String
strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\伟湟车间管理库.mdb;Persist Security Info=false"
cn.Open strCn
' 设置该属性, 使 recordcount 和 absolutepage 属性可用
t1 = Text0(1).Text
t2 = Text1(0).Text
t3 = Text2(2).Text
t4 = Text3(1).Text
If OptionButton1.Value = 0 Then
t5 = "2"
Else
t5 = "1"
End If''t5 = Mid(Text1, InStr(Text1.Text, "a4") + 2, Len(Text1.Text) - InStr(Text1.Text, "a4") - 3)If t1 = "0" And t2 = "0" And t3 = "0" And t4 = "0" Then '0000
Adodc2.RecordSource = "select * from 车间管理表 where 班次 like '%" & t5 & "%'"
Adodc2.Refresh
Adodc2.Recordset.Update
End If谢谢! 展开
Dim rs As New ADODB.Recordset
Dim strCn As String
Dim sql As String
strCn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\伟湟车间管理库.mdb;Persist Security Info=false"
cn.Open strCn
' 设置该属性, 使 recordcount 和 absolutepage 属性可用
t1 = Text0(1).Text
t2 = Text1(0).Text
t3 = Text2(2).Text
t4 = Text3(1).Text
If OptionButton1.Value = 0 Then
t5 = "2"
Else
t5 = "1"
End If''t5 = Mid(Text1, InStr(Text1.Text, "a4") + 2, Len(Text1.Text) - InStr(Text1.Text, "a4") - 3)If t1 = "0" And t2 = "0" And t3 = "0" And t4 = "0" Then '0000
Adodc2.RecordSource = "select * from 车间管理表 where 班次 like '%" & t5 & "%'"
Adodc2.Refresh
Adodc2.Recordset.Update
End If谢谢! 展开
2个回答
2013-05-24
展开全部
引用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~
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~
2013-05-24
展开全部
额,用ADO是可以直接select输出到excel的比如说,insert into [Excel 8.0;Database='c:\temp.xls].[''sheet1$''] (字段1,字段2,...) from ..........记得工作表名后面要跟 $
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询