none
Recognize MS-Office language settings on user PC RRS feed

  • Question

  • Hello,

    I am opening, editting, saving and then closing a word file using a dll. It writes a table which is then filled with string values provided by the user.

    The issue is that the dll functions correctly if the user has installed word in German language. For a user who has installed Office in English language, I have to change the code and compile the dll again.

    For e.g., the following is the part of code that draws table in a word document:
    Code:
    object TableStyle = "Mittlere Formatvorlage 8";
    Microsoft.Office.Interop.Word.Range tableLocation = m_ReportDoc.Range(ref start, ref end);
    m_ReportDoc.Tables.Add(tableLocation, aRows, aColumn, ref MISSING, ref MISSING);            
    m_ReportDoc.Tables[1].set_Style(ref TableStyle);
    As clear from the code the table style is set to "Mittlere Formatvorlage 8". This style is "Table Grid 8" (example) in English.

    Now my questions are:
    - how can I know in which language the word has been set by the user on his/her PC, so that depending on the set language, I can set the table style.
    - Is there any method, so that I can set table style in German without accounting for the language. The word automatically looks for the replacement of given style in the installed language. This happens when I recieve a word file which was originally created in English but opens without any problem on my PC where the word is installed in German.

    Thanks in advance.

    Regards
    Ricky
    • Moved by Bob Shen Monday, September 24, 2012 3:00 AM (From:Visual C# Language)
    Friday, September 21, 2012 1:53 PM

Answers

  • Hi Ricky

    Tom is referring to the fact that the built-in styles in Word have a WdBuiltinStyle Enum that can be used instead of the style name in order to address a built-in style. He's asking whether the style in your code is a built-in style? If yes, then you should be able to look up the Enum value and use that instead of the string in your code sample.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, September 25, 2012 5:32 AM
    Moderator
  • Hi Cindy,

    Thanks for your excellent explain. Yes, all like what you said. I hope your explain can help Ricky to resolve his issue.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us


    Tuesday, September 25, 2012 6:21 AM
    Moderator

All replies

  • Hi ricky,

    According to your description, I'd like to move this thread to Word dev Forum for better support, where more experts live.
     
    Thanks for your understanding.


    Bob Shen [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 24, 2012 2:58 AM
  • Hi ricky_CSharp,

    Thanks for posting in the MSDN Forum.

    - how can I know in which language the word has been set by the user on his/her PC

    I think following snippet can solved this problem:

            private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Office.LanguageSettings objLanguageSetting = 
                    Application.LanguageSettings;
                CultureInfo objCultureInfo = 
                    new CultureInfo(objLanguageSetting
                        .get_LanguageID(Office.MsoAppLanguageID.msoLanguageIDUI));
                Properties.Resources.Culture = objCultureInfo;
            }
    Is there any method, so that I can set table style in German without accounting for the language.

    Due to you use string index to set the style and I have no culture environment to reproduce your issue. I would recommend you do more research to see whether it can use number as index. If it can use number index it will not depend on the culture information.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us

    Monday, September 24, 2012 5:35 AM
    Moderator
  • Hello Tom,

    Sorry, but I did not understand the last part of your answer. Where to use number as Index? Did you mean that there exists a specific number that exists for a style which is same for all languages/culture?

    Regards

    Ricky

    Monday, September 24, 2012 3:54 PM
  • Hi Ricky

    Tom is referring to the fact that the built-in styles in Word have a WdBuiltinStyle Enum that can be used instead of the style name in order to address a built-in style. He's asking whether the style in your code is a built-in style? If yes, then you should be able to look up the Enum value and use that instead of the string in your code sample.


    Cindy Meister, VSTO/Word MVP, my blog

    Tuesday, September 25, 2012 5:32 AM
    Moderator
  • Hi Cindy,

    Thanks for your excellent explain. Yes, all like what you said. I hope your explain can help Ricky to resolve his issue.

    Have a good day,

    Tom


    Tom Xu [MSFT]
    MSDN Community Support | Feedback to us


    Tuesday, September 25, 2012 6:21 AM
    Moderator
  • Hello,

    Thank you Tom and Cindy. It worked fine. Now we do not need to recompile depending on the language.

    Just an observation:

    The WdBuildInStyle defines all table stlyes as enumration but not their Accent. Although its not so important but is good to know if one can also apply different accents.

    I could also find some interesting information where styles are given in some code with a small note in the start that says "any values can change any time in any version"Regards

    Ricky

    Tuesday, September 25, 2012 9:17 AM