C# 如何确定打开文件的完整路径

发布于 2024-11-24 09:45:36 字数 80 浏览 3 评论 0原文

我正在编写一个 Excel 插件,我希望能够确定当前打开的 Excel 文件的完整路径。将其作为字符串获取的命令是什么?

谢谢你!

I am programming an excel 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

滿滿的愛 2024-12-01 09:45:36

首先,您需要以某种方式获得一个 Workbook 示例。我的例子很明显,因为我已经知道我的文件在哪里,但是如果您从某个地方将 Workbook 传递给您,您可以使用相同的属性。

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);

现在,您可以使用 FullName 属性来获取文件名和所有前面的路径,或者简单地使用“Name”来获取文件名:openedWorkbook.FullName

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文