Esempio n. 1
0
        public bool OpenDocument(short _docType, string _fileName, string _documentReference, bool _activateWord)
        {
            try
            {
                if (LoadDocument(_docType, _fileName, _documentReference))
                {
                    if (_activateWord)
                    {
                        MicrosoftWord.Application appWord = new MicrosoftWord.Application();

                        object template    = _fileName;
                        object newTemplate = false;
                        object docType     = MicrosoftWord.WdNewDocumentType.wdNewBlankDocument;
                        object visible     = true;

                        MicrosoftWord.Document doc = appWord.Documents.Add(ref template, ref newTemplate, ref docType, ref visible);
                        doc.PrintPreview();
                        appWord.Visible = true;
                        appWord.Activate();
                    }

                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (Exception err)
            {
                MessageBox.Show(err.Message, $"{err.Source}.{err.TargetSite.Name}", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Esempio n. 2
0
        private OpenFileDialog G_OpenFileDialog; //定義瀏覽資料夾欄位

        private void btn_Open_Click(object sender, EventArgs e)
        {
            btn_Open.Enabled = false;                           //將打開按鈕設定為不可用
            ThreadPool.QueueUserWorkItem(                       //開始線程池
                (pp) =>                                         //使用lambda表達式
            {
                G_wa =                                          //建立應用程式對像
                       new Microsoft.Office.Interop.Word.Application();
                G_wa.Visible             = true;                //將文件檔設定為可見
                object P_FileName        = G_OpenFileDialog.FileName;
                Word.Document P_Document = G_wa.Documents.Open( //打開Word文件檔
                    ref P_FileName, ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                    ref G_missing, ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                    ref G_missing, ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                    ref G_missing);
                P_Document.PrintPreview();    //開始預覽
            });
        }
Esempio n. 3
0
        private OpenFileDialog G_OpenFileDialog; //定义浏览文件夹字段

        private void btn_Open_Click(object sender, EventArgs e)
        {
            btn_Open.Enabled = false;                           //将打开按钮设置为不可用
            ThreadPool.QueueUserWorkItem(                       //开始线程池
                (pp) =>                                         //使用lambda表达式
            {
                G_wa =                                          //创建应用程序对象
                       new Microsoft.Office.Interop.Word.Application();
                G_wa.Visible             = true;                //将文档设置为可见
                object P_FileName        = G_OpenFileDialog.FileName;
                Word.Document P_Document = G_wa.Documents.Open( //打开Word文档
                    ref P_FileName, ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                    ref G_missing, ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                    ref G_missing, ref G_missing, ref G_missing, ref G_missing, ref G_missing,
                    ref G_missing);
                P_Document.PrintPreview();    //开始预览
            });
        }
Esempio n. 4
0
        /// <summary>
        /// 打印预览
        /// </summary>
        /// <param name="printName"></param>
        /// <returns></returns>
        public bool printView(string printName)
        {
            //打印
            Microsoft.Office.Interop.Word.Application app = null;
            Microsoft.Office.Interop.Word.Document    doc = null;
            object missing      = System.Reflection.Missing.Value;
            object templateFile = printFilePath;

            try
            {
                app = new Microsoft.Office.Interop.Word.ApplicationClass();
                doc = app.Documents.Add(ref templateFile, ref missing, ref missing, ref missing);

                //保存默认打印机
                string defaultPrint = app.ActivePrinter;
                app.ActivePrinter = printName;
                //预览
                app.Visible = true;
                doc.PrintPreview();
            }
            catch (Exception exp)
            {
                object saveChange = Microsoft.Office.Interop.Word.WdSaveOptions.wdPromptToSaveChanges;// .wdDoNotSaveChanges;
                if (doc != null)
                {
                    doc.Close(ref saveChange, ref missing, ref missing);
                }
                if (app != null)
                {
                    app.Quit(ref missing, ref missing, ref missing);
                }

                foreach (System.Diagnostics.Process p in System.Diagnostics.Process.GetProcessesByName("WINWORD"))
                {
                    p.Kill();
                }

                return(false);
            }
            return(true);
        }
Esempio n. 5
0
        public void StartDocumentShow()
        {
            object missing = System.Reflection.Missing.Value;
            object readOnly = true;

            axFramerControl1.EventsEnabled = true;
            System.Windows.Forms.Application.DoEvents();

            axFramerControl1.Open(_fileName, readOnly, missing, missing, missing);

            //axFramerControl1.Open(_fileName, true, Type.Missing, Type.Missing, Type.Missing);
            //_presentation = axFramerControl1.ActiveDocument as Presentation;

            //_document = axFramerControl1.ActiveDocument as Microsoft.Office.Interop.Word.DocumentClass;
            _document = (Microsoft.Office.Interop.Word.Document)axFramerControl1.ActiveDocument;

            //TO DO: Удалить
            //axFramerControl1.EventsEnabled = true;
            //axFramerControl1.Select();
            if (_document != null)
            {
                //SlideShowSettings slideShowSettings = _presentation.SlideShowSettings;
                //slideShowSettings.ShowType = PpSlideShowType.ppShowTypeWindow;
                //slideShowSettings.ShowScrollbar = MsoTriState.msoFalse;
                //slideShowSettings.LoopUntilStopped = MsoTriState.msoTrue;

                //TO DO: Удалить
                // без задержки не всегда успевают правильно определится тулбары
                //Thread.Sleep(500);
                //System.Windows.Forms.Application.DoEvents();
                //_helper = new DsoFramerHelper(axFramerControl1);
                //_helper.Init();

                _document.PrintPreview();

                _document.Application.DisplayScrollBars = true;
                _document.Application.ActiveWindow.DisplayRulers = false;

                _document.CommandBars["Print Preview"].Enabled = false;
                _document.CommandBars["Print Preview"].Visible = false;

                if (StartPage != 1)
                    GoToPage(StartPage);
                if (StartLine != 1)
                {

                    object objCurrentLine = _document.ActiveWindow.ActivePane.Selection.get_Information(WdInformation.wdFirstCharacterLineNumber);
                    int.TryParse(objCurrentLine.ToString(), out currentLine);
                    line = currentLine + StartLine;

                    object wdGoToLine = WdGoToItem.wdGoToLine;
                    object wdGoToNext = WdGoToDirection.wdGoToNext;
                    object count = line;
                    object name = "";
                    //_document.ActiveWindow.Selection.GoTo(ref wdGoToLine, ref wdGoToNext, ref count, ref name);
                    _document.ActiveWindow.ActivePane.Pages[StartPage].Application.Selection.GoTo(ref wdGoToLine, ref wdGoToNext, ref count, ref name);
                }

                Zoom(StartZoom);
            }
        }