WINWORD$ opens and creates an RTF document, saves it as Word document and returns the name of the document
WINWORD$ Template.rtf(Target$, Mode%=0, 1, 2, [InpVar])
Arguments
Qnowledge has provided a macro with the Quaestor distribution to assist with the creation of the RTF templates in MS Word. The file is by default installed in the "Qnowledge\Quaestor" directory and called "QnowledgeForm.dot".
To use this macro, place the file in the directory "startup" of Microsoft Office. Usually this is directory is in: "C:\Program Files\Microsoft Office\Office..\STARTUP". Please note that you might also need to change your Word macro security settings because the macro as no Thrust certificate.
After placing the file in the indicated directory an additional button is provided. For further explanation on the macro please click here.
The general process of creating the total functionality
The following steps are required to generate a document with Quaestor:
Step 1)
Create an RTF document and store it on the current applications directory (either of the knowledge base, located in Kbs\_<KnowledgeBaseName>\Applic, or the general Applic directory in My Knowledge).
For extensive information on document formatting options, please revert to the TEMPLATE$() function.
Step 2)
Verify the template document by using the menu option "Tools>RTF Template Check" in Quaestor.
This is necessary to remove parasite RTF codes in the format statements (just follow the instructions). Please note that MS Word includes RTF codes as it were on arbitrary locations which might destroy some of the code you have created to include functionality and parameters.
After you select the file (it shows the .rtf files on the current application directory), the check is performed and any changes are reported in a .log file. Quaestor reports the name of the original file, creates a .log file and makes a back-up of the original with a time stamp (2.46.2 and higher).
Step 3)
Load the knowledge base in which to include the document generator (or start with an empty KB (Newqkb))
Select in the knowledge browser the option New Relation and type expression.
Close the expression editor by selecting Save. If you select the new relation in the Browser, in the frame viewer you will see all existing parameters in the template are included in the expression. You may observe that template parameters in expression are not included. This is because the presence of parameters in logical expressions do not need to exist in the current solution to be used in the expression (this parameter being PENDING might also be information to be used). So if you want certain parameters to be present before the document is created, make sure these are included in the expression.
After this, your document generator is ready for use.
Step 4)
To generate a document, double click on the parameter connected to the expression to start the dialogue. Quaestor will either ask for values of the above parameters or calculate them (if possible). If the WINWORD$ function is invoked and finished, with the Mode% being 1, MS Word will open with the resulting document. This document is a normal Word document as any one created within Word itself. Note that the resulting document starts as a RTF document which will be saved as .DOC in Word, resulting in a considerable reduction of file size. Reports created by WINWORD$ can be of enormous size if, for instance graphical information is included. The original created document remains on the current Report directory.
After completion of the solution, the parameter connected to the expression will contain the name of the output document as returned/contained by Target$, without path information. All (intermediate) results of Quaestor sessions including program output and any generated documents are stored on the current (project's) Report directory.
The template document can contain any graphical and/or markup information deemed necessary. As mentioned above, on any location where you want to insert values computed byQuaestor in the template, it should be indicated using format statements between "#". See the TEMPLATE$() function for options.
In the example of a template:
TO FAX : #FAXNO$#
COMPANY: #COMPANY#
ATTN : #CLIENTCONTACT$#
SUBJECT: #SUBJECT$#
Dear ..
The power consumption at the design speed is #VDES|F6.2# knots.
#NS=2[1]#The vessel has two propellers[1]
With best regards,
#PROJMANNAME$#
In this example NS=2 is an expression that controls everything between the [1] labels. When true, the text between "[1]#" and "propellers[1]" is added, if false the part between "#NS" and "propellers[1]" is removed.
Please check the rtf document with Quaestor. After checking the above template, Quaestor will show the resulting log made of the required changes Quaestor made. This might be as followed:
#FAXNO$#
#FAXNO$#
#COMPANY#
#CLIENTCONTACT$#
#SUBJECT$#
#VDES|F6.2#
#NS=2[1]#
[1]
#PROJMANNAM}{\f2\lang1033\cgrid0 E}{\f2\lang1033\cgrid0 $#
RTF code in parameter or constraint, removal attempted =>
RTF code in parameter or constraint, removal attempted =>
#PROJMANNAME$#
The example shows that there was some RTF code that had to be removed.
Using the above template, we make an expression using the template with the WINWORD$ function:
DataReport$ = WINWORD$ DataFax.rtf(FaxFile$, "1") |
After saving the expression you will see that the additional parameters are added, resulting into the following expression:
DataReport$ = WINWORD$ DataFax.rtf(FaxFile$, 1, FAXNO$, COMPANY, CLIENTCONTACT$, SUBJECT$, VDES, PROJMANNAME$)
You will see that NS has not been included. If you want NS to be present, provide the first relation as:
DataReport$ = WINWORD$ DataFax.rtf(FaxFile$, 1, NS)
which will give
DataReport$ = WINWORD$ DataFax.rtf(FaxFile$, 1, NS, FAXNO$, COMPANY, CLIENTCONTACT$, SUBJECT$, VDES, PROJMANNAME$)
Document parts
When you want to add a separate document part as part of the template add a document tag to this document part. Using the example, you can do this in this way:
TO FAX : #FAXNO$#
COMPANY: #COMPANY#
ATTN : #CLIENTCONTACT$#
SUBJECT: #SUBJECT$#
Dear ..
The power consumption at the design speed is #VDES|F6.2# knots.
#NS=2[1]#The vessel has two propellers[1]
#DocumentTag$#
With best regards,
#PROJMANNAME$#
In the template we added #DocumentTag$#. This parameter will contain the document tag required to include the separate document with the correct name. By setting this all up parametrically it will stay working for one or more cases. So we will add the following relation:
DocumentTag$="#"+SubDocument$+"#"
In which SubDocument$ is the parameter generating the sub document, comparable to DataReport$ above.
Furthermore, add DocumentTag$ and SubDocument$ to DataReport$.
When you use several objects, data from these objects can be addressed in the template. This done as follows:
#ObjectName.ParameterName#
or
#ObjectName.ObjectName.ParameterName#
etc.
You will receive the data for the case of ParameterName which is selected at the moment of document generation. For a specific case you have to add a number, like for case 3:
#ObjectName.ObjectName.ParameterName.3#
When you want to receive all case values for ParameterName you have to write:
#ObjectName.ObjectName.ParameterName.0#
You will receive all cases separated with a CrLf.
When you want to address values in TeLiTab data, it is slightly different. You can address this in the template as follows:
#TeLiTabName.ParameterName#
If the object or TeLiTab contains several cases for the parameter, you will receive all parameters as a list of values with carriage return linefeeds (CrLf) in between. When you want a nice comma separated sentence instead, you have to create a separate parameter for the list of values and use additional attributes in the data slot of the expression.
For example, within a "Calculation" object you have done calculations on one or more Rigs with a "RigNumber". Place the summary parameter "RigNumber$" in the template:
#RigNumber$#
And create a relation:
RigNumber$=Calculation.RigNumber
with in the dataslot of this expression:
@TEXTDELIMITER:", "
@TEXTLASTDELIMITER:" and "
The attributes indicates that comma's should be used between values and that the final two values should have " and " between them.
This is very much like adding sub-documents. Use the @RUNWORDMACRO() function to create a Word macro for a table based on TeLiTab input (when required create the TeLiTab first with the TELITAB#() function). In the template add the reference to the parameter that creates the table macro and also add this parameter to the relation that uses the template.
Quick links: Functions overview | Attribute overview | Constants overview | Dimensions overview