1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102:
| using System; using Microsoft.Office.Interop.Word;
namespace Office2007Steuerung { class MainProgramm { public static void Main(String[] args) { new MainProgramm(); }
public MainProgramm() { Application wordApp = null; wordApp = new Application(); wordApp.ScreenUpdating = true; wordApp.Visible = true;
Object oTemplate = ""; Object oNewTemplate = false; Object oDocType = WdNewDocumentType.wdNewBlankDocument; Object oVisible = true; try { wordApp.Documents.Add(ref oTemplate, ref oNewTemplate, ref oDocType, ref oVisible); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.StackTrace); } wordApp.ScreenRefresh(); wordApp.Selection.TypeText("Ich du und der Esel wir sind 3"); wordApp.Selection.TypeParagraph(); wordApp.Selection.TypeText("EselEselEsel"); wordApp.Selection.TypeParagraph(); wordApp.Selection.TypeText("Ich du und der esel wir sind 3"); wordApp.Selection.TypeParagraph(); wordApp.Selection.TypeText("Ich du und der eSeL wir sind 3"); wordApp.Selection.TypeParagraph(); wordApp.Selection.TypeText("Esel der du fliegst im Himmel so frei wie ein eseL"); wordApp.Selection.TypeParagraph();
Object oFindText = "Esel"; Object oReplaceText = "Vogel"; Object oForward = true; Object oWrap = WdFindWrap.wdFindContinue; Object oFormat = false; Object oMatchCase = false; Object oMatchWholeWord = false; Object oMatchWildcards = false; Object oMatchSoundsLike = false; Object oMatchAllWordForms = false; Object oReplaceAll = WdReplace.wdReplaceAll; Object oFalse = false;
wordApp.Selection.Find.Execute(ref oFindText, ref oMatchCase, ref oMatchWholeWord, ref oMatchWildcards, ref oMatchSoundsLike, ref oMatchAllWordForms, ref oForward, ref oWrap, ref oFormat, ref oReplaceText, ref oReplaceAll, ref oFalse, ref oFalse, ref oFalse, ref oFalse);
wordApp.ScreenRefresh();
String pdfFileName = "C:\\Dokumente und Einstellungen\\user\\Eigene Dateien\\dummy-test.pdf"; WdExportFormat exportFormat = WdExportFormat.wdExportFormatPDF; Boolean openAfterExport = true; WdExportOptimizeFor optimizeFor = WdExportOptimizeFor.wdExportOptimizeForPrint; WdExportRange docRange = WdExportRange.wdExportAllDocument; int from = 0; int to = 0; WdExportItem exportItem = WdExportItem.wdExportDocumentContent; Boolean includeDocProp = true; Boolean keepIRM = true; WdExportCreateBookmarks createBookmarks = WdExportCreateBookmarks.wdExportCreateWordBookmarks; bool docStructTags = true; Boolean bitmapMissingFonts = true; Boolean isPDFA = false; Object fixedFormatExtClassPtr = null;
wordApp.ActiveDocument.ExportAsFixedFormat(pdfFileName, exportFormat, openAfterExport, optimizeFor, docRange, from, to, exportItem, includeDocProp, keepIRM, createBookmarks, docStructTags, bitmapMissingFonts, isPDFA, ref fixedFormatExtClassPtr);
Object saveChanges = WdSaveOptions.wdDoNotSaveChanges; Object oriFormat = WdOriginalFormat.wdOriginalDocumentFormat; wordApp.Quit(ref saveChanges, ref oriFormat, ref oFalse); } } } |