WordCreateDocument
syntax
result = WordCreateDocument (template, document, option, tag)
Arguments
template, document, tag: text
option: numeric
result: integer (error code)
Meaning
With Microsoft Word, you can use ADAPL to place data from one or more records into a Word template to automatically create one or more documents.
Because the data is exported to a Word document that can be edited, WordCreateDocument allows you the freedom to use MS Word to change the format and layout of your exported data, before you actually print the document(s) from Word (or afterwards). (Note that direct printing of the generated document from within the output format, as used to be possible in Adlib, or via the Print button in the Output formats dialog in Collections is not possible.)
Use the arguments as follows:
• | template is a text variable or constant with the name of the (custom) Word template that you want to use. In Collections, you can only use templates with the .docx extension. |
• | document is a text variable or constant that may contain the file name (including file extension) in which the resulting document is to be stored. So the file name is used to create the document and to save it when it's completed. If you use a relative path in front of the file name, make sure it is relative to the application folder. Also, folder names used in paths (absolute or relative) must already exist, otherwise no documents will be generated. You cannot provide an empty document name.
From Collections 1.14, you can use a URL (to an image server able to store documents) to write to as well, using option 1024. |
• | option is a numerical variable or constant that determines a few settings (see table below). |
• | tag (optional):When creating a new Word document via the ADAPL Wordcreatedocument function, you may provide the file name and possibly a relative path in front of it. Typically, the adapl will then insert that (path\) file name in an application field. However, in Collections, an (adapl) hard-coded relative path and file name may conflict with a DAMS or image server storage URL and (a different) retrieval URL, because application fields are also open for uploading files manually by the user (turning the file names into GUIDs), bypassing the adapl, in which all uploaded files must end up in the same target folder/repository. In that case, Collections would normally not be able to write documents created by an adapl (and filled in in the application field) to the repository. To solve this problem, this (optional) tag option has been added to the Wordcreatedocument function, for which you must specify the field tag of the relevant application field (without quotes around it), so that Collections knows which base storage path to use. Instead of hard-coding the tag you may also use tag indirection, so if you've stored some field tag ax in a text variable called my_tag, then !my_tag could be used instead of ax. If the adapl needs to write a document in a sub folder of the storage path, then make sure that the repository already contains that sub folder, because Collections can't upload those files to a sub folder if it doesn't exist yet. Also note that a relative path to such a sub folder should not be preceded by ../ or ..\ because going up a folder level would conflict with the storage and retrieval URLs and also pose a potential security risk. Example: result = WordCreateDocument (template_path + templatename, docname, 1, !docreftag) This option is supported by the adapl compiler in Axiell Designer from version 7.6.18347.1. |
• | result is 0 when the operation was successful, otherwise an error code results. When creation of the Word document fails, a CONFIGURATION_ERROR will be returned: the details of the error will also contain the name of the problematic template. Those details can be retrieved via error$(val(result)) if result contains the function result code. |
Option |
Meaning |
0 |
MS Word will not be visible. With this option value, you can (also) export multiple records, although each record will be inserted in its own document. If you do want to export more than one record with this option, you should use a text variable in which you build up a new document name for each record, for instance by adding some incremented number to a fixed name. Otherwise only the last record will be saved in the specified document. |
1024 |
From Collections 1.14, it is possible to use a URL as the document argument: previously it always had to be a file name (possibly preceded by a path). For a URL you must of course provide one which can actually handle the writing of a document, like an Axiell WebAPI call using the writecontent command. Typically this URL is available in the Storage path property of the relevant application field, since you'd probably like manually uploaded documents by the user to be posted to that URL too. That could be a URL like: So suppose you have a repeatable application field tag DC and using an adapl you'd like to fill field occurrence 3 of this field with a document name formatted like mydocument<current date>.docx. An actual Word document with that name must be created in a location indicated by the Storage path (like the example above) set for field tag DC in the .inf. If you then have an empty destination_path text variable, a docreftag text variable containing string "DC", an integer occ variable containing occurrence number 3 and a template_path text variable containing the relative path and name of a Word template to use, then you could create the actual document and fill tag DC with the document name via: !docreftag[occ] = 'mydocument' + date$(8) + '.docx'
|
Example
integer result
result = WordCreateDocument ('c:\Axiell\templates\mytemplate0.docx', 'c:\Axiell\mydocs\test.docx', 0)
See also
Accessing data for a Word template from an adapl