Пример #1
0
        /// <summary>
        /// Handle Word's WindowActivate event (a new window has focus).
        /// </summary>
        /// <param name="wddoc">A Document object specifying the document that has focus.</param>
        /// <param name="wdwin">A Window object specifying the window that has focus.</param>
        private void app_WindowActivate(Word.Document wddoc, Word.Window wdwin)
        {
            log.Debug("app_WindowActivate fired");

            int intNewWindowCount = Globals.ThisAddIn.Application.Windows.Count;

            //check if we lost a window, if so, clean up its CustomTaskPane
            if (intNewWindowCount - m_intLastWindowCount == -1)
            {
                //a window was closed - remove any lingering CTP from the collection
                if (m_dictTaskPanes.ContainsKey(m_wdwinLastWindow))
                {
                    Globals.ThisAddIn.CustomTaskPanes.Remove(m_dictTaskPanes[m_wdwinLastWindow]);
                    m_dictTaskPanes.Remove(m_wdwinLastWindow);
                }
            }

            //check for SDI<-->MDI changes
            CheckForMdiSdiSwitch();

            //store new window and count
            m_intLastWindowCount = intNewWindowCount;
            m_wdwinLastWindow    = wdwin;

            // If the user did View > New Window,
            // they get a window without a task pane.
            // So disable the buttons
            // (especially the main button), since
            // it is otherwise in a state which
            // contradicts the assertion in RibbonMapping.
            UpdateButtonState();
        }
