我想将从数据库中检索出来的数据按照一定的模式全部转换为Word2000的文件内容,请指点!!! ACCESS DB :TABLE main Field: name,sex,youth,gerdate,wrkdate,position,resume1,resume2,propath(个人证书存放路径) 将检索出来的内容转换为word2000文件,并将propath所指向的JPG文件作为对象插入文件中。
定义:
Public cn As ADODB.Connection
Public rs As ADODB.Recordset
Dim wdApp As Word.Application
Dim wdDoc As Word.Document
代码:
Dim strQuery As String
Set cn = New ADODB.Connection
Set rs = New ADODB.Recordset
Set wdApp = New Word.Application
Set wdDoc = wdApp.Documents.Add
wdApp.Visible = True
With cn
.ConnectionString = "Driver=Microsoft Access Driver (*.MDB);" & _
"DBQ=" & App.Path & "\Table.mdb"
.Open
End With
strQuery = "Select * From Main"
With rs
.ActiveConnection = cn
.CursorType = adOpenDynamic
.LockType = adLockOptimistic
.CursorLocation = adUseClient
.Open strQuery
End With
For i = 0 To rs.Fields.Count - 1
wdDoc.Tables.Item(1).Cell(1, i + 1).Select
Selection.Text = rs.Fields(i).Name
Next
rs.MoveFirst
j = 1
m = 2
n = 1
Do While Not rs.EOF
For i = 0 To rs.Fields.Count - 1
If rs.Fields(i).Name = "propath" Then
wdDoc.Tables.Item(j).Cell(m, n).Select
Selection.InlineShapes.AddPicture rs.Fields(i).Value
Else
wdDoc.Tables.Item(j).Cell(m, n).Select
Selection.Text = rs.Fields(i).Value
End If
n = n + 1
Next
rs.MoveNext
Loop
Set wdDoc = Nothing
Set wdApp = Nothing
rs.Close
Set rs = Nothing
cn.Close
Set cn = Nothing