How does a DBF database bulk turn to Word documents?

Source: Internet
Author: User
Tags manual ole requires

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.