I am programming an 开发者_StackOverflowexcel add in, and I want to be able to determine the full path of the current excel file open. What would the command be to get this as a string?
Thank You!
First of all you need to somehow get a Workbook
exemplar. My example would be obvious, because I've already know where is my file, but if you getting Workbook
passed to you from somewhere you can use the same property.
Excel.Application excelApp = new Excel.ApplicationClass();
string workbookPath = "c:/SomeWorkBook.xls";
Excel.Workbook openedWorkbook = excelApp.Workbooks.Open(workbookPath,
0, false, 5, "", "", false, Excel.XlPlatform.xlWindows, "",
true, false, 0, true, false, false);
Now you can use FullName
property to get name of file and all preceding path, or simply "Name" to get only filename: openedWorkbook.FullName
精彩评论