GroupDocsGists
10/24/2017 - 1:30 PM

generating report in groupdocs.assembly 1.3.0.cs

// For complete examples and data files, please go to https://github.com/groupdocsassembly/GroupDocs_Assembly_NET
private static TemplateEditor ProcessWord()
       {
           var templatePath = Path.Combine(_dirPath, "WordTemplate.docx");

           WordsTemplateEditor templateEditor = new WordsTemplateEditor(templatePath);

           if (!templateEditor.IsSupported)
           {
               throw new NotSupportedException("Document is not supported");
           }

           var hasFields = templateEditor.HasFields;
           var words = templateEditor.GetWords();
           if (!hasFields)
           {
               if (words.Length == 0)
               {
                   throw new Exception("Document is empty. Library is not working with empty Word document!");
               }
           }

           var insertField = new Groupdocs.Assembly.Words.TextField
           {
               Name = "MergeField",
               Position = words[0].Position,
               Length = words[0].Value.Length
           };

           if (!templateEditor.IsFieldExist(insertField.Name))
           {
               templateEditor.AddField(insertField);
           }
           else
           {
               var deletingField = templateEditor.GetField(insertField.Name);
               templateEditor.RemoveField(deletingField);
           }

           templateEditor.Save();

           return templateEditor;
       }