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).

Try GrapeCity Documents for Word

Download the latest version of GrapeCity Documents for Word

Download Now!

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:

https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-numeric-format-strings

The chart below will help you to understand the layout of the Closing Document sample:

steps to create a word template

Below is the example of the Loan Closing Disclosure statement Report Template, followed by the results:

Sample template file for Loan Closing Disclosure Statement to be used by GcWord V4 API in C Sharp by GrapeCity

Download this template here

Sample completed file for Loan Closing Disclosure created by GcWord V4 API in C Sharp by GrapeCity

Download the completed document here

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:

  1. Be sure to include all appropriate namespaces in your project:

GrapeCity Documents

  1. 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");
  1. Set up a dataset:
var ds = new DataSet();
  1. Read the data into the object (In this case, an XML file):
ds.ReadXml(Path.Combine("Resources", "data", "GcWordTplDataSet.xml")); 
  1. Lastly, process and save the document (typically called from a separate method which returns an object of type GcWordDocument):
doc.DataTemplate.Process(System.Globalization.CultureInfo.GetCultureInfo("en-US"));

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:

Sample completed file for Loan Closing Disclosure created by GcWord V4 API in C Sharp by GrapeCity

Next Steps

Download the 30 day Trial!

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.

Happy coding!

Try GrapeCity Documents for Word

Download the latest version of GrapeCity Documents for Word

Download Now!