How does the data in the DBF database go to a Word document? Manual copying and pasting requires a lot of time and energy, in fact, a small piece of code can solve the problem. You can just copy it. Here is a detailed introduction of DBF database batch to Word document tutorial.
In the recent work, I need to classify some document information regularly, and make the DBF data table file with Visual FoxPro, and also need to export the Excel document according to the data table, and make the Word Document Information table for printout. Because the table structure of the DBF datasheet and the table fields in the Word document are fixed, plus the amount of information collated every time, manual copying and pasting requires a lot of time and energy, so I wrote a small program to achieve mass replication, that is, the realization of DBF data to Word document forms of automatic output.
The program development environment is: Vb6.0,foxpro 6.0,word 2003.
The relevant techniques for application are: ADO (ActiveX Data Objects), OLE (Object Linking and embedding, object connection and embedding).
The basic idea of program realization is to access the DBF data table through ADO, get the contents of the data table and write it into a fixed format Word document table.
The main objects used are ADODB. Connection, ADODB. Recordset,word.application, Word.acttivedocument, Word.Range and so on.
Using ADO to realize the access of DBF data table, VB code is as follows:
Dim cn as New ADODB. Connection
cn. ConnectionTimeout = 15
cn. ConnectionString = "Provider=msdasql;" & _
"Driver={microsoft Visual Foxpro Driver};" & _
"SOURCETYPE=DBF;" & _
"Sourcedb=" & Dbfpath
cn. Open
To realize the data acquisition of DBF data table, VB code is as follows:
Private Rec as Variant
Dim rs as ADODB. Recordset
Et rs = New ADODB. Recordset
Dim Sqlstr as String
SQLSTR = "SELECT * from" & Dbfname
Rs. Open Sqlstr, CN, adOpenStatic, adLockPessimistic
rec = Rs. GetRows (N)
Open Word document through OLE implementation, VB code is as follows:
Private objWD as Word. Application
Set objWD = CreateObject ("Word.Application")
ObjWD.Documents.Open newfile ' newfile as filename
Implementation of the Word Document table content, VB code is as follows:
ActiveDocument.Tables.Item (i). Cell (J, Wordcol). Range.Text = Rec (j, i-1)
(Note: REC is a multidimensional array that stores data in a recordset dataset)
Description: For ease of use, all relevant code (such as the figure) can also be downloaded to http://iask.sina.com.cn/u/ish?uid=1704202287.
Note : more Wonderful tutorials please focus on the Triple computer Tutorials section, triple Computer office group: 189034526 Welcome to join