private void btn_ExecuteSearch_Click(object sender, RibbonControlEventArgs e)
        {
            //get the text from the settings
            Searches searches = Properties.Settings.Default.searches;

            //Find out which option is selected
            RibbonDropDownItem item = this.dd_Searches.SelectedItem;

            if (searches.Dict.ContainsKey(item.Label))
            {
                Search search = searches.Dict[item.Label];
                if (search.Replace == null)
                {
                    Globals.ThisAddIn.Application.Selection.Find.Execute(FindText: search.Find, MatchCase: search.CaseSensitive, MatchWildcards: search.Wildcards, Wrap: Word.WdFindWrap.wdFindAsk);
                }
                else
                {
                    Word.WdReplace mode = Word.WdReplace.wdReplaceOne;
                    if (search.ReplaceAll)
                    {
                        mode = Word.WdReplace.wdReplaceAll;
                    }
                    Globals.ThisAddIn.Application.Selection.Find.Execute(FindText: search.Find, MatchCase: search.CaseSensitive, MatchWildcards: search.Wildcards, Wrap: Word.WdFindWrap.wdFindAsk, ReplaceWith: search.Replace, Replace: mode);
                }
            }
            else
            {
                MessageBox.Show("An error occurred when finding your saved search. Please let Aaron know!");
                return;
            }
        }
Exemple #2
0
        public void ConvertToTable(string strText, int row_cnt = -1, int col_cnt = -1, bool bSetBorders = true, string bookmark = "")
        {
            string strReturn  = "" + (char)10;
            bool   bUseReturn = false;

            if (strText.IndexOf(strReturn) >= 0)
            {
                bUseReturn = true;
            }

            strText = strText.Replace(strReturn, "#enter#");

            if (bookmark == "")
            {
                if (m_pDoc == null)
                {
                    m_pDoc = m_pApp.ActiveDocument;
                }
                if (m_pDoc == null)
                {
                    return;
                }

                m_pDoc.Select();
                m_pSelection = m_pApp.Selection;
                if (m_pSelection == null)
                {
                    return;
                }

                m_pSelection.Collapse(0);

                object varInfo = m_pSelection.get_Information(MSWord.WdInformation.wdWithInTable);
                if (Convert.ToBoolean(varInfo) == true)
                {
                    m_pDoc.Select();
                    m_pSelection = m_pApp.Selection;
                    if (m_pSelection == null)
                    {
                        return;
                    }
                    m_pSelection.Collapse(0);
                }
            }
            else
            {
                m_pSelection.GoTo(-1, Type.Missing, Type.Missing, bookmark);
            };

            m_pSelection.Font.Bold = 0;
            m_pSelection.Text      = strText;

            m_pSelection.Paragraphs.SpaceAfter      = 0;
            m_pSelection.Paragraphs.SpaceBefore     = 0;
            m_pSelection.Paragraphs.LineSpacingRule = MSWord.WdLineSpacing.wdLineSpaceSingle;


            if (row_cnt < 0 && col_cnt < 0)
            {
                m_pTable = m_pSelection.ConvertToTable(1, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, 0, 0);
            }
            else
            {
                m_pTable = m_pSelection.ConvertToTable(1, row_cnt, col_cnt, 0, 0,
                                                       Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                       Type.Missing, 0, 0);
            }

            // выравниваем талицу (не содержимое!!!)
            if (m_pTable == null)
            {
                return;
            }

            MSWord.Rows pRows = m_pSelection.Rows;
            pRows.AllowBreakAcrossPages = 0;

            m_pSelection.Collapse(0);

            MSWord.Borders pBorders = m_pTable.Borders;
            if (pBorders == null)
            {
                return;
            }
            if (bSetBorders)
            {
                pBorders.Enable = 1;
            }
            else
            {
                pBorders.Enable = 0;
            }

            if (bUseReturn)
            {
                m_pTable.Select();
                MSWord.Selection sel = m_pApp.Selection;

                MSWord.Find find = sel.Find;
                find.ClearFormatting();
                MSWord.Replacement replace = find.Replacement;
                replace.ClearFormatting();
                find.Text              = "#enter#";
                replace.Text           = "^p";
                find.MatchCase         = false;
                find.MatchWholeWord    = false;
                find.MatchWildcards    = false;
                find.MatchSoundsLike   = false;
                find.MatchAllWordForms = false;
                find.Wrap              = MSWord.WdFindWrap.wdFindContinue;
                MSWord.WdReplace repl = MSWord.WdReplace.wdReplaceAll;
                find.Execute(find.Text, find.MatchCase, find.MatchWholeWord, find.MatchWildcards,
                             find.MatchSoundsLike, find.MatchAllWordForms, Type.Missing, find.Wrap, Type.Missing, replace.Text, repl);
            }
        }