Document.FindAll and DocX.InsertTable out of range exception

Jan 11, 2014 at 12:26 AM
Edited Jan 11, 2014 at 12:29 AM
I am trying to replace some text with a table, but am having some trouble.
The FindAll function returns a single occurrence of the string I am looking for, yet when I attempt to call document.InsertTable(index, tbl), I get an "Specified argument was out of the range of valid values" that traces back to the HelperFunctions.GetFirstParagraphEffectedByInsert(DocX document, Int32 index) function.

Calling just document.InsertTable(tbl) works, but puts the table at the end of the document.

I have tried what was suggested in this (slightly old) thread https://docx.codeplex.com/discussions/63742 with no success.

The document is simply:
Hello,

Here is the data:
{Table_Here}

Goodbye
and the search term is "{Table_Here}"

Any suggestions as to what could be going wrong?
Jan 21, 2014 at 6:58 AM
I am having the same issue.
I need to replace text with Paragraph with multiple formattings.
Any update on this?
Mar 3, 2014 at 7:07 PM
Hi

Same here.

regards
wvdvegt
May 20, 2014 at 8:50 AM
InsertTable used DocX.paragraphLookup dictionary for search apropriate paragraph. But that Dictionary not populate...
I'am (for self) modify DocX.cs, function PostLoad, before
return document;
insert that:
            document.paragraphLookup.Clear();
            foreach (var paragraph in document.Paragraphs)
            {
                if (!document.paragraphLookup.ContainsKey(paragraph.endIndex))
                    document.paragraphLookup.Add(paragraph.endIndex, paragraph);
            }
Marked as answer by MadBoy on 6/3/2014 at 4:14 AM
Developer
Jun 3, 2014 at 11:14 AM
Added this to main source code. Please verify if it works. Thanks monstress