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
| using Word = Microsoft.Office.Interop.Word;
private static void PrintWord(string filePath, string PrintName) { try { Object wordFile = filePath; object oMissing = Missing.Value; object oTrue = true; object oFalse = false; object doNotSaveChanges = Word.WdSaveOptions.wdDoNotSaveChanges;
Word.Application appWord = new Word.Application();
appWord.Visible = false;
appWord.DisplayAlerts = Word.WdAlertLevel.wdAlertsNone;
string defaultPrinter = appWord.ActivePrinter;
Word.Document doc = appWord.Documents.Open( ref wordFile, ref oMissing, ref oTrue, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing );
appWord.ActivePrinter = PrintName;
doc.PrintOut( ref oTrue, ref oFalse, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing, ref oMissing );
doc.Close(ref doNotSaveChanges, ref oMissing, ref oMissing);
appWord.ActivePrinter = defaultPrinter;
appWord.Quit(ref oMissing, ref oMissing, ref oMissing); doc = null; appWord = null; } catch (Exception ex) { string line = ex.StackTrace.ToString(); string errorfunction = ex.TargetSite.ToString(); int code = ex.HResult; } }
|