|
| 1 | +REM Word Templating - ApplicationForm (example5) |
| 2 | +REM (This example is similar to example1 at wordTest1.bas) |
| 3 | +REM Create a Loan Application Form by populating with data the template and |
| 4 | +REM attaching a second document at the end of the first. The example demonstrating |
| 5 | +REM how to retrieve only the necessary for the template data from the database. |
| 6 | +REM |
| 7 | + |
| 8 | +rem Prepare template documents |
| 9 | +FILESTREAM template, inmemory, "", "other", "LoanTemplate.docx" ' Streams Library |
| 10 | +FILESTREAM final, out, "", "Output", "example5.docx" |
| 11 | +WORDEXTRACTBODY template, text ' Templating Library |
| 12 | + |
| 13 | +rem Extract metadata |
| 14 | +PHVSDATA allNames text ' TextReplacer Library |
| 15 | +PHSdata cnames text ' TextReplacer Library |
| 16 | + |
| 17 | +rem Orchestrate the needed data |
| 18 | +print "Load data on demand..." |
| 19 | +let AppID=1010 ' Input from the caller application |
| 20 | +let Today = date() |
| 21 | + |
| 22 | +foreach cnames |
| 23 | + loginfo "Setting up...."+[cnames.ph] |
| 24 | + phgosub [cnames.ph] else notfound ' TextReplacer Library |
| 25 | +endforeach cnames |
| 26 | + |
| 27 | + |
| 28 | +rem (v) Do the replacement and save the document |
| 29 | +loginfo "Creating the new document" |
| 30 | +WORDREPALCEBODY template, ALL, allNames ' Templating Library |
| 31 | + |
| 32 | + |
| 33 | +rem (v) Append Consent |
| 34 | +FILESTREAM Consent, in, "", "other", "Consent.docx" |
| 35 | +WORDAPPEND Consent, template |
| 36 | + |
| 37 | +SCOPY template,final ' Streams Library |
| 38 | + |
| 39 | +halt |
| 40 | + |
| 41 | +rem |
| 42 | +rem ...............DATA SOURCES................... |
| 43 | +rem |
| 44 | +Appl: |
| 45 | +loginfo "Loading Application: "+AppID |
| 46 | +retrieve Appl,NEW,1, "select CustomerID,RequestedAmount,LoanTerms,Purpose,ApplicationDate from Applications where ApplicationID="+sql(AppID) ' SQLData Adapter |
| 47 | + |
| 48 | +return |
| 49 | + |
| 50 | +Cust: |
| 51 | +loginfo "Loading Customer:"+[Appl.CustomerID] |
| 52 | +retrieve Cust,NEW,1, "select Name,VatNumber,Email,Address,City from Customers where CustomerID="+sql([Appl.CustomerID]) |
| 53 | + |
| 54 | +return |
| 55 | + |
| 56 | +notfound: |
| 57 | +print "***NOT FOUND***" |
| 58 | +return |
| 59 | + |
| 60 | +End |
0 commit comments