How to create a word report with template dynamically?

Hello,Could you please help me with following question?
I used Aspose word to build a word report with template a month ago. But now,I meet a new requirement: my client hope the word report could be dynamic,that is to say,he sometimes want some form fieds to be hidden,but which fields to be hidden are not certain. Since I had build that report with a nice template before,could I do only a little changes to realize the new requirment? If not,what is the best way to build a dynamic word report with Aspose?
Thanks a lot

Hi
Thanks for your request. I think that you can remove the form fields during generating report. Also you can build your template contains multiple sections. And then remove unnecessary sections. See the following thread.

Also, please attach your template and code that you use to generate report. I will investigate it and try to help you.
Best regards.

Hello,thanks for your very quick reply and kind help.
Below is the main codes for inserting values into the predefined word template as my attached file. I mainly use bookmarks for positioning the place where to insert variables.
In following function, the first parameter “bookmarkValuePairs” is a two dimension array which has stored all my data,the secod parameter is only a location path.
For business confidential,I hide some data in the word template in attached file.
Await for your good news.

private byte[] CreateOfferInsuranceWordBuffer(string[,] bookmarkValuePairs, string strWordTemplateFileFullName)
{
    Document doc = new Document(strWordTemplateFileFullName);
    try
    {
        string oBookMark = null;
        for (int row = bookmarkValuePairs.GetLowerBound(0); row <= bookmarkValuePairs.GetUpperBound(0); row++)
        {
            oBookMark = bookmarkValuePairs[row, 0].ToString();
            if (doc.Range.Bookmarks[oBookMark] != null)
            {
                if (bookmarkValuePairs[row, 1].ToString().Trim().Equals("selected"))
                {
                    doc.Range.FormFields[oBookMark].Checked = true;
                }
                else if (bookmarkValuePairs[row, 1].ToString().Trim().Equals("unselected"))
                {
                    doc.Range.FormFields[oBookMark].Checked = false;
                }
                else
                {
                    doc.Range.Bookmarks[oBookMark].Text = bookmarkValuePairs[row, 1].ToString();
                }
            }
        }
    }
    catch (Exception e) { throw e; }
    try
    {
        MemoryStream ms = new MemoryStream();
        doc.Save(ms, SaveFormat.Doc);
        byte[] Buffer = ms.GetBuffer();
        ms.Close();
        doc = null;
        return Buffer;
    }
    catch (Exception e)
    {
        throw e;
    }
}

Hi
Thanks for additional information. Try to use the following code to solve your problem.

for (int row = bookmarkValuePairs.GetLowerBound(0); row <= bookmarkValuePairs.GetUpperBound(0); row++)
{
    oBookMark = bookmarkValuePairs[row, 0].ToString();
    if (doc.Range.Bookmarks[oBookMark] != null)
    {
        if (bookmarkValuePairs[row, 1].ToString().Trim().Equals("selected"))
        {
            doc.Range.FormFields[oBookMark].Checked = true;
        }
        else if (bookmarkValuePairs[row, 1].ToString().Trim().Equals("unselected"))
        {
            doc.Range.FormFields[oBookMark].Checked = false;
        }
        // If value is empty
        else if (bookmarkValuePairs[row, 1].ToString().Trim().Equals(string.Empty))
        {
            DocumentBuilder builder = new DocumentBuilder(doc);
            // move to bookmark
            builder.MoveToBookmark(oBookMark);
            if (builder.CurrentParagraph.ParentNode.NodeType == NodeType.Cell)
            {
                // if cell contains >1 paragraphs the remove only paragraph
                if ((builder.CurrentParagraph.ParentNode as Cell).Paragraphs.Count > 1)
                {
                    builder.CurrentParagraph.Remove();
                }
                // else remove whole cell
                else
                {
                    builder.CurrentParagraph.ParentNode.Remove();
                }
            }
        }
        else
        {
            doc.Range.Bookmarks[oBookMark].Text = bookmarkValuePairs[row, 1].ToString();
        }
    }
}

I hope that it will help you.
Best regards.

Dear Vitaly Shtanko,
Thank you very much for your excellent help. Your prompt support is very good.