我正在为单词编写一个加载项,在下面的代码中,我将文件中的所有单词放在字典中。获取当前正在运行的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