We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

Problem with Structured Document Tags (Content Controls) and .docx

Hi,

I am new to Aspose, so I might be overlooking something obvious.

I have a load of Word template files (.dotx) containing Structured Document Tags that has been handed to me by a client. Using Aspose.Words 10.8.0.0 I have been attempting to write some code to replace the content of the SDTs and save the resulting output to a file.

This has worked fine when saving to .xps or .pdf. However, when I change the output fileformat to .docx and open the result in Word the content of the tags is not replaced by the content I have defined in code.
I tried to insert an SDT of my own with Word2010, ran the code again and found that the tag I put in myself was replaced fine, but the other was not. When changing the output to .doc or .xps, both tags are replaced as expected.
If I unzip the .xml-files from the .docx, I can see my values in document.xml.

Here is some sample code that generates the output (sorry, not sure how to enable syntax highlighting … ):

using Aspose.Words;
using Aspose.Words.Markup;

namespace DocumentGeneration.Tryout.Managers
{
    public class SdtManager : AsposeManagerBase
    {
        private
        const string TemplateFile = @"C:\Aspose\Test\template2.dotx";
        private
        const string OutputDocxFile = @"C:\Aspose\Test\output-docx.docx";
        private
        const string OutputDocFile = @"C:\Aspose\Test\output-doc.doc";
        private
        const string OutputXpsFile = @"C:\Aspose\Test\output-xps.xps";
        private
        const string LicenseFile = @"C:\Aspose\license\license.lic";

        public SdtManager()
        {
            var license = new Aspose.Words.License();
            license.SetLicense(LicenseFile);
        }

        public void InsertNameAndSave(object name)
        {
            var document = new Document(TemplateFile);
            var tags = document.GetChildNodes(NodeType.StructuredDocumentTag, true);
            foreach (var tag in tags)
            {
                var sdt = tag as StructuredDocumentTag;
                if (sdt != null && sdt.Tag.Equals("NameTag"))
                {
                    sdt.RemoveAllChildren();
                    var p = new Paragraph(document);
                    var r = new Run(document, name.ToString());
                    if (sdt.Level == MarkupLevel.Inline)
                        sdt.AppendChild«;
            else
                    {
                        p.AppendChild«;
                        sdt.AppendChildº;
                    }
                }
            }

            document.Save(OutputDocxFile, SaveFormat.Docx);
            document.Save(OutputDocFile, SaveFormat.Doc);
            document.Save(OutputXpsFile, SaveFormat.Xps);
        }
    }
}

using DocumentGeneration.Tryout.Managers;

namespace DSA.Facit.DocumentGeneration.Tryout.Runner
{
    class Program
    {
        static void Main(string[] args)
        {
            var manager = new SdtManager();
            manager.InsertNameAndSave("John Doe");
        }
    }
}

I have attached a stripped down version of the template I use, including the tag I inserted myself.
As far as I can tell, the only difference between the two tags is the attributes Id and PlaceHolderName having different values.

Best regards,
Christian

Hi
Christian,

Thanks for you inquiry. While using the latest version of Aspose.Words i.e. 10.8.0, i managed to reproduce this issue on my side. We have logged this issue in our bug tracking system. You will be notified as soon as it is resolved.

Hi Christian,
Let me clear more. The second SDT is linked to custom XML tag, and value of SDT is taken from this custom XML.

Currently there is no way to bind SDT to CustomXML properties. We will consider adding such feature in one of future versions of Aspose.Words. Your request has been linked to the appropriate “New Feature Request”. We will let you know once it is resolved.

Note:
Simply not supported/nonimplemented feature.Sorry for inconvenience.

Hi Imran,

Thanks for your input, I appreciate it.

Hi Christian,
Thank you very much for your feedback. You are always welcome and please feel free to ask if you have any query in future. We always welcome constructive response from our customers.

Hi Christian,

It is to update you that I cannot reproduce the problem with latest Aspose.Words v11.3.0. It seems the issue was fixed by recent changes. Could you please try it with latest Aspose.Words v11.3.0 and let us know how it goes on your side. I have attached output files for your reference.

Hi Imran,

Thank you for your update. I have found a work-around for the original problem, but I took Aspose.Words v11.3.0 for a spin anyway. I can confirm that the issue seems to have been fixed for plain text SDTs. After playing around a bit, I discovered that docx output is still different from doc and xps when using a date SDT.
For your reference, I have attached template and output files, where you will see that the date is displayed twice in doc and XPS, but only once in the docx file.

Best regards,
Christian

Hi Christian,

Thanks for your inquiry. While using the latest version of Aspose.Words i.e. 11.3.0, I managed to reproduce this issue on my side. I have logged this issue in our bug tracking system. The issue ID is WORDSNET-6391.Your request has also been linked to this issue and you will be notified as soon as it is resolved. Sorry for the inconvenience.

Best Regards,

The issues you have found earlier (filed as WORDSNET-6391) have been fixed in this .NET update and this Java update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.

The issues you have found earlier (filed as WORDSNET-4738) have been fixed in this Aspose.Words for .NET 17.5 update and this Aspose.Words for Java 17.5 update.

This message was posted using Notification2Forum from Downloads module by aspose.notifier.
(4)