Skip to main content Skip to footer

What's New in Documents for Word v4

GcWord v4.2 - August 19, 2021

Support Multiple Data Sources in Single Template

In complex business applications, data is stored or retrieved from multiple data sources. GcWord Report Templates now supports binding Word Report Templates with data from multiple data sources.

New Copy/Paste Options

In order to ensure that the copied and pasted range in a Word document has similar formatting and is not affected with the other document’s styles of default properties, GcWord adds a new enum option KeepSource to type FormattingCopyStrategy.

Shapes and Textboxes support in Word to PDF and Images Export

Exporting Word to PDF supports Shapes in Word documents. Many shapes also have special adjustments, such as the radius of the internal circle for the Donut shape. These adjustments are now fully supported in GcWordLayout.

GcWord v4.1 - April 30, 2021

  • Improved Copy and Move Range Operations - Improved functionality when applying copy and move range operations in Word documents.
  • Support for Malformed Hyperlinks in Word Template Processing - Supports the opening and saving of Word documents with malformed URLs in hyperlinks.
  • Added the Ability to Remove Empty Runs during Replace Operations - introduces FindReplaceOptions.RemoveEmptyRuns boolean property indicating whether the replace should remove empty runs or not.
  • Added New overloads to Add Images using .NET Image and GcImaging - Use both .NET Image and GcImaging classes to add images in Word documents.

Read the full Documents 4.1 release blog.

GcWord v4 - December 10, 2020

Generate Data-bound Word.docx Documents from GcWord Data Templates

Although organizations of all types use complex reporting, and many utilize Word as the file of choice, it is unnecessary to recreate complex reports from scratch each time. Rather, it's better to use a template approach, many of which are standardized in various industries and organizations. Once a templated approach has been established, it is easy with GcWord Word API to bind data to the template, creating dynamic, complex, and flexible Word .docx format reports. GcWord also supports Word mail-merge templates to make the automation of reporting requirements even simpler. The GcWord API saves the Word reports as .docx files, PDF files, or images. Developers can create a Word template using the mustache syntax to define the database fields, variables, bullets, lists, multi-level lists, and tables. This formatting makes it easy to replace the templated fields (those notated in mustache format). A data source is added by using the Word document object through the GcWordDocument.DataTemplate.DataSources collection and binding the data with the template using the GcWordDocument.DataTemplate.Process() method. This template API will detect the fields, matching them with the appropriate data in the database and replace with the actual data. There is also an option for batch processing through the DataTemplate.BatchProcess() method to generate a data-bound copy of the document for each iterated data object without changing the current document.

Generate the following reports:

  • Legal
  • Employee Contracts
  • House Lease Agreements
  • Invoices
  • Flight ticket
  • Itinerary
  • Price catalogs
  • And more

By using the GcWord Word API, you can do some of the following:

  • No need to create complex Word documents from scratch manually.
  • Changes to data in a database reflect automatically in the generated document by calling the GcWordDocument.DataTemplate.Process() method.
  • Make use of Microsoft Word formatting features to generate professional-looking documents.
  • Easily define Word templates with simple syntax in Microsoft Word.
Lease Agreement Example

Most states require tenants and landlords to have a lease agreement in place, and these documents tend to be standardized. Thus, this is a perfect example and use for the GcWord Word API for creating individual or multiple leases based on data in any database or spreadsheet.

Because these Lease Agreements are standard in format and involve replacing essential information in a template, it is easy to create Word templates in Microsoft Word and define data fields with mustache syntax. These fields should be replaced with the data from the database. With GcWord, you can add the data source using the GcWordDocument.DataTemplate.DataSources collection and bind the data with the template using the GcWordDocument.DataTemplate.Process() method.

Using the following code, the data fields will bind automatically to generate the final Lease Agreement .docx report, as you see below.

var doc = new GcWordDocument();  
            // Load the template DOCX:  
            doc.Load(Path.Combine("Resources", "LeaseAgreementTpl.docx"));
            
            using (var ds = new DataSet())  
            {  
                  // Load the data set:  
                  ds.ReadXml(Path.Combine("Resources", "data", "GcWordTplDataSet.xml"));  
                  // Add the data source to the data template data sources:  
                  doc.DataTemplate.DataSources.Add("ds", ds);  
                  // The document already has all the necessary bindings,  
                  // so we only need to process the data template:  
                  doc.DataTemplate.Process();  
                  doc.Save("Lease Agreement.docx");  
            }
            

Example of a lease template and final output using GcWord Word API to read and populate the template by GrapeCity

Key Features
  • Bind with any data source.
  • Batch process multiple rows of data into separate documents
  • Add bullets, numbered, multi-level lists
  • Supports hyperlinks
  • Support for tables
  • Repeat multiple table rows
  • Support for loops and nesting data
  • Conditionally hide blocks of data
  • Support for various formatting styles on data including:
  • Value Formats
  • Range Formats
  • String Formats
  • Date time Formats with DateTime and DateTimeOffset data types
  • Array and Collection Formats
  • Support variables from another data level in a single block

Read more details in this blog: Introducing Data Templates to generate data-bound Word documents in C# 

Help | Demo | Use Case samples

Enhanced Word (.docx) Files to PDF and New Images Export

Included with the v4 release of the GcWordLayout package is enhanced exporting of Word (.docx) files to PDF and new functionality for exporting Word (.docx) files to images.

Note a new, rewritten GcWordLayout package has replaced the old GcLayout package used in previous versions. It provides updates to the existing package, improving the export functionality of Word to several image formats (JPEG, PNG, and multi-frame TIFF) while introducing new PdfOutPutSettings to set additional properties while exporting to PDF.

Follow these simple steps to convert Word documents to PDF:

using GrapeCity.Documents.Word;  
            using GrapeCity.Documents.Word.Layout;  
            using GrapeCity.Documents.Pdf;
            
            class Program  
            {  
                static void Main(string[] _)  
                {  
                    var wordDoc = new GcWordDocument();  
                    wordDoc.Load(@"..\..\..\WordDocs\SimpleText.docx");  
                    using (var layout = new GcWordLayout(wordDoc))  
                    {  
                        // save the whole document as PDF  
                        layout.SaveAsPdf(@"..\..\..\Output\SimpleText.pdf", null, new PdfOutputSettings() { CompressionLevel = CompressionLevel.Fastest });  
                    }  
                }  
            }
            

Example of before & after conversion from Word file to PDF using the GcWord Word API by GrapeCity

Help | Demo

New Word (.docx) Files to Images Export

Exporting Word (.docx) documents to JPEG, PNG, and multi-frame TIFF files are easy using the ImageOutputSettings method. These settings help you set specific environment variables related to the images like; zoom factor, resolution, or background color. Additionally, you can either export the whole document to a Tiff or specific pages only for Tiff images. You can also specify TiffFrameSettings to encode a Tiff Frame and save it to a stream.

The following example exports a Word document to a JPEG image with a background color.

using GrapeCity.Documents.Word;  
            using GrapeCity.Documents.Word.Layout;  
            using GrapeCity.Documents.Imaging;  
            using System.Drawing;
            
            class Program  
            {  
                static void Main(string[] _)  
                {  
                    var wordDoc = new GcWordDocument();  
                    wordDoc.Load(@"SalesInvoice.docx");  
                    using (var layout = new GcWordLayout(wordDoc))  
                    {  
                        // save the first document as Jpeg  
                        layout.Pages[0].SaveAsJpeg(@"SalesInvoice.jpg", new ImageOutputSettings() { BackColor = Color.LightGray });  
                    }  
                }  
            }
            

Example of exporting a word document to a JPG image using GcWord Word API by GrapeCity

Help | Demo



Select Product Version...