Example #1
0
        private void btn_setlanguage_Click(object sender, EventArgs e)
        {
            PowerPoint.Application  ppApp     = Globals.ThisAddIn.Application;
            PowerPoint.Presentation ActivePPT = Globals.ThisAddIn.Application.ActivePresentation;

            string        lang = cmb_lng.Text;
            int           scount = ppApp.ActivePresentation.Slides.Count;
            MsoLanguageID langID = MsoLanguageID.msoLanguageIDEnglishUS, curr_lang;

            if (lang == "US English")
            {
                langID = MsoLanguageID.msoLanguageIDEnglishUS;
            }
            else if (lang == "UK English")
            {
                langID = MsoLanguageID.msoLanguageIDEnglishUK;
            }
            curr_lang = ActivePPT.DefaultLanguageID;
            ActivePPT.DefaultLanguageID = langID;

            for (int sld = 1; sld <= ActivePPT.Slides.Count; sld++)
            {
                foreach (PowerPoint.Shape shp in ActivePPT.Slides[sld].Shapes)
                {
                    // '---------------- Check if it is a table
                    if (shp.Type == MsoShapeType.msoTable)
                    {
                        for (int r = 1; r <= shp.Table.Rows.Count; r++)
                        {
                            for (int c = 1; c <= shp.Table.Columns.Count; c++)
                            {
                                shp.Table.Cell(r, c).Shape.TextFrame.TextRange.LanguageID = langID;
                            }
                        }
                    }
                    //'------------- Check if it is a group of shapes
                    if (shp.Type == MsoShapeType.msoGroup)
                    {
                        if (shp.GroupItems.Count > 0)
                        {
                            for (int i = 1; i <= shp.GroupItems.Count; i++)
                            {
                                if (shp.GroupItems[i].HasTextFrame == MsoTriState.msoTrue)
                                {
                                    shp.GroupItems[i].TextFrame.TextRange.LanguageID = langID;
                                }
                            }
                        }
                    }
                    //'-------------- Check if it is a simple shape
                    if (shp.HasTextFrame == MsoTriState.msoTrue)
                    {
                        shp.TextFrame.TextRange.LanguageID = langID;
                    }
                }
                ActivePPT.Slides[sld].NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.LanguageID = langID;
            }
            MessageBox.Show("Language has been changed to " + lang + " in active presentation.", PPTAttribute.msgTitle, MessageBoxButtons.OK, MessageBoxIcon.Information);
            this.Close();
        }
Example #2
0
        RibbonDropDownItem CreateItem(MsoLanguageID languageId)
        {
            var ddi = Factory.CreateRibbonDropDownItem();

            ddi.Label = FormatLanguageString(languageId);
            ddi.Tag   = languageId;
            return(ddi);
        }
Example #3
0
        private string FormatLanguageString(MsoLanguageID language)
        {
            string        formattedLanguage = language.ToString().Replace("msoLanguageID", "");
            StringBuilder sb = new StringBuilder(formattedLanguage.Length);

            sb.Append(formattedLanguage[0]);
            bool previousWasUpper = true;
            bool moreUppers       = false;

            for (int i = 1; i < formattedLanguage.Length; i++)
            {
                if (Char.IsUpper(formattedLanguage[i]))
                {
                    if (!previousWasUpper)
                    {
                        sb.Append(' ');
                    }
                    if (!moreUppers)
                    {
                        sb.Append('(');
                        moreUppers = true;
                    }
                    previousWasUpper = true;
                }
                else
                {
                    previousWasUpper = false;
                }
                sb.Append(formattedLanguage[i]);
            }
            if (moreUppers)
            {
                sb.Append(')');
            }
            return(sb.ToString());
        }
Example #4
0
        public string DocumentLanguage()
        {
            string language = "US English";

            try
            {
                MsoLanguageID shp_lang, not_lang;
                Dictionary <MsoLanguageID, String> langDict = new Dictionary <MsoLanguageID, string>();
                MsoLanguageID doc_lang = ppApp.ActivePresentation.DefaultLanguageID;
                langDict.Add(doc_lang, "lang");
                //Set language in each textbox in each slide
                for (int sld = 1; sld <= ppApp.ActivePresentation.Slides.Count; sld++)
                {
                    foreach (PowerPoint.Shape shp in ppApp.ActivePresentation.Slides[sld].Shapes)
                    {
                        // '---------------- Check if it is a table
                        if (shp.Type == MsoShapeType.msoTable)
                        {
                            for (int r = 1; r <= shp.Table.Rows.Count; r++)
                            {
                                for (int c = 1; c <= shp.Table.Columns.Count; c++)
                                {
                                    shp_lang = shp.Table.Cell(r, c).Shape.TextFrame.TextRange.LanguageID;
                                    if (!langDict.ContainsKey(shp_lang))
                                    {
                                        langDict.Add(shp_lang, "lang");
                                    }
                                }
                            }
                        }
                        //'------------- Check if it is a group of shapes
                        if (shp.Type == MsoShapeType.msoGroup)
                        {
                            if (shp.GroupItems.Count > 0)
                            {
                                for (int i = 1; i <= shp.GroupItems.Count; i++)
                                {
                                    if (shp.GroupItems[i].HasTextFrame == MsoTriState.msoTrue)
                                    {
                                        shp_lang = shp.GroupItems[i].TextFrame.TextRange.LanguageID;
                                        if (!langDict.ContainsKey(shp_lang))
                                        {
                                            langDict.Add(shp_lang, "lang");
                                        }
                                    }
                                }
                            }
                        }
                        //'-------------- Check if it is a simple shape
                        if (shp.HasTextFrame == MsoTriState.msoTrue)
                        {
                            shp_lang = shp.TextFrame.TextRange.LanguageID;
                            if (!langDict.ContainsKey(shp_lang))
                            {
                                langDict.Add(shp_lang, "lang");
                            }
                        }
                    }
                    not_lang = shp_lang = ActivePPT.Slides[sld].NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.LanguageID;
                    if (!langDict.ContainsKey(not_lang))
                    {
                        langDict.Add(not_lang, "lang");
                    }
                }
                if (langDict.Count == 1)
                {
                    List <MsoLanguageID> dLang = new List <MsoLanguageID>();
                    dLang = langDict.Keys.ToList();
                    if (dLang[0] == MsoLanguageID.msoLanguageIDEnglishUS)
                    {
                        language = "US English";
                    }
                    if (dLang[0] == MsoLanguageID.msoLanguageIDEnglishUK)
                    {
                        language = "UK English";
                    }
                }
                else
                {
                    language = "Mixed (US/UK)";
                }
            }
            catch (Exception err)
            {
                string errtext = err.Message;
                PPTAttribute.ErrorLog(errtext, "DocumentLanguage");
            }
            return(language);
        }
        /// <summary>检查对象的拼写。
        /// </summary>
        /// <param name="CustomDictionary">一个字符串,它表示自定义词典的文件名,如果在主词典中找不到单词,则会到此词典中查找。如果省略此参数,则使用当前指定的词典。</param>
        /// <param name="IgnoreUppercase">如果为 True,则 Microsoft Excel 忽略所有字母都是大写的单词。如果为 False,则 Microsoft Excel 检查所有字母都是大写的单词。如果省略此参数,将使用当前的设置。</param>
        /// <param name="AlwaysSuggest">如果为 True,则 Microsoft Excel 在找到不正确拼写时显示建议的替换拼写列表。如果为 False,Microsoft Excel 将等待输入正确的拼写。如果省略此参数,将使用当前的设置。</param>
        /// <param name="SpellLang">当前所用词典的语言。它可以是由 LanguageID 属性使用的 MsoLanguageID 值之一。</param>
        public dynamic CheckSpelling(string CustomDictionary = null, bool? IgnoreUppercase = null, bool? AlwaysSuggest = null, MsoLanguageID? SpellLang = null)
        {
            _objaParameters = new object[4] {
                CustomDictionary == null ? System.Type.Missing : CustomDictionary,
                IgnoreUppercase == null ? System.Type.Missing : IgnoreUppercase,
                AlwaysSuggest == null ? System.Type.Missing : AlwaysSuggest,
                SpellLang == null ? System.Type.Missing : SpellLang
            };

            return _objRange.GetType().InvokeMember("CheckSpelling", BindingFlags.InvokeMethod, null, _objRange, _objaParameters);
        }