I'm attempting to replace the use of MS Word in our application and I'm having trouble with one of the functions we need. We use DOCX templates and fill them with data from our application. Using Office Interop, I can set the header, footer or main document as the "SeekView" before a find replace like this -
WordApp.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageHeader
WordApp.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter
WordApp.ActiveWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument
Is there any function for the RichTextEditor that can allow me to perform a find/replace on the header and footer? I can only get the find/replace code to work on the main body.
6 Answers, 1 is accepted
The implementation of RadRichTextBox is a bit different than the one provided by MS Office Interop and the API of the control doesn't include something similar to the SeekView.
Since the headers and footers in RadRichTextBox are implemented as instances of the RadDocument class and the FindReplace functionality works with a RadDocument instance, this is the default behavior of the functionality. However, you can customize it by handling the command and executing it over the headers and footers as well.
The headers and footers of a document can be obtained through the sections. Please, find below a sample code showing how you can obtain a header of a section. The approach for the footer is the same.
Additionally, we have logged a task to implement a similar functionality and you can vote to increase its priority as well as track its status using the related public item.
If you need further assistance in implementing this, please let us know.
So here's what I've got and it doesn't work. The find replace doesn't find any of the search strings I specify even though I can see they are there. fine replace works great on the main body. I suppose I'm doing something wrong but not sure what to try next.
The Insert() method of RadRichTextEditor adds the content at the current caret position. I would suggest you using the RadDocumentEditor class so that you can ensure you are inserting the content at the desired document part. I modified the code so I can build it and here is how it looks like after changing the way the content is being inserted:
Does that work for you?
This is working for me. Thank you!
I am running this 3 times, once each for Default, Even and First header.
Thank you for writing back.
Indeed, you will need to run it for each additional RadDocument instance used. Something that worth mentioning here is that would be good to check whether the header/footer document is not null. Such case would be if the current document doesn't have applied header or footer.