![](/img/trans.png)
[英]How to get language ID for a language culture in nopCommerce 3.9?
[英]How to get the Language ID of Word dynamically
我想動態獲取Word的語言ID,並將其分配給“自定義詞典”語言ID。 當我知道Word使用Word.WdLanguageID.wdEnglishUS ;的語言時,可以執行此操作。 但是如何動態獲取。 我嘗試了以下操作,但出現了投放錯誤。 我可以在VB6中輕松地做到這一點,但需要使用C#解決方案。
無法將類型“ Microsoft.Office.Core.MsoLanguIDID”隱式轉換為“ 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;
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.