We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Replace in word document

Hi
I have a wordfile that I want to replace a text in. I use the following code:
WordDocumentrebarTemplate=newWordDocument();
rebarTemplate.Open(textBox1.Text,FormatType.Automatic);
 
rebarTemplate.Replace("%1%_P:RebarChecked","newvalue",false,true);
 
Directory.CreateDirectory(@"C:\temp\synctest\");
rebarTemplate.Save(@"C:\temp\synctest\syncreplace.docx");
 
rebarTemplate.Close();
I get the argumentoutofrangeexception 'startIndex cannot be larger than length of string.' when the replace line is called.
I get this exception from the original file.
However, if I open the word file in word 2013 and alter one or more of the texts and save it, the code runs ok.
The original word file open correctly in word 2013.
Any idea what may be wrong?
See the attached file...

Regards
Øyvind Knappskog Olsen
Norconsult Informasjonssystemer AS

Attachment: RebarTemplateNOR_bc140b34.zip

1 Reply

SV Sarathkumar V Syncfusion Team December 8, 2015 06:55 AM UTC

Hi Øyvind Knappskog Olsen,

Sorry for the delay being caused.

We could see that you have created incident for the below query under your account. Please follow up with that incident for further updates.

Please let us know if you have any queries.

Regards,
Sarath


Loader.
Up arrow icon