Wednesday 15 September 2010

c# - Programmatically replace formatted text in paragraphs (links, content) -



c# - Programmatically replace formatted text in paragraphs (links, content) -

i trying create word addin. how can programmatically replace text in paragraphs? need replace: \r \t\r in line.

first attempt:

globals.thisaddin.application.activedocument.paragraphs[nr].range.text = globals.thisaddin.application.activedocument .paragraphs[nr].range.text.replace("\r", "\t\r");

its text, if have links or content in paragraphs doesn't work.

second attempt:

globals.thisaddin.application.activedocument.paragraphs[nr].range.find.execute("\r"); globals.thisaddin.application.selection.text = "\t"

this fails 1

third attempt:

globals.thisaddin.application.selection.find .execute("\r", wrap: microsoft.office.interop.word.wdfindwrap.wdfindcontinue); word.find findobject = application.selection.find; // findobject.clearformatting(); findobject.text = "\r"; // findobject.replacement.clearformatting(); findobject.replacement.text = "\t\r" object replaceall = word.wdreplace.wdreplaceall; findobject.execute(ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref replaceall, ref missing, ref missing, ref missing, ref missing);

this fails 1 more, because delete 1 paragraph (put text paragraph[1] , paragraph[2] 1 paragraph)

for future readers:

it possible using openxml. openxml can extracted right addin's code. approach universal, allows manipulate document faster , more precisely.

c# ms-word office-addins

No comments:

Post a Comment