Current location - Quotes Website - Signature design - Replacement of Word Content in PB [1]
Replacement of Word Content in PB [1]
This paper introduces a method based on Power Builder (hereinafter referred to as PB) to convert the data in the database into Word documents by using OLE. In this way, users can change the content as needed and print the resulting document in Word mode. For example, when dealing with students' grades, each student's grade report should be generated as a Word document. Different students only change data such as name, student number and year, and other formats remain unchanged. The problem can be solved as long as specific data is transferred from the student score database and inserted or replaced into the Word template that has been made.

Word template documents are created according to the needs of users. The location of fixed content (such as name, year, certificate number, etc.) after input. ) is entered into codes such as student name, student year and student id. Note: Try to express these variables in English to avoid incorrect substitution caused by the same Chinese characters.

You don't need to enter text where you need to dynamically change the content, but you can do this by inserting bookmarks. The specific operation is as follows: first, select Insert * bookmark in Word to pop up the bookmark dialog box (as shown in the figure), enter the bookmark name in the book signature text box, and then click the Add button to add a bookmark at the current cursor position. Suppose we add a bookmark, that is, name, year department and id, which represent name, year department and certificate number respectively.

2pb implementation method

Create a new OLE control in the form. Select the Microsoft Word document option in the New tab of the pop-up Insert Object Properties window. Click the OK button to place the control in the appropriate position in the form. PB system will appear automatically. The Microsoft Word application named the control OLE_Word and created an open file to replace the data and save the file. Write the following code.

. Open the file string docname named integer value = getfileopenname (select file docname named doc files (* doc) * doc) If value = then//, save the template file as an actual operation file (the program is abbreviated). If ole _ wordopen (docname) = then ole _ wordactivate (inplace! )end if end if

Here, the GetFileOpenName function is used to allow users to select their own files for practical applications. Note: Before opening the template file, you need to save it as an actual operation file. Template files cannot be manipulated directly. There are several parameters for opening a file, among which inplace refers to calling Word in the internal window of PB program to provide a function menu of Word; Another parameter is leaving the station, that is, starting the Word application program outside the PB program to provide all the functions of Word. A simple presentation document is shown in the figure.

Lishi Xinzhi/Article/program/PB/20 13 1 1/24577