限制对C#程序打开的Excel文件的访问 [英] Restrict access to excel file opened by C# program

查看:80
本文介绍了限制对C#程序打开的Excel文件的访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题1:

我已经打开了一个excel文件

I've opened an excel file with

Excel.Application app = new Excel.ApplicationClass();
Excel.Workbook Wbook = app.Workbooks.Open("aaa.xlsx",...);

现在,我要停止其他程序访问"aaa.xlsx".(想限制其他程序(如excel.exe&等)的访问权限

Now, I want to stop other programs accessing "aaa.xlsx". (want to restrict access by other programs like excel.exe & etc)

我可以设置锁定/阻止/限制文件打开的任何选项吗?

Are there any options that I can set to lock/block/restrict file open?

问题2:

自从我做完这个

Excel.Application app = new Excel.ApplicationClass();

我创建了一个新的excel实例.我想将其隐藏起来,以防外部使用.(我不希望在系统上双击一些随机的excel文件时弹出它.)

I've created a new instance of excel. I want to hide it from external use. (I don't want it to pop up when some random excel file is double clicked on the system.)

有什么办法可以防止它被自动调用?

Is there something I can do to prevent it from being called up automatically?

任何帮助将不胜感激.

推荐答案

一个丑陋的解决方案,但您可以做到:

An ugly solution but you could do it:

自己打开并锁定文件.将其复制到一个临时位置,将该临时加载到您的隐藏窗口中.保存后,将其复制回原始位置.请注意,这两个副本都必须在程序中实现,因为锁定将阻止Windows执行此操作.

Open and lock the file yourself. Copy it to a temporary location, load that temporary into your hidden window. After saving it copy it back to the original location. Note that both of these copies will have to be implemented in your program as the lock will preclude Windows from doing it.

这篇关于限制对C#程序打开的Excel文件的访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