Complex Document Abilities

Currently I maintain a very complex technical docuement that covers software installation. The complexities come from all the possible options that are available to the end user to select from when installing the software. What I am looking to do is to develop an application that will present the end user with a list of questions or options and depending on the answers a doc will be generated based on the users input. The generated document would be made up of sections from the main document. Is this application with in the realm of the Aspose Word product family? If so, at a high level what would be the best way to break up the master document? Would it be through sections or bookmarks? Any input or advice would be greatly appreciated.
Thanks
Ron Gregory

Hi

Thanks for your request. I think, in your case, you can use both sections and bookmarks simultaneously. Section will represent part of content and bookmark will identify Section. You should just insert bookmark at the beginning of the Section and you will be able to use code like the following to find out Section by bookmark name.

// Open the document
Document doc = new Document(@"C:\Temp\in.doc");
// Remove the second section for the docuemnt using a bookmark as a marker.
Bookmark bk = doc.Range.Bookmarks["sect2"];
if (bk != null)
{
    // Get section where the bookmark is located and remove it.
    Section sect = (Section) bk.BookmarkStart.GetAncestor(NodeType.Section);
    if (sect != null)
        sect.Remove();
}
// Save output document
doc.Save(@"C:\Temp\out.doc");

Hope this helps. Please let me know if you need more assistance, I will be glad to help you.
Best regards,

Thanks for your reply, I really do appreciate it. I have a related question to your response. Lets say with in one of the sections that I want to include there is currently 3 identical commands but the syntax is different based on the OS. So I would like to strip out the other two commands in the section and only keep the command based on the OS the user selected? So if I have created a section and have a bookmark within the section how would I go about stripping out the other two commands?
Thanks
Ron Gregory

Hi

Thanks for your request. But unfortunately, it is not quite clear for me what you mean. Could you please provide me sample document and expected output? I will check the documents and provide you more information.
By the way, what do you mean under “commands”?
Best regards.

I apologize for not making it more clear. I’m including a little snippet from the document:
1.1 Copy the SOURCE Replicate Temporary Directory from SOURCE to All TARGET Application Nodes

[ NODE(S)]
Note: Perform this step only on ALL TARGET application nodes that do not contain SOURCE.

  1. Copy the SOURCE replicate temporary directory from SOURCE to all TARGET nodes that do not contain SOURCE.

On VMS, enter the following command:
$ BACKUP/LOG/IGNORE=INTERLOCK :[…]. :[…].
If the above command does not work with the current system configuration, the directory should be FTP’d from the SOURCE node to the TARGET node.
On AIX and HP-UX, enter the following command:
/usr/bin/scp –rp :/// //*
So for this example I want to include this section in the generated document but the target OS is AIX/HP-UX so I would not want the VMS commands displayed.

Hi Ron,

Thank you for additional information. I think, the best way to achieve what you need is using IF fields. IF field code will look like the following:
{ IF “On VMS, enter the following command:
$ BACKUP/LOG/IGNORE=INTERLOCK :[…]. :[…].
If the above command does not work with the current system configuration, the directory should be FTP’d from the SOURCE node to the TARGET node.” “On AIX and HP-UX, enter the following command:
/usr/bin/scp –rp :/// //*” }
I attached sample document and here is sample code. I use mergefield in the condition (Press Alt+F9 to see field codes).

Document doc = new Document(@"Test001\in.doc");
doc.MailMerge.Execute(new string[]
{
    "isVMS"
}, new object[]
{
    "true"
});
doc.Save(@"Test001\out.doc");

Hope this helps.
Best regards.

Where can I find the sample document that you attached?
Thanks
Ron

Hi Ron,

The documents are attached.
Best regards.

Thanks for your help. Where can I go to see the underlying code in each of these two documents?
Ron

Hi Ron,

Thanks for your inquiry. in.doc was created in MS Word. This is template document. Then I used the following code to generate out.doc

Document doc = new Document(@"Test001\in.doc");
doc.MailMerge.Execute(new string[]
{
    "isVMS"
}, new object[]
{
    "true"
});
doc.Save(@"Test001\out.doc");

During mail merge process IF field is evaluated and in the final document you see the expected value. (Press Alt+F9 in MS Word to see the field codes)
Best regards.

When I press (Alt + F9) in the “In Doc” the VMS section is removed which is perfect. My question is where did you set the value for “is VMS” and how did the template know which section to remove?
Thanks
Ron Gregory

Hi Ron,

Thanks for your request. IF field’s code looks like the following:
{ IF }
If condition is true – true_value text is displayed, otherwise false_value text is displayed. In your case IF field looks like the following:
{ IF “{ MERGEFIELD isVMS }” = “true” " On VMS, enter the following command:
$ BACKUP/LOG/IGNORE=INTERLOCK :[…]. :[…].
If the above command does not work with the current system configuration, the directory should be FTP’d from the SOURCE node to the TARGET node." " On AIX and HP-UX, enter the following command:
/usr/bin/scp –rp :/// //*" }
As you can see there is a mergefield in the condition expression. After executing the following code:

Document doc = new Document(@"Test001\in.doc");
doc.MailMerge.Execute(new string[]
{
    "isVMS"
}, new object[]
{
    "true"
});
doc.Save(@"Test001\out.doc");

Please see the following link to learn more about mail merge:
https://docs.aspose.com/words/net/mail-merge-and-reporting/
Mergefield with name isVMS is replaced with value “true” and in the output document you see only true text. IF Field code will look like this:
{ IF “true” = “true” " On VMS, enter the following command:
$ BACKUP/LOG/IGNORE=INTERLOCK :[…]. :[…].
If the above command does not work with the current system configuration, the directory should be FTP’d from the SOURCE node to the TARGET node." " On AIX and HP-UX, enter the following command:
/usr/bin/scp –rp :/// //*" }
Best regards.

For the “in doc” template is the code stored in a macro? I’m not finding the code your using to run the mailmerge in the “In Doc”.
Thanks
Ron

Hi Ron,

Thanks for your request. No, code is not stored in macro or anywhere else. This is C# code, which uses Aspose.Words to process a document. For example if you would like to run this code in console application, it will look like this:

using Aspose.Words;
namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            // Open input document.
            Document doc = new Document(@"C:\Temp\in.doc");
            // Execute mail merge.
            doc.MailMerge.Execute(new string[]
            {
                "isVMS"
            }, new object[]
            {
                "true"
            });
            // Save output document.
            doc.Save(@"C:\Temp\out.doc");
        }
    }
}

Please see the documentation for more information:
https://docs.aspose.com/words/net/
Best regards.