GrapeCity Documents for Word (GcWord), is a Word API offering a complete solution to programmatically create, modify, and save Word documents in .NET Core applications without installing MS Word on your system. The object model is based on Microsoft Office API, Word Javascript API, and OpenXML SDK to create complete MS Word-like documents.

With GrapeCity Documents v2 sp2, GcWord is adding more Microsoft Word OM features to the API. The Word documents will generate a richer and common feature set that will handle more data. The special highlights of v2 sp2 include the support of content controls, easily designed form-based Word documents, and the ability to bind with XML data.

Read the full GcDocs release

Let's dive in.

Support for Content Controls

Creating templates, forms, or documents are some common scenarios executed in MS Word; for example, arranging a school parent/teacher meeting using dynamic forms. The form should be a template that includes the school logo and school name by default along with the form field labels. The school has thousands of active students and would like to generate a pre-filled field bound to a database in order to send it online.

Document Word API

With the support of Content Controls, forms can now be designed using GcWord. You can add many types of content controls with respective properties to design forms and templates.

New Types of Content Controls

  • RichText
  • Text
  • Picture
  • ComboBox
  • DropdownList
  • BuildingBlockGallery
  • BuildingBlock
  • Date
  • Group
  • CheckBox
  • Equation
  • Bibliography
  • Citation
  • RepeatingSection
  • RepeatingSectionItem
  • ExternalContentEntityPicker

Help | Demo

Support Custom XML Parts and XML Mapping

Custom XML parts are used in Word documents to store XML data. Content controls can be bound with these XML parts to generate forms and template documents. A good part of this binding occurs when a user edits the text in the UI of Word document and the corresponding XML element is automatically updated. Similarly, if element values in the custom XML parts are changed, the bound content controls to the XML elements display the new data.

The binding of content control with XML parts can be used in many scenarios. For example, an online store wants to send annual greetings to customers and needs to add a customized note, stating the yearly bonus added to the account.

Document Word API

The data is in the form of an XML document that contains XML data with the customer's name and other details. This data needs to be mapped to the content controls in order to generate multiple greeting letters. In the document above, CustomerName from the XML file is mapped to PlainText content control.

In this release, we added the capability of binding content controls to these XMP parts using CustomXMLPart class in GcWord. You can add, load, and modify custom XML parts and save the document with custom XML parts as .docx files.

Binding in this way is convenient because if a user edits the text in the UI of Word document, the corresponding XML element is automatically updated. Similarly, if element values in the custom XML parts are changed, the content controls that are bound to the XML elements display the new data. To bind content controls with XML parts, GcWord also provides the XMLMapping class. You can map the content control with the XML node, or map any built-in property value with a content control.

GcWordDocument doc = new GcWordDocument();

// create custom xml element to map
const string ns = "http://cusomxml/";
XmlDocument xml = new XmlDocument();
xml.AppendChild(xml.CreateXmlDeclaration("1.0", "utf-8", null));
XmlNode root = xml.AppendChild(xml.CreateElement("root", ns));
XmlNode child = root.AppendChild(xml.CreateElement("child", ns));
child.InnerText = "test value";

// add the xml document to a new custom xml part
doc.CustomXmlParts.Add(xml);

// map a new content control to the xml element
ContentControl cc = doc.Body.ContentControls.Add(ContentControlType.Text, false);
// gets the content control mapped value
string value = cc.XmlMapping.SetMapping(child);

// change the mapped value in the xml document and the content control
cc.XmlMapping.TrySetValue("new test value");

// set a built-in property value
doc.Settings.BuiltinProperties.Author = "me";
doc.Body.Paragraphs.Add();
// add a new content control for the built-in property
ContentControl ccp = doc.Body.ContentControls.Add(ContentControlType.Text, false);
// map the built-in property value with the content control
// now when a user user changes the content control value the built-in property will be changed automatically
string author = ccp.XmlMapping.SetMapping(() => doc.Settings.BuiltinProperties.Author);

doc.Save("xml-mapping.docx");

Help | Demo

Support for Adding Glossary Documents

You may have certain content that you do not want to appear in the Word document, but still want to keep it as part of the document for future insertion as per user action. A Glossary document acts as supplementary document storage that stores the definition and content for those instances.

For example, if you have real estate contract document where you would like to keep certain optional clauses, you would want to add them as an optional clause and to choose from the footer dropdown.

Word API - Glossary Documents

GcWord adds the GlossaryDocument and BuildingBlock classes to be able to add this type of kind of content to Word documents. Since this is in MS Word, there are several pre-defined blocks of text and formatting (known as Building Blocks). The Building Block galleries include pre-formatted Headers, Footers, Page Numbers, Text Boxes, Cover Pages, Watermarks, Quick Tables, Tables of Contents, Bibliographies, and Equations. The BuildingBlock class will help in adding content, (like a GlossaryDocument) to any Building Block Gallery type.

Help | Demo

What do you think about above features in GcWord? Please leave a comment below.

Try the new GrapeCity Documents for Word

Download GrapeCity Documents for Word

Download Now!