Пример #2
0
        public void OpenExistingLeaf(string path)
        {
            var openedWordDocuments = GetAllOpenLeavesPaths();

            // Checks if current file is already open.
            foreach (string name in openedWordDocuments)
            {
                if (name.Equals(path))
                {
                    MessageBox.Show($"This leaf is already open, check your open word documents.", "Leaf Already Opened");
                    return;
                }
            }

            try
            {
                if (_wordInstance == null)
                {
                    _wordInstance = (Application)Marshal.GetActiveObject("Word.Application");
                }

                _wordInstance.Visible = true;
                Document wordDocument = _wordInstance.Documents.Open(path);

                Window wordWindow = GetSpecificWordWindow(wordDocument.FullName);
                IntPtr hwnd       = new IntPtr(wordWindow.Hwnd);
                SetForegroundWindow(hwnd);
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
Пример #3
0
        /// <summary>
        /// Moves the focus to the appropriate header/footer.
        /// </summary>
        /// <param name="SelectionRange">The range containing the target header/footer.</param>
        /// <param name="sectionIdFinal">The section to be selected.</param>
        /// <param name="headerFooterId">The header/footer type to be selected.</param>
        internal static void MoveHeaderFooterFocus(Word.Range SelectionRange, int?sectionIdFinal, Word.WdHeaderFooterIndex?headerFooterId)
        {
            if (sectionIdFinal != null && headerFooterId != null)
            {
                Word.Window CurrentWindow = SelectionRange.Application.ActiveWindow;
                try
                {
                    Word.Section CurrentSection = SelectionRange.Document.Sections[(int)sectionIdFinal];
                    if (!RedactCommon.GetHeaderFooterVisibility(CurrentSection, (Word.WdHeaderFooterIndex)headerFooterId) || CurrentWindow.View.Type != Word.WdViewType.wdPrintView)
                    {
                        //if that header/footer isn't being shown, we need to fall back into normal view
                        CurrentWindow.View.Type = Word.WdViewType.wdNormalView;
                        CurrentSection.Range.Select();
                        CurrentWindow.View.SplitSpecial = RedactCommon.GetSplitTypeForStory(SelectionRange.StoryType);
                    }
                    else
                    {
                        //select the appropriate section
                        SelectionRange.Document.Sections[(int)sectionIdFinal].Range.Select();

                        //jump to the header/footer
                        CurrentWindow.View.SeekView = RedactCommon.GetSeekViewForStory(SelectionRange.StoryType);

                        Thread tTabSwitch = new Thread(StayOnReviewTab);
                        tTabSwitch.Start(Redaction.Properties.Resources.ReviewTab);
                    }
                }
                catch (COMException)
                {
                    System.Diagnostics.Debug.Fail("incorrect header/footer view movement detected");
                }
            }
        }
Пример #4
0
 /// <summary>
 /// Fired when Word Application becomes the active window
 /// </summary>
 /// <param name="Doc"></param>
 /// <param name="Wn"></param>
 void Application_WindowActivate(Word.Document Doc, Word.Window Wn)
 {
     if (m_AlfrescoPane != null)
     {
         m_AlfrescoPane.OnWindowActivate();
     }
 }
 void Application_WindowActivate(Word.Document Doc, Word.Window Wn)
 {
     if (OverlayForm != null && OverlayForm.Visible)
     {
         OverlayForm.Opacity = 100;
     }
 }
Пример #6
0
 void KeepNewWindowActivated(Word.Document Doc, Word.Window Wn)
 {
     if (newDoc == Doc)
     {
         Doc.Activate();
     }
 }
Пример #7
0
        private void Application_WindowActivate(Word.Document Doc, Word.Window Wn)
        {
            //throw new NotImplementedException();
            try
            {
                Office.DocumentProperties prp = this.Application.ActiveDocument.CustomDocumentProperties;

                bool isSenitive = false;

                foreach (Office.DocumentProperty documentProperty in prp)
                {
                    if (documentProperty.Name.Equals("Sensitive"))
                    {
                        InitRabbionControl(documentProperty.Value);
                        isSenitive = true;
                    }
                }

                if (isSenitive == false)
                {
                    InitRabbionControl(string.Empty);
                }
            }
            catch (Exception e)
            {
                //MessageBox.Show(e.ToString());
                throw;
            }
        }
Пример #8
0
        private void eventInterface_WindowActivate(Word.Document Doc, Word.Window Wn)
        {
            // Ensure pause checkbox in ribbon is accurate, start by getting timer
            DocumentTimer documentTimer = documentEditTimes[this.Application.ActiveDocument.Name];

            // Set checkbox
            Globals.Ribbons.TimerRibbon.SetPauseStatus(!documentTimer.IsActive);
        }
Пример #9
0
        internal void DisplaySignaturePane()
        {
            paneMode = PaneMode.SignatureDisplayPane;
            Word.Window window = this.Application.ActiveDocument.ActiveWindow;

            RemoveTaskPaneFromWindow(window);

            // Check for task pane in window
            Tools.CustomTaskPane docPane      = null;
            Tools.CustomTaskPane paneToRemove = null;
            foreach (Tools.CustomTaskPane pane in SAPOLDisplayPanes)
            {
                try
                {
                    if (pane.Window == window)
                    {
                        docPane = pane;
                        break;
                    }
                }
                catch (ArgumentNullException)
                {
                    // pane.Window is null, so document1 has been unloaded.
                    paneToRemove = pane;
                }
            }

            // Remove pane if necessary
            SAPOLDisplayPanes.Remove(paneToRemove);

            // Add task pane to doc
            if (docPane == null)
            {
                Tools.CustomTaskPane pane;
                //09/05/2017
                try
                {
                    this.Application.ActiveDocument.Unprotect("NEOPHYTE");
                }
                catch (Exception)
                {
                    //
                }
                //PopulateDocumentPath();
                PopulateSignatureFileds();
                SignatureDisplayPane userCtrl = new SignatureDisplayPane(documentEditProperties[this.Application.ActiveDocument.Name], logger);
                pane = this.CustomTaskPanes.Add(
                    userCtrl,
                    "Add Signature(s) to Document",
                    window);

                pane.Width = GetWidth();
                userCtrl.AdjustSize(pane.Height);
                SAPOLDisplayPanes.Add(pane);
                pane.Visible = true;
            }
        }
Пример #10
0
 /// <summary>
 /// Fired when the Word Application loses focus
 /// </summary>
 /// <param name="Doc"></param>
 /// <param name="Wn"></param>
 void Application_WindowDeactivate(Word.Document Doc, Word.Window Wn)
 {
     if (m_AlfrescoPane != null)
     {
         if (m_AlfrescoPane.Handle.ToInt32() != GetForegroundWindow())
         {
             m_AlfrescoPane.OnWindowDeactivate();
         }
     }
 }
Пример #11
0
 private static void ApplicationOnWindowActivate(Word.Document doc, Word.Window wn)
 {
     try
     {
         WakaTime.HandleActivity(doc.FullName, false, string.Empty);
     }
     catch (Exception ex)
     {
         WakaTime.Logger.Error("ApplicationOnWindowActivate", ex);
     }
 }
Пример #12
0
        private void RemoveTaskPaneFromWindow(Word.Window Wn)
        {
            // Check for task pane in window
            Tools.CustomTaskPane docPane = GetPaneByWindow(Wn);

            // Remove document task pane
            if (docPane != null)
            {
                this.CustomTaskPanes.Remove(docPane);
                SAPOLDisplayPanes.Remove(docPane);
            }
        }
Пример #13
0
 public CustomTaskPane GetMyPane()
 {
     Word.Window window = Globals.ThisAddIn.Application.ActiveWindow;
     foreach (CustomTaskPane ctp in m_MyPanes)
     {
         if (ctp.Title == "我的工具" && ctp.Window == window)
         {
             return(ctp);
         }
     }
     return(m_MyPanes.Add(new ToolsPanel(), "我的工具", window));
 }
Пример #14
0
        /// <summary>
        /// Reloads the ribbon for the given Office application.
        /// </summary>
        /// <param name="applicationName">The Office application; Word, Excel</param>
        /// <param name="applicationObject">An instance of a office COM object (for testing)</param>
        static bool ReloadRibbon(string applicationName, dynamic applicationObject = null)
        {
            // Prevent Word from stealing the focus.
            LockSetForegroundWindow(1);

            // Get the running instance.
#if GOT_OFFICE
            Word.Application app = Marshal.GetActiveObject("Word.Application") as Word.Application;
#else
            dynamic app = applicationObject ?? Marshal.GetActiveObject(applicationName + ".Application");
#endif
            if (app == null)
            {
                // No instance means nothing to update.
                return(true);
            }

            int windowCount = app.Windows.Count;

            // A word window will update the ribbon when it has been activated, but only if another Word window was
            // active sometime earlier.

            // A single window will need another window to be activated first.
            if (windowCount == 1)
            {
#if GOT_OFFICE
                Word.Window window = app.ActiveWindow;
#else
                dynamic window = app.ActiveWindow;
#endif

                try
                {
                    // Make this window on top of everything, to hide the flicker of the new window.
                    SetWindowPos(window.Hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
                    // Create and close a new window
                    window.NewWindow().Close();
                }
                finally
                {
                    // Stop the window from being over everything.
                    SetWindowPos(window.Hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
                }
            }

            // Send a message to each Word window to make it think it's been activated, and therefor reload the Ribbon.
            for (int i = 0; i < windowCount; i++)
            {
                SendMessage((IntPtr)app.Windows[i + 1].Hwnd, WM_ACTIVATE, 1, IntPtr.Zero);
            }

            return(true);
        }
Пример #15
0
        private void Application_WindowDeactivate(Word.Document Doc, Word.Window Wn)
        {
            //MessageBox.Show("Cerramos intenpestivamente word");

            try
            {
                if (!AnalyzerProcess.HasExited)
                {
                    AnalyzerProcess.Kill();
                }
            }
            catch (InvalidOperationException) { }
        }
Пример #16
0
 private Tools.CustomTaskPane GetPaneByWindow(Word.Window Wn)
 {
     Tools.CustomTaskPane docPane = null;
     foreach (Tools.CustomTaskPane pane in SAPOLDisplayPanes)
     {
         if (pane.Window == Wn)
         {
             docPane = pane;
             break;
         }
     }
     return(docPane);
 }
Пример #17
0
 /// <summary>
 /// Gets the attached Wiki Explorer of a Word Window.
 /// </summary>
 /// <param name="window">The Word window contining the Wiki Explorer.</param>
 /// <returns>The instance of the corresponding Wiki Explorer Task Pane. Null if not found.</returns>
 private Tools.CustomTaskPane GetWikiExplorer(Word.Window window)
 {
     foreach (Tools.CustomTaskPane ctp in CustomTaskPanes)
     {
         if (ctp.Title == XWikiNavigationPane.TASK_PANE_TITLE)
         {
             if (ctp.Window == window)
             {
                 return(ctp);
             }
         }
     }
     return(null);
 }
Пример #18
0
 void Application_WindowActivate(Word.Document Doc, Word.Window Wn)
 {
     RemoveOrphanedTaskPanes();
     try
     {
         DocumentProperties prps;
         prps = (DocumentProperties)Globals.ThisAddIn.Application.ActiveDocument.CustomDocumentProperties;
         CustomTaskPane ctp = Globals.ThisAddIn.CustomTaskPanes.Where(x => x.Control.Name == prps["customTaskPaneName"].Value.ToString()).FirstOrDefault();
         if (ctp != null && Wn.Active == true)
         {
             ctp.Visible = true;
         }
     }
     catch { }
 }
Пример #19
0
 private void ListCaptionsForTaskPaneWindows(String context)
 {
     try
     {
         for (int i = this.CustomTaskPanes.Count; i > 0; i--)
         {
             CustomTaskPane ctp       = this.CustomTaskPanes[i - 1];
             Word.Window    ctpWindow = (Word.Window)ctp.Window;
             System.Diagnostics.Debug.Write(context + "   i " + i + " tcp WindowCaption: " + ctpWindow.Caption + "\n");
         }
     }
     catch (Exception ex)
     {
     }
 }
Пример #20
0
 private void Application_WindowActivate(Word.Document Doc, Word.Window Wn)
 {
     Debug.WriteLine("Windown Active on this: " + Doc.FullName + "  " +
                     Doc.FullName.Equals(AppsSettings.GetInstance().DocumentName));
     if (AppsSettings.GetInstance().isLogin&&
         AppsSettings.GetInstance().Session != null &&
         AppsSettings.GetInstance().DocumentName != null &&
         Doc.FullName.Equals(AppsSettings.GetInstance().DocumentName))
     {
         ActiveControl();
     }
     else
     {
         DeactiveControl();
     }
 }
Пример #21
0
        private static Word.Document FindDocument(Word.Windows windows, COMObjectsHelper comHelper, string title)
        {
            Word.Window matchingWindow = null;

            for (var i = 1; i <= windows.Count; i++)
            {
                var window = comHelper.Register(() => windows[i]);

                if (title.Contains(window.Caption))
                {
                    matchingWindow = window;
                    break;
                }
            }

            return(comHelper.Register(() => matchingWindow?.Document));
        }
Пример #22
0
        public void AcceptChanges()
        {
            Word.Document doc  = Globals.ThisAddIn.Application.ActiveDocument;
            Word.Window   win  = Globals.ThisAddIn.Application.ActiveWindow;
            Word.View     view = win.View;

            view.ShowComments               = false;
            view.ShowInkAnnotations         = false;
            view.ShowInsertionsAndDeletions = false;

            doc.AcceptAllRevisionsShown();

            view.ShowComments               = true;
            view.ShowInkAnnotations         = true;
            view.ShowInsertionsAndDeletions = true;
            //MessageBox.Show("Formatting changes have been accepted.");
        }
Пример #23
0
        private void btn_AcceptFormatting_Click(object sender, RibbonControlEventArgs e)
        {
            Word.Document doc  = Globals.ThisAddIn.Application.ActiveDocument;
            Word.Window   win  = Globals.ThisAddIn.Application.ActiveWindow;
            Word.View     view = win.View;

            view.ShowComments               = false;
            view.ShowInkAnnotations         = false;
            view.ShowInsertionsAndDeletions = false;

            doc.AcceptAllRevisionsShown();

            view.ShowComments               = true;
            view.ShowInkAnnotations         = true;
            view.ShowInsertionsAndDeletions = true;
            MessageBox.Show("Formatting changes have been accepted.");
        }
Пример #24
0
        private void RemoveTaskPaneFromWindow(Word.Window Wn)
        {
            // Check for task pane in window
            Tools.CustomTaskPane docPane = null;
            foreach (Tools.CustomTaskPane pane in timerDisplayPanes)
            {
                if (pane.Window == Wn)
                {
                    docPane = pane;
                    break;
                }
            }

            // Remove document task pane
            if (docPane != null)
            {
                this.CustomTaskPanes.Remove(docPane);
                timerDisplayPanes.Remove(docPane);
            }
        }
Пример #25
0
        void WindowActivateHandler(Word.Document doc, Word.Window window)
        {
            if (!(wordWrappersDict.ContainsKey(doc)))
            {
                ListCaptionsForTaskPaneWindows("before");
                // remove redundant TaskPane if present
                String caption = GetCaptionStringFromDoc(doc);
                RemoveTaskPanesIfTheirWindowHasThisCaption(caption);

                List <String> tags   = tagNameSource.GetNextTags(caption);
                TagBar        tagBar = new TagBar();
                this.primaryTagBarDecorator = new WordTagBarDecorator();
                tagBar.SetTagBarHelper(this.primaryTagBarDecorator);
                DocumentWindowWrapper dww = new DocumentWindowWrapper();
                CustomTaskPane        ctp = dww.Wrap(this, doc, tags, tagBar);

                wordWrappersDict.Add(doc, dww);
                System.Diagnostics.Debug.Write("window caption for new taskPane " + window.Caption + "\n");
                ListCaptionsForTaskPaneWindows("after");
            }
        }
Пример #26
0
        void RemoveTaskPanesIfTheirWindowHasThisCaption(String caption)
        {
            String normalizedCaption = caption.Replace(" [Compatibility Mode]", "");
            List <CustomTaskPane> redundantTaskPanes = new List <CustomTaskPane>();

            for (int i = this.CustomTaskPanes.Count; i > 0; i--)
            {
                CustomTaskPane curTp                        = this.CustomTaskPanes[i - 1];
                Word.Window    curTpWindow                  = (Word.Window)curTp.Window;
                String         curTpWindowCaption           = curTpWindow.Caption;
                String         normalizedcurTpWindowCaption = curTpWindowCaption.Replace(" [Compatibility Mode]", "");
                if (normalizedcurTpWindowCaption.Equals(normalizedCaption))
                {
                    redundantTaskPanes.Add(curTp);
                }
            }
            foreach (CustomTaskPane tp in redundantTaskPanes)
            {
                this.CustomTaskPanes.Remove(tp);
            }
        }
        /// <summary>
        /// Handle Word's WindowActivate event (a new window has focus).
        /// </summary>
        /// <param name="wddoc">A Document object specifying the document that has focus.</param>
        /// <param name="wdwin">A Window object specifying the window that has focus.</param>
        private void app_WindowActivate(Word.Document wddoc, Word.Window wdwin)
        {
            int intNewWindowCount = Globals.ThisAddIn.Application.Windows.Count;

            //check if we lost a window, if so, clean up its CustomTaskPane
            if (intNewWindowCount - m_intLastWindowCount == -1)
            {
                //a window was closed - remove any lingering CTP from the collection
                if (m_dictTaskPanes.ContainsKey(m_wdwinLastWindow))
                {
                    Globals.ThisAddIn.CustomTaskPanes.Remove(m_dictTaskPanes[m_wdwinLastWindow]);
                    m_dictTaskPanes.Remove(m_wdwinLastWindow);
                }
            }

            //check for SDI<-->MDI changes
            CheckForMdiSdiSwitch();

            //store new window and count
            m_intLastWindowCount = intNewWindowCount;
            m_wdwinLastWindow    = wdwin;
        }
Пример #28
0
        private Window GetSpecificWordWindow(string targetName)
        {
            Window window = null;

            try
            {
                if (_wordInstance == null)
                {
                    _wordInstance = (Application)Marshal.GetActiveObject("Word.Application") ?? null;
                }

                // If there are any open windows (documents), get their names.
                if (_wordInstance.Windows.Count > 0)
                {
                    Window wordWindow;

                    for (int i = 0; i < _wordInstance.Windows.Count; i++)
                    {
                        object a = i + 1;
                        wordWindow = _wordInstance.Windows.get_Item(ref a);

                        if (wordWindow.Document.FullName == targetName)
                        {
                            window = wordWindow;
                            break;
                        }
                    }
                }
            }
            catch (COMException ex)
            {
                //throw new COMException(ex.Message);
                _wordInstance = CreateNewWordInstance();
            }
            return(window);
        }
Пример #29
0
        private void AddTaskPaneToWindow(Word.Window Wn)
        {
            // Check for task pane in window
            Tools.CustomTaskPane docPane      = null;
            Tools.CustomTaskPane paneToRemove = null;
            foreach (Tools.CustomTaskPane pane in timerDisplayPanes)
            {
                try
                {
                    if (pane.Window == Wn)
                    {
                        docPane = pane;
                        break;
                    }
                }
                catch (ArgumentNullException)
                {
                    // pane.Window is null, so document1 has been unloaded.
                    paneToRemove = pane;
                }
            }

            // Remove pane if necessary
            timerDisplayPanes.Remove(paneToRemove);

            // Add task pane to doc
            if (docPane == null)
            {
                Tools.CustomTaskPane pane = this.CustomTaskPanes.Add(
                    new TimerDisplayPane(documentEditTimes),
                    "Document Edit Timer",
                    Wn);
                timerDisplayPanes.Add(pane);
                pane.VisibleChanged += new EventHandler(timerDisplayPane_VisibleChanged);
            }
        }
Пример #30
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            var t = e.Argument as Tuple <string, string>;

            if (String.IsNullOrWhiteSpace(textBox1.Text))//вставить проверку, что указаны годы
            {
                MessageBox.Show("Не указан год рождения!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            string select = @"SELECT Student.name, [Group].groupName, city.city, Student.street, Student.house, Student.flat, 
                                     Student.phone, Student.birth, sex.sex
                              FROM Student INNER JOIN
                              [Group] ON Student.idGroup = [Group].id INNER JOIN
                              city ON Student.id_city = city.id INNER JOIN
                              sex ON Student.id_sex = sex.id
                              WHERE (Student.birth LIKE '%" + t.Item1 + @"%') AND 
                                    (sex.sex = 'муж.') AND 
                                    (prikazNumKval = '') AND (prikazNumOut = '') 
                              ORDER BY name";

            DataSet ds1 = new DataSet();

            try
            {
                ds1 = Util.FillTable("Student", select);
            }
            catch (SqlException ex)
            {
                MessageBox.Show(ex.ToString());
            }

            if (ds1.Tables[0].Rows.Count == 0)
            {
                MessageBox.Show("С указанными данными никого нет!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }

            Word.Application wdApp  = new Word.Application();
            Word.Document    wdDoc  = new Word.Document();
            Object           wdMiss = System.Reflection.Missing.Value;

            wdDoc = wdApp.Documents.Add(ref wdMiss, ref wdMiss, ref wdMiss, ref wdMiss);
            //wdApp.Visible = true; //сначала формируется документ, показывать потом
            wdDoc.PageSetup.LeftMargin   = 40;
            wdDoc.PageSetup.RightMargin  = 25;
            wdDoc.PageSetup.TopMargin    = 20;
            wdDoc.PageSetup.BottomMargin = 20;
            Word.Table tb;
            Word.Range _range;

            int columnsCount = 5;

            tb = wdDoc.Tables.Add(wdApp.Selection.Range, ds1.Tables[0].Rows.Count + 3, columnsCount);
            tb.Columns[1].Width = 40;
            tb.Rows[1].Height   = 40;
            tb.Columns[2].Width = 210;
            tb.Rows[2].Height   = 40;
            tb.Columns[3].Width = 60;
            tb.Rows[3].Height   = 40;
            tb.Columns[4].Width = 140;
            tb.Columns[5].Width = 90;

            Word.Row  row       = tb.Rows[1];
            Word.Cell firstCell = row.Cells[1];
            foreach (Word.Cell currCell in row.Cells)
            {
                if (currCell.ColumnIndex != firstCell.ColumnIndex)
                {
                    firstCell.Merge(currCell);
                }
            }
            row       = tb.Rows[2];
            firstCell = row.Cells[1];
            foreach (Word.Cell currCell in row.Cells)
            {
                if (currCell.ColumnIndex != firstCell.ColumnIndex)
                {
                    firstCell.Merge(currCell);
                }
            }

            tb.Select();
            wdApp.Selection.ParagraphFormat.Alignment  = Word.WdParagraphAlignment.wdAlignParagraphCenter;
            wdApp.Selection.Range.Font.Name            = "Times New Roman";
            wdApp.Selection.Range.Font.Size            = 10;
            wdApp.Selection.Cells.VerticalAlignment    = Word.WdCellVerticalAlignment.wdCellAlignVerticalCenter;
            wdApp.Selection.ParagraphFormat.SpaceAfter = 0;

            tb.Cell(1, 1).Select();
            wdApp.Selection.Range.Font.Size = 14;
            wdApp.Selection.Font.Bold       = 1;
            tb.Cell(1, 1).Range.Text        = "Список";
            tb.Rows[2].Select();
            wdApp.Selection.Range.Font.Size = 12;
            wdApp.Selection.Font.Bold       = 1;
            tb.Cell(2, 1).Range.Text        = "юношей " + t.Item1 + " года рождения, подлежащих первоначальной постановке на воинский учет, обучающихся в  , по состоянию на " + t.Item2 + " года";

            tb.Rows[3].Select();
            wdApp.Selection.Font.Bold = 1;
            tb.Cell(3, 1).Range.Text  = "№ п/п";
            tb.Cell(3, 2).Range.Text  = "Фамилия, имя, отчество";
            tb.Cell(3, 3).Range.Text  = "№ курса, группа";
            tb.Cell(3, 4).Range.Text  = "Домашний адрес, телефон";
            tb.Cell(3, 5).Range.Text  = "Примечание";


            int rowCount  = 3;
            int rowNumber = 0;

            foreach (DataRow str in ds1.Tables[0].Rows)
            {
                rowCount++;
                rowNumber++;
                tb.Cell(rowCount, 1).Range.Text = rowNumber.ToString() + ".";
                tb.Cell(rowCount, 2).Range.Text = str.ItemArray[0].ToString();
                tb.Cell(rowCount, 3).Range.Text = Util.CalcKurs(str.ItemArray[1].ToString()) + " курс, гр. " + str.ItemArray[1].ToString(); //номер курса считать
                tb.Cell(rowCount, 4).Range.Text = "г." + str.ItemArray[2].ToString() + ", ул." + str.ItemArray[3].ToString() + ", д." +
                                                  str.ItemArray[4].ToString() + ", кв." + str.ItemArray[5].ToString() + ", т." +
                                                  str.ItemArray[6].ToString();
            }

            _range = wdDoc.Range(tb.Cell(4, 2).Range.Start, tb.Cell(rowCount, 5).Range.End);
            _range.Select();
            wdApp.Selection.ParagraphFormat.Alignment = Word.WdParagraphAlignment.wdAlignParagraphLeft;
            _range = wdDoc.Range(tb.Cell(3, 1).Range.Start, tb.Cell(rowCount, columnsCount).Range.End);
            _range.Select();

            /* вызов макроса для отображения границ таблицы
             * Sub Сетка()
             * 'Сетка макрос
             * With Selection.Borders(wdBorderTop)
             * .LineStyle = Options.DefaultBorderLineStyle
             * .LineWidth = Options.DefaultBorderLineWidth
             * .Color = Options.DefaultBorderColor
             * End With
             * With Selection.Borders(wdBorderLeft)
             * .LineStyle = Options.DefaultBorderLineStyle
             * .LineWidth = Options.DefaultBorderLineWidth
             * .Color = Options.DefaultBorderColor
             * End With
             * With Selection.Borders(wdBorderBottom)
             * .LineStyle = Options.DefaultBorderLineStyle
             * .LineWidth = Options.DefaultBorderLineWidth
             * .Color = Options.DefaultBorderColor
             * End With
             * With Selection.Borders(wdBorderRight)
             * .LineStyle = Options.DefaultBorderLineStyle
             * .LineWidth = Options.DefaultBorderLineWidth
             * .Color = Options.DefaultBorderColor
             * End With
             * With Selection.Borders(wdBorderHorizontal)
             * .LineStyle = Options.DefaultBorderLineStyle
             * .LineWidth = Options.DefaultBorderLineWidth
             * .Color = Options.DefaultBorderColor
             * End With
             * With Selection.Borders(wdBorderVertical)
             * .LineStyle = Options.DefaultBorderLineStyle
             * .LineWidth = Options.DefaultBorderLineWidth
             * .Color = Options.DefaultBorderColor
             * End With
             * End Sub
             */
            try
            {
                wdApp.Run("Сетка");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message + " Сетка", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }

            //нумерация страниц
            Word.Window activeWindow = wdDoc.Application.ActiveWindow;
            object      currentPage  = Word.WdFieldType.wdFieldPage;
            object      totalPages   = Word.WdFieldType.wdFieldNumPages;

            //переход к редактированию футера
            activeWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekCurrentPageFooter;
            activeWindow.ActivePane.Selection.Paragraphs.Alignment = Word.WdParagraphAlignment.wdAlignParagraphRight;
            //напечатает номер страницы в формате X стр. из Y
            activeWindow.Selection.Fields.Add(activeWindow.Selection.Range, ref currentPage, ref wdMiss, ref wdMiss);
            activeWindow.Selection.TypeText(" стр. из ");
            activeWindow.Selection.Fields.Add(activeWindow.Selection.Range, ref totalPages, ref wdMiss, ref wdMiss);
            //выход из футера
            activeWindow.ActivePane.View.SeekView = Word.WdSeekView.wdSeekMainDocument;

            wdApp.Visible = true; //показать документ пользователю
        }
        /// <summary>
        /// Handle Word's WindowActivate event (a new window has focus).
        /// </summary>
        /// <param name="wddoc">A Document object specifying the document that has focus.</param>
        /// <param name="wdwin">A Window object specifying the window that has focus.</param>
        private void app_WindowActivate(Word.Document wddoc, Word.Window wdwin)
        {
            log.Debug("app_WindowActivate fired");

            int intNewWindowCount = Globals.ThisAddIn.Application.Windows.Count;

            //check if we lost a window, if so, clean up its CustomTaskPane
            if (intNewWindowCount - m_intLastWindowCount == -1)
            {
                //a window was closed - remove any lingering CTP from the collection
                if (m_dictTaskPanes.ContainsKey(m_wdwinLastWindow))
                {
                    Globals.ThisAddIn.CustomTaskPanes.Remove(m_dictTaskPanes[m_wdwinLastWindow]);
                    m_dictTaskPanes.Remove(m_wdwinLastWindow);
                }
            }

            //check for SDI<-->MDI changes
            CheckForMdiSdiSwitch();

            //store new window and count
            m_intLastWindowCount = intNewWindowCount;
            m_wdwinLastWindow = wdwin;

            // If the user did View > New Window,
            // they get a window without a task pane.
            // So disable the buttons
            // (especially the main button), since
            // it is otherwise in a state which
            // contradicts the assertion in RibbonMapping.
            UpdateButtonState();
        }