Пример #1
0
        //</Snippet89>


        //---------------------------------------------------------------------

        private void PageSetupDialogHidden()
        {
            Word.Dialog dialog = Application.Dialogs[Word.WdWordDialog.wdDialogFilePageSetup];

            InvokeHelper(dialog, "PageWidth", "3.3\"");
            InvokeHelper(dialog, "PageHeight", "6\"");
            InvokeHelper(dialog, "TopMargin", "0.71\"");
            InvokeHelper(dialog, "BottomMargin", "0.81\"");
            InvokeHelper(dialog, "LeftMargin", "0.66\"");
            InvokeHelper(dialog, "RightMargin", "0.66\"");
            InvokeHelper(dialog, "HeaderDistance", "0.28\"");
            InvokeHelper(dialog, "Orientation", "0");
            InvokeHelper(dialog, "DifferentFirstPage", "0");
            InvokeHelper(dialog, "FirstPage", "0");
            InvokeHelper(dialog, "OtherPages", "0");

            // Apply these settings only to the current selection with this line of code:
            InvokeHelper(dialog, "ApplyPropsTo", "3");

            // Apply the settings.
            dialog.Execute();
        }
Пример #2
0
        /// <summary>
        /// 批量打印
        /// </summary>
        public void printFiles()
        {
            var wordFiles = new List <object>();
            var docs      = new List <Word._Document>();

            foreach (string s in listWord)
            {
                if (s != "")
                {
                    wordFiles.Add(s);
                }
                //wordFiles.Add(@"E:\testPrint2.doc");
                //wordFiles.Add(@"E:\testPrint3.doc");
            }
            object oMissing = System.Reflection.Missing.Value;

            Word._Application app = new Word.Application();
            try
            {
                //Document doc = app.Documents.Add(ref wordFile, ref oMissing, ref oMissing, ref oMissing);
                Word.Dialog dialog = null;
                foreach (var wordFile in wordFiles)
                {
                    object         file = wordFile;
                    Word._Document doc  = app.Documents.Open(ref file, 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);
                    docs.Add(doc);
                    //doc.Activate();
                    if (dialog == null)
                    {
                        dialog = app.Dialogs[Word.WdWordDialog.wdDialogFilePrint];
                        //第一次弹出打印设置窗体单击确定默认就会打印了。
                        //所以这里就判断flag为0,就单击的是取消,就退出;否则就默认打印了
                        int flag = dialog.Show(ref oMissing);
                        if (flag == 0)
                        {
                            break;
                        }
                        //if ( flag == 1)
                        //{
                        //    dialog.Execute();
                        //    doc.PrintOut(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,
                        //                 ref oMissing, ref oMissing);
                        //}
                    }
                    else
                    {
                        dialog.Execute();
                        //doc.PrintOut(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,
                        //             ref oMissing, ref oMissing);
                    }
                    System.Threading.Thread.Sleep(1000 * listWord.Count);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            finally
            {
                object saveChange = Microsoft.Office.Interop.Word.WdSaveOptions.wdDoNotSaveChanges;
                foreach (var doc in docs)
                {
                    if (doc != null)
                    {
                        doc.Close(ref saveChange, ref oMissing, ref oMissing);
                    }
                }
                app.Quit(ref oMissing, ref oMissing, ref oMissing);
            }
        }