DBF database batch transfer Word document

  
How does the data in the DBF database go to the WORD document? Manual copying and pasting takes a lot of time and effort. In fact, a small piece of code can solve the problem. You just have to copy it. The following system home will introduce you to the DBF database batch transfer Word document tutorial. In the recent work, the author needs to sort and sort some document information regularly, and use Visual FoxPro to make DBF data table files. At the same time, I need to export Excel documents according to the data table, and make a Word document information table for printing output. Since the table structure of the DBF data table and the table fields in the Word document are fixed, and the amount of document information that is sorted out is quite large, it takes a lot of time and effort to copy and paste manually. Therefore, the author has written a batch copy. Small program, that is, automatic output of DBF data to Word document table. The program development environment is: VB6.0, Foxpro 6.0, Word 2003. Related technologies for program applications are: ADO (ActiveX Data Objects), OLE (Object Linking and Embedding). The basic idea of ​​program implementation is to access the DBF data table through ADO, get the data table content, and write it to the fixed format Word document table. The main objects used are ADODB.Connection, ADODB.Recordset, Word.Application, Word.Acttivedocument, Word.Range, and so on. Access to DBF data tables through ADO, VB code is as follows: Dim cn As New ADODB.Connectioncn.ConnectionTimeout = 15cn.ConnectionString = "Provider=MSDASQL;" & _"Driver={Microsoft Visual Foxpro Driver};" & _"SourceType=DBF;" & _"SourceDB=" & dbfpathcn.Open to achieve DBF data table data acquisition, VB code is as follows: Private rec As VariantDim rs As ADODB.Recordsetet rs = New ADODB.RecordsetDim Sqlstr As Stringsqlstr = "select * from " & dbfnamers.Open sqlstr, cn, adOpenStatic, adLockPessimisticrec = rs.GetRows(n) Open Word document via OLE implementation, VB code is as follows: Private objWD As word.ApplicationSet objWD = CreateObject ("Word.Application")objWD.Documents.Open newfile ‘newfile Fill in the contents of the Word document table for the file name, 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 the Recordset dataset) For ease of use, all the code (FIG.) May also be downloaded to http://iask.sina.com.cn/u/ish?uid=1704202287. This article comes from [System Home] www.xp85.com
Copyright © Windows knowledge All Rights Reserved