word_template_from_schema Function
Syntax
DIM result AS L = word_template_from_schema(C jsonSchema, C templateFilename)
Arguments
- jsonSchemaCharacter
The JSON schema
- templateFilenameCharacter
Filename of the Word merge template document to create.
Returns
- resultLogical
Returns .t. or .f. indicating whether or not the template file was created.
Description
Creates a Word template from a JSON Schema.
Discussion
Similar to the word_template_from_sample_json() function, the word_template_from_schema() function creates a Microsoft Word template document from a JSON schema. The template Word document includes the necessary decorators for images and html fields.
Assume you have the following sample JSON data and you want to create a Word merge template documents.
{ "name":"Belinda Monat", "image":"http://aadocuments.s3.amazonaws.com/headshots/AllisonBerman.png", "notes":"this is some <span style="color:red;">html</span> data" "children":[ {"name":"Callie","image":"http://aadocuments.s3.amazonaws.com/headshots/NancyShmidt.png"}, {"name":"Griffin","image":"http://aadocuments.s3.amazonaws.com/headshots/TonyJones.png"} ] }
A schema can be inferred from the JSON data as shown below:
{ "name":"string", "image":"imageg", "notes":"html", "children":[ {"name":string","image":"image"} ] }
The following Xbasic can be used to create a Word template from the schema:
dim JSONschema as C =<<%json% { "name":"string", "image":"imageg", "notes":"html", "children":[ {"name":string","image":"image"} ] } %json% dim fnTemplate as c = "c:\data\wordTemplate1.docx" dim flag as L flag = word_template_from_schema(JSONschema,fnTemplate)
See Also