'index' issue

Jul 16, 2009 at 6:42 PM
Edited Jul 17, 2009 at 6:35 PM

Hello, I am having trouble with the 'index' parameter with regard to paragraphs and tables.

I am attempting to locate a paragraph which contains a certain string and then insert paragraphs or tables before or after it.

It appears that the index returned by Paragraph.startIndex is not the same index used by Document.InsertTable.

When I get a paragraph's startIndex and use that index as a parameter to Document.InsertTable, I get my table inserted at the incorrect location.

It appears that Document.InsertParagraph works as expected and the "NEW PARAGRAPH" gets inserted at the correct place.

Sample code below:

int index = 0;
foreach (Paragraph p in document.Paragraphs)
{
    if (p.Text.Contains("SOMESTRING"))
    {
        index = p.startIndex;
        break;
    }
}

document.InsertParagraph(index,"NEW PARAGRAPH", false);

 document.InsertTable(index, myTable);

 

Is it possible that the Document.InserTable index and the Paragraph.StartIndex would not be the same number?

Thanks,

-Brian

 

 

Coordinator
Jul 28, 2009 at 11:49 PM

Hi Brian,

thank you for taking the time to submit this bug. I believe that I have fixed this issue with the newest version of DocX v1.0.0.6. I plan on uploading this version as soon as I have finished both testing and updating the documentation.chm.

If you would like, I can send you an early (pre-released) copy of DocX v1.0.0.6? I only require your email address so that I can send it as an attachment.

kind regards and happy coding,
Cathal

Feb 7, 2014 at 2:19 PM
Hello,
I am using the latest released version of the DocX v1.0.0.13 and I am having problems with the InsertParagraph ( index As Integer,text As String,trackChanges As Boolean) method. I am getting the error message that I have pasted at the end of this email.

Does anyone know if this original issue was resolved?

Thank you.


Specified argument was out of the range of valid values.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
__
Exception Details: System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.

Source Error:

ArgumentOutOfRangeException: Specified argument was out of the range of valid values.]
Novacode.HelperFunctions.GetFirstParagraphEffectedByInsert(DocX document, Int32 index) +381
Novacode.Container.InsertParagraph(Int32 index, String text, Boolean trackChanges, Formatting formatting) +198
Novacode.DocX.InsertParagraph(Int32 index, String text, Boolean trackChanges, Formatting formatting) +59
Novacode.Container.InsertParagraph(Int32 index, String text, Boolean trackChanges) +55
Novacode.DocX.InsertParagraph(Int32 index, String text, Boolean trackChanges) +56.......
Developer
Feb 7, 2014 at 2:22 PM
Try using newest source code instead of the binary version. And let us know.

With regards,
Przemek
Feb 7, 2014 at 5:39 PM
OK, I see now why the exception is being thrown. I can only use the InsertParagraph(index, text) in the brand new document where I myself inserted all prior paragraphs - this is the only way that you populate document.paragraphLookup dictionary. I, however, tried to insert a new paragraph into the existing template document - thus no entries in the dictionary.