Поиск синонимов с помощью Microsoft Word на языке Си#
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Microsoft.Office.Interop.Word; using WordApplication = Microsoft.Office.Interop.Word.Application; using Microsoft.Office.Interop.Outlook; namespace synonyms_try1 { public partial class Form1 : Form { Class1 c=new Class1(); public Form1() { InitializeComponent(); } private void bSubmit_Click(object sender, EventArgs e) { Microsoft.Office.Interop.Word.Application appWord; // word application var object objNull = null; // word object method calls require // references to objects... create // object for null and object objFalse = false; // false entries and language object objLanguage = Microsoft.Office.Interop.Word.WdLanguageID.wdEnglishUS; // or appropritate lang! try { // Try opening Word app appWord = new Microsoft.Office.Interop.Word.Application(); } catch(System.Exception exc) { // could not open word... show error message and return MessageBox.Show(exc.Message); return; } // clear synonym listbox lbSynonym lbSynonym.Items.Clear(); // now call get_SynonymInfo to get SynonymInfo structure for // word entered in TextBox tbWord Microsoft.Office.Interop.Word.SynonymInfo si = appWord.get_SynonymInfo(tbWord.Text, ref (objLanguage)); // first find out how many meanings were found for word int iMeanings = (int)si.MeaningCount; if(iMeanings > 0) { // one or more meanings were found... loop over each // (notice SynonymInfo.MeaningList is type System.ArrayList!) foreach (string strMeaning in (Array)si.MeaningList) { // get Synonym List for each meaning... note that // get_SynonymList takes an object ref, thus we // must create objMeaning object object objMeaning = strMeaning; System.Array aSynonyms = (System.Array)si.get_SynonymList(ref objMeaning); foreach(string strSynonym in aSynonyms) { // loop over each synonym in ArrayList // and add to lbSynonym ListBox lbSynonym.Items.Add(strSynonym); } } } else { // no meanings/synonyms found... set ListBox value to "NONE" lbSynonym.Items.Add("NONE"); } // Clean up COM object c.Destroy(si); // quit WINWORD app appWord.Quit(ref objFalse, ref objNull, ref objNull); // clean up COM object c.Destroy(appWord); } } }
я использую этот код для поиска синонимов, но он дает ошибку
Unable to cast object of type 'System.String[*]' to type 'System.String[]'.
Ошибка на этой линии......
foreach (string strMeaning in (Array)si.MeaningList)
Скажите мне, что вы предлагаете, если у вас есть.. я беру этот код из этой ссылки jczerk solution use in this link..
C#: WordNet / MS Word Object Library Spellchecker / SynonymInfo[^]
Что я уже пробовал:
я пытаюсь найти синонимы с помощью microsoft word ...но это дает ошибку