如何动态获取Word的Language ID
How to get the Language ID of Word dynamically
我想动态获取Word的语言id,并将其分配给Custom Dictionaries语言id。当我知道 Word 使用的语言 Word.WdLanguageID.wdEnglishUS; 时,我可以这样做。但是如何动态地得到这个。我尝试如下,但出现铸造错误。我可以在 VB6 中轻松完成此操作,但需要在 C# 中的解决方案。
Cannot implicitly convert type 'Microsoft.Office.Core.MsoLanguageID' to 'Microsoft.Office.Interop.Word.WdLanguageID'
C#
oCustDict.LanguageSpecific = true;
oCustDict.LanguageID = WordApp.Language;
VB6 - 有效
Dim lCurrentLanguage As Long
CurrentLanguage = WordApp.Language
oCustDict.LanguageSpecific = True
oCustDict.LanguageID = lCurrentLanguage
VB6 在强制执行变量类型方面出了名的糟糕 - 它会跳过看不见的环,试图将一种类型的数据填充到另一种类型的变量中,而且通常是错误的。
C# 在类型转换方面更加严格,在 99.9% 的情况下这是一件好事。在这种特殊情况下,看起来这两个枚举具有相同的值,因此您只需要添加一个显式转换:
oCustDict.LanguageID = (Microsoft.Office.Interop.Word.WdLanguageID)WordApp.Language;
我想动态获取Word的语言id,并将其分配给Custom Dictionaries语言id。当我知道 Word 使用的语言 Word.WdLanguageID.wdEnglishUS; 时,我可以这样做。但是如何动态地得到这个。我尝试如下,但出现铸造错误。我可以在 VB6 中轻松完成此操作,但需要在 C# 中的解决方案。
Cannot implicitly convert type 'Microsoft.Office.Core.MsoLanguageID' to 'Microsoft.Office.Interop.Word.WdLanguageID'
C#
oCustDict.LanguageSpecific = true;
oCustDict.LanguageID = WordApp.Language;
VB6 - 有效
Dim lCurrentLanguage As Long
CurrentLanguage = WordApp.Language
oCustDict.LanguageSpecific = True
oCustDict.LanguageID = lCurrentLanguage
VB6 在强制执行变量类型方面出了名的糟糕 - 它会跳过看不见的环,试图将一种类型的数据填充到另一种类型的变量中,而且通常是错误的。
C# 在类型转换方面更加严格,在 99.9% 的情况下这是一件好事。在这种特殊情况下,看起来这两个枚举具有相同的值,因此您只需要添加一个显式转换:
oCustDict.LanguageID = (Microsoft.Office.Interop.Word.WdLanguageID)WordApp.Language;