Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- foreach (Field mergeField in document.Fields)
- {
- if (mergeField.Type == WdFieldType.wdFieldMergeField)
- {
- string fieldText = mergeField.Code.Text;
- string fieldName = Extensions.GetFieldName(fieldText);
- if (values.ContainsKey(fieldName))
- {
- mergeField.Select();
- application.Selection.TypeText(values[fieldName]);
- }
- }
- }
- subscriptionDocument.Sections[1].Headers[WdHeaderFooterIndex.wdHeaderFooterPrimary].Range.Fields.Count;
- ?activedocument.Sections(1).Headers(wdHeaderFooterFirstPage).Range.Fields.Count
- putField("First_Name", "Fred");
- putField("Last_Name", "Bloggs");
- private void putField(string search, string replace) {
- foreach (Section section in doc.Sections) {
- doReplace(section.Range.Find, search, replace);
- foreach (HeaderFooter h in section.Headers) {
- doReplace(h.Range.Find, search, replace);
- }
- foreach (HeaderFooter f in section.Footers) {
- doReplace(f.Range.Find, search, replace);
- }
- }
- }
- private void doReplace(Find fnd, string search, string replace){
- fnd.ClearFormatting();
- fnd.Replacement.ClearFormatting();
- fnd.Forward = true;
- fnd.Wrap = WdFindWrap.wdFindContinue;
- fnd.Text = "«" + search + "»";
- fnd.Replacement.Text = replace;
- fnd.Execute(Replace: WdReplace.wdReplaceAll);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement