We had a strange occurrence take place when we first tested our paid license. In most cases, everything works, but we have a situation where are using a text value as a tag (as opposed to a bookmark) in order to specify where to update a table in a Word document. We need to continue to do this because of legacy documents that our client uses. Because of this, we are using the IReplacing callback class to intercept the replace, then make changes to the table and replace the tag with an empty string. This was working fine with the temporary license, and again, with the evaluation license when that expired.
When I tested it with the paid license, it stopped working, getting an out of bounds issue as described below. It took me a while to track it down and verify that the same code stops working when I change from the evaluation license to the paid license.
What I do is: get a collection of the tables in the document called allTables:
Dim allTables As Aspose.Words.NodeCollection = builder.Document.GetChildNodes(Aspose.Words.NodeType.Table, True)
In both cases, this returns four tables - 2 earlier in the document, and then two versions of my test table. For legacy reasons, then search text is in the very first cell of the table to be populated. So I locate the table I’m looking for like this:
Dim oldTable As Aspose.Words.Tables.Table = builder.CurrentNode.GetAncestor(Aspose.Words.NodeType.Table)
This finds the correct table. I can look at it in debug and see that the first cell contains the text tag that I’m looking for.
Here’s where it gets interesting. I locate the table index with the following code:
Dim oldTableIndex As Integer = allTables.IndexOf(oldTable)
This code gets a different value depending on whether I’m using the evaluation license or the paid license. The paid license version returns a 2, which would seem right based on the order of the tables in the document. The evaluation license returns a zero. If I look at allTables, though, the index does point to the correct table in both cases, they are just in different places in the collection. The problem comes in when I call:
builder.MoveToCell(oldTableIndex, row, cols, -1) ' row and cols both are zero here.
This returns an error, but only when the paid license is in effect: “System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: tableIndex”
We resolved this problem temporarily by using the following code to get the index:
Dim oldTableIndex As Integer = oldTable.ParentNode.GetChildNodes(Aspose.Words.NodeType.Table, True).IndexOf(oldTable)
This is successful with both license cases, but, depending on how complex the document is, I could see this possibly causing a problem in the future.
I’ll attach the document I’m using. I have changed the code, but if you need more than this, I can set up a version of the old code and attach that.
- Steve
SOP-MF-0640 Shortened - TABLE TEST - Conjugation Processes.docx (29.7 KB)