...如何编写代码使数据库导出到excel、word或html上?
发布网友
发布时间:2024-04-21 05:27
我来回答
共2个回答
热心网友
时间:2024-10-04 14:27
Private Sub Command1_Click()
Dim xlapp As Variant
Dim xlBook As Variant
Dim xlSheet As Variant
Dim sum As Long
Set xlapp = CreateObject("excel.application")
Set xlBook = xlapp.Workbooks.Open(App.Path & "\data\报表.xlt") '打开EXCEL模板
'Set xlBook = xlapp.Workbooks.Add
Set xlSheet = xlBook.worksheets(1)
xlapp.Visible = True
Adodc1.ConnectionString = cn.ConnectionString
Adodc1.RecordSource = "select * from [Sheet1] where 试验号='" & shiyanH & "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
xlSheet.Cells(sum + 1, 2) = shiyanH
For sum = 0 To Adodc1.Recordset.RecordCount - 1
xlSheet.Cells(sum + 3, 1) = Adodc1.Recordset(1)
For j = 2 To 21
If Adodc1.Recordset(j) <> "" Then
If Adodc1.Recordset(j) = "********" Then
xlSheet.Cells(sum + 3, j) = (Adodc1.Recordset(j))
Else
xlSheet.Cells(sum + 3, j) = Val(Adodc1.Recordset(j))
End If
End If
Next
Adodc1.Recordset.MoveNext
Next sum
End If
End Sub
Sub Main()
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\tsdb.mdb;Persist Security Info=False"
frmStart.Show
End Sub
以上是读取Access数据表,导入到Excel的代码。
热心网友
时间:2024-10-04 14:23
可以的,私信一下我
热心网友
时间:2024-10-04 14:23
Private Sub Command1_Click()
Dim xlapp As Variant
Dim xlBook As Variant
Dim xlSheet As Variant
Dim sum As Long
Set xlapp = CreateObject("excel.application")
Set xlBook = xlapp.Workbooks.Open(App.Path & "\data\报表.xlt") '打开EXCEL模板
'Set xlBook = xlapp.Workbooks.Add
Set xlSheet = xlBook.worksheets(1)
xlapp.Visible = True
Adodc1.ConnectionString = cn.ConnectionString
Adodc1.RecordSource = "select * from [Sheet1] where 试验号='" & shiyanH & "'"
Adodc1.Refresh
If Adodc1.Recordset.RecordCount > 0 Then
Adodc1.Recordset.MoveFirst
xlSheet.Cells(sum + 1, 2) = shiyanH
For sum = 0 To Adodc1.Recordset.RecordCount - 1
xlSheet.Cells(sum + 3, 1) = Adodc1.Recordset(1)
For j = 2 To 21
If Adodc1.Recordset(j) <> "" Then
If Adodc1.Recordset(j) = "********" Then
xlSheet.Cells(sum + 3, j) = (Adodc1.Recordset(j))
Else
xlSheet.Cells(sum + 3, j) = Val(Adodc1.Recordset(j))
End If
End If
Next
Adodc1.Recordset.MoveNext
Next sum
End If
End Sub
Sub Main()
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\data\tsdb.mdb;Persist Security Info=False"
frmStart.Show
End Sub
以上是读取Access数据表,导入到Excel的代码。
热心网友
时间:2024-10-04 14:26
可以的,私信一下我