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

Free Support Forum - aspose.com

Adding Bookmark text of cell level make the bookmark disappear when rendering

Hi,
Adding the bookmark mark text in a cell level document header makes the bookmark disappear when rendering using the following code
> private bool InternalWriteToBookMark(Document AWordDoc, string _bookName, string _bookText)

    {
        LogInfo("DocumentConversion.InternalWriteToBookMark - Start - Bookmark Name: " + _bookName + " Bookmark Text: " + _bookText);
        bool ModifiedBookmark = false;

        ProtectionType oldProtectionType = AWordDoc.ProtectionType;

        if (oldProtectionType != ProtectionType.NoProtection)
        {
            LogInfo("DocumentConversion.InternalWriteToBookMark - Before:  wordDoc.Unprotect()");
            AWordDoc.Unprotect();
            LogInfo("DocumentConversion.InternalWriteToBookMark - After:  wordDoc.Unprotect()");
        }
        try
        {
            LogInfo("DocumentConversion.InternalWriteToBookMark - Before:  AWordDoc.Range.Bookmarks");

            Bookmark bookmark = AWordDoc.Range.Bookmarks[_bookName];

            LogInfo("DocumentConversion.InternalWriteToBookMark - After:  AWordDoc.Range.Bookmarks");

            if (bookmark == null)
            {
                LogInfo("DocumentConversion.InternalWriteToBookMark - Bookmark " + _bookName + " does not exist in document");
            }
            else
            {
                LogInfo("DocumentConversion.InternalWriteToBookMark - Bookmark " + _bookName + " exists in document");

                LogInfo("DocumentConversion.InternalWriteToBookMark - modifying text within bookmark - this will always overwrite");
                bookmark.Text = _bookText;
                LogInfo("DocumentConversion.InternalWristeToBookMark - Found and inserted text within Bookmark: " + _bookName);

                ModifiedBookmark = true;
            }
        }
        finally
        {
            if (oldProtectionType != ProtectionType.NoProtection)
            {
                LogInfo("DocumentConversion.InternalWriteToBookMark - Before wordDoc.Protect(oldProtectionType);");
                AWordDoc.Protect(oldProtectionType, null);
            }
        }

        LogInfo("DocumentConversion.InternalWriteToBookMark - End - Bookmark Name: " + _bookName + " Bookmark Text: " + _bookText);

        return ModifiedBookmark;
    }

Please Add support for ColumnFirst and ColumnLast properties in BookmarkStart as these will be filled out for cell level bookmarks.

Please find the attachment of the word template that is used to reproduce the bug. (filling the Date of Birth field in the header causes the bug)
Thanks,

RobertTestBookMarkTemplate.zip (37.4 KB)

Upon further research, the issue is that the bookmark is a cell level bookmark with the entire cell selected. The issue here is that Aspose BookmarkStart object doesn’t expose the ColumnFirst and ColumnLast properties that are in the Word file. To work-around, we need to parse the Word XML file ourselves to find this info. Aspose.Words should take this into account when modifying the bookmark.text property.

@rsamveda.ramsoft

Unfortunately, Aspose.Words does not support the requested feature at the moment. However, we have logged this feature request as WORDSNET-18694 in our issue tracking system. You will be notified via this forum thread once this feature is available.

We apologize for your inconvenience.

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