查找文件是否正在使用 - 特别是 xls 文件

发布于 2024-12-26 14:05:35 字数 467 浏览 3 评论 0原文

检查了下面的链接并尝试使用那里提出的方法但没有结果。我的问题与使用 OLEDB 提供程序从 Excel 文件导入有关,由于某些我不明白的原因,当文件在 Excel 中打开时,导入将某些列(例如日期)显示为文本,当文件未在使用中。我的问题可以通过检查 xls 文件是否打开/正在使用来暂时解决,因此我可以发布一条消息要求用户关闭该文件。

谢谢, 米哈伊尔

https://www.google.com/search?rlz=1C1RNHN_enUS465US465&ix=hea&sourceid=chrome&ie=UTF-8&q=stackoverflow

Checked out the link bellow and tried to use the method proposed there with no results. My problem relates with importing from an Excel file using the OLEDB provider, for some reasons that I don't understand, when the file is open in Excel the import shows some columns (e.g date) as text, it doesn't happen when the file is not in use. My problem can be solved temporally by checking if the xls file is open/in use, so I can post a message asking the user to close the file.

Thanks,
Mihail

https://www.google.com/search?rlz=1C1RNHN_enUS465US465&ix=hea&sourceid=chrome&ie=UTF-8&q=stackoverflow.

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

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

发布评论

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

评论(1

小…楫夜泊 2025-01-02 14:05:35

一种方法是以独占模式打开文件。如果该文件在任何其他进程中打开,这将会失败,并且它还会阻止其他进程打开它,直到您关闭句柄。例如:

File.Open("worksheet.xls", FileMode.Open, FileAccess.Read, FileShare.None); 

One way to do that would be opening the file in exclusive mode. This will fail if the file is open in any other process, and it will also prevent other processes from opening it until you close the handle. For example:

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