使用sheetname获取我的excel文件的FilePath

6 c# filepath

我想做的是获取我的excel文件的文件路径.但我无法这样做.

文件位于Document/Visual Studio 2013/Project/ProjectName/a.xlsx中

string path = Path.Combine(HttpContext.Current.Server.MapPath("~/"),"a.xlsx");
string SheetName="Sheet1";
Run Code Online (Sandbox Code Playgroud)

这样做是错误的还是正确的方法?

小智 1

根据我的说法,这是更好的答案。

最好保存在

C:\Users\AJ1110\Documents\Visual Studio 2013\Projects\Proj\Proj 
Run Code Online (Sandbox Code Playgroud)

并且在

程序.cs

string pathfile = @"..\..\a.xlsx";
string sheetName = "Whatever_SheetName_IS!!!";
Run Code Online (Sandbox Code Playgroud)

这可能会解决你的问题。