Document Revisions MoveTo/MoveToCell

Hi

We have a piece of code which performs the following:

  1. Compares 2 word documents
  2. Get the revisions from the comparison document
  3. Open the comparison document using the DocumentBuiler class
  4. Loop through the revisions collection
  5. Adds a html tag before each revisions parent node (using the DocumentBuiler class)
  6. Convert the document to html

This works fine for most documents, however this code fails with document which contains tables.

This is the code we are using

            // move to the correct revision node
            _documentBuilder.MoveToDocumentStart();
	_documentBuilder.MoveTo(_lastRevision.ParentNode);

            if (_documentBuilder.CurrentNode != null)
            {
                // build the html anchor and insert
                var insertHtmlAnchor = ......

                _documentBuilder.InsertHtml(insertHtmlAnchor);
            }

The _documentBuilder.MoveTo(_lastRevision.ParentNode) line fails when the nodetype is of Row

In order to address this I a trying the following

            // move to the correct revision node
            _documentBuilder.MoveToDocumentStart();

            switch (_lastRevision.ParentNode.NodeType)
            {
                case NodeType.Row:
                    var row = (Aspose.Words.Tables.Row)_lastRevision.ParentNode;

                    _documentBuilder.MoveToCell(.....);
                    break;

                default:
                    _documentBuilder.MoveTo(_lastRevision.ParentNode);
                    break;
            }

            if (_documentBuilder.CurrentNode != null)
            {
                // increment/reset the revision index
                _revisionIndex++;

                // build the html anchor and insert
                var insertHtmlAnchor = ...

                _documentBuilder.InsertHtml(insertHtmlAnchor);
            }

I don’t know how to get the properties/values in order to perform the following call

                case NodeType.Row:
                    var row = (Aspose.Words.Tables.Row)_lastRevision.ParentNode;

                    _documentBuilder.MoveToCell(.....);
                    break;

Please advise how I can call MoveToCell, with the correct parameters for the revision, when its of type Row

Thanks

@david.hancock.imagef,

Thanks for your inquiry. To ensure a timely and accurate response, please attach the following resources here for testing:

  • Your input Word documents.
  • Please attach the output HTML file that shows the undesired behavior.
  • Please attach the expected output HTML file that shows the desired behavior.
  • Please create a standalone console application (source code without compilation errors) that helps us to reproduce your problem on our end and attach it here for testing.

As soon as you get these pieces of information ready, we’ll start investigation into your issue and provide you more information. Thanks for your cooperation.

PS: To attach these resources, please zip and upload them.

Aspose.Words.MoveTo.Issue.zip (30.5 KB)

Hi Please the attached ZIP file as request (requires VS 2017 and a NUGET restore)

look at the comments on lines 56 to 64 in the Program.cs hopefully this will describe the issue for you

Basically issue MoveTo is failing when NodeType is Row

@david.hancock.imagef,

Thanks for your inquiry. We suggest you please about Aspose.Words document object model from here:
Aspose.Words Document Object Model

The DocumentBuilder’s cursor cannot be moved to a Row node. However, you can move it to first paragraph of row’s cell using following line of code. Hope this helps you.

documentBuilder.MoveTo(((Row)revision.ParentNode).FirstCell.FirstParagraph);

If you want to use DocumentBuilder.MoveToCell method, please use following code snippet.

Row row = ((Row)revision.ParentNode);
int tableindex = row.FirstCell.FirstParagraph.ParentSection.Body.Tables.IndexOf(row.ParentTable);
int rowindex = row.ParentTable.Rows.IndexOf(row);
documentBuilder.MoveToCell(tableindex, rowindex, 0, 0);

Please read following article.
Moving the Cursor