This is part two of a multi-part series highlighting various use cases for the new GcWord V4 API Report Template feature to automate new documents in specific industries. In this edition, I will show you how to easily use GcWord Report Templates to automate a process within the Finance industry, specifically managing a set of closing documents (when buying or selling real estate).
A new development partner has approached you with a project they are working on. With a huge influx of buyers moving to more rural areas during the pandemic, they need a way to automate the creation and storage of closing documents for their multi-million dollar Real Estate business. After several fact-finding conversations, you determine you can connect to their existing MySQL database, which collects and houses information on their buyers.
In turn, pull information from this database to automatically populate documents that have been created as a template for their closing documents. You assure them, this will be very easy because you are working with GrapeCity, and their GcWord API will work wonders for them in this situation!
Using the new GcWord API V4, you will be saving the client time, energy, and money and reducing errors due to multiple data entry points. This blog demonstrates how to use the GcWord API (using C#) to quickly and efficiently create and save documents using GcWord Report Templates (and the 'mustache' syntax) from an existing data source.
For a much more detailed look at all various options in a single blog, check out the original introductory blog on GcWord Report Templates.
See the step-by-step instructions below to get started and download a complete sample project here (example form in the project may differ from the below example).
Steps to Create Word template
The GcWord V4 API utilizes a customer Report Template (similar to MS Word Templates) but uses a "mustache syntax" to indicate the fields being populated through a data source. An example of the closing disclosure document is shown below with the proper syntax.
Notice the consistent use of double curly brackets on both sides of the templated field name. There are more advanced features with this syntax, covered in a separate blog, allowing the use of these templates with datasets. For now, we will focus on this template and some of the field properties and features. Note that only a few format specifiers are used, but they are consistent and easy to understand. The GcWord API utilizes the standard .NET format specifiers as defined here:
The chart below will help you to understand the layout of the Closing Document sample:
Below is the example of the Loan Closing Disclosure statement Report Template, followed by the results:
Steps to Create Files from Word Template
To use the GcWord V4 API to create documents from this template, follow the example located here, but here is a synopsis of the steps required:
- Be sure to include all appropriate namespaces in your project:
- Next, instantiate a new GcWordDocument object and load your template file:
var doc = new GcWordDocument();
//now load your file
doc.Load(Path.Combine("Resources", WordDocs", "House_Rental_Template.docx");
- Set up a dataset:
var ds = new DataSet();
- Read the data into the object (In this case, an XML file):
ds.ReadXml(Path.Combine("Resources", "data", "GcWordTplDataSet.xml"));
- Lastly, process and save the document (typically called from a separate method which returns an object of type GcWordDocument):
As stated, the full example and our documentation site have more information, but the above steps are the main portions required to utilize the API to get a template and create a new file from a data source.
The final product will look like this:
Download a sample (sample may differ slightly from the above example) and give it a try! Next month, the third part of this series will discuss how to set up another word template document for a different industry.
I hope this helps get the imagination flowing on all the ways to utilize the GcWord V4 API.