我正在爲單詞編寫一個加載項,在下面的代碼中,我將文件中的所有單詞放在字典中。獲取當前正在運行的docx的路徑和名稱c#
`
Dictionary<string, string> motRap = new Dictionary<string, string>();
Microsoft.Office.Interop.Word.Application application = new Microsoft.Office.Interop.Word.Application();
Document document = application.Documents.Open("monfichiertxt.docx");
// Loop through all words in the document.
int count = document.Words.Count;
for (int i = 1; i <= count; i++)
{
// Write the word.
string text = document.Words[i].Text;
//motRapport.Add(text);
motRap.Add(text, "blabla");
}
// Close word.
application.Quit();
我想要當前正在運行的docx的文件名,而不是寫入「monfichiertxt.docx」。
有人可以幫我請 謝謝。
可能的複製[如何使用後期綁定訪問Microsoft Word中存在的實例]( https://stackoverflow.com/questions/2203968/how-to-access-mic rosoft-word-existing-instance-using-late-binding) – BugFinder