查找文件是否正在使用 - 特别是 xls 文件
检查了下面的链接并尝试使用那里提出的方法但没有结果。我的问题与使用 OLEDB 提供程序从 Excel 文件导入有关,由于某些我不明白的原因,当文件在 Excel 中打开时,导入将某些列(例如日期)显示为文本,当文件未在使用中。我的问题可以通过检查 xls 文件是否打开/正在使用来暂时解决,因此我可以发布一条消息要求用户关闭该文件。
谢谢, 米哈伊尔
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一种方法是以独占模式打开文件。如果该文件在任何其他进程中打开,这将会失败,并且它还会阻止其他进程打开它,直到您关闭句柄。例如:
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: