tags:

views:

33

answers:

2

Question 1:

I've opened an excel file with

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

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?

Question 2:

Since I've done this

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

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?

Any help would be much appreciated.

A: 

These should probably be separate questions, but I will try.

Also, caveat emptor: It's been a while since I've touched Office Automation and don't have the docs handy, so I'm going off memory.

The Excel.Application object should have a Visible property. Set it to false to hide the application.

As for opening the document, check the docs to see if there are any parameters like "FileAccess". I can't remember off hand, but I will keep looking...

Edit: Okay, I found the documentation on MSDN, but there doesn't appear to be any way to specify that Excel should lock the document while it's open. Sorry.

Mike Caron
I was thinking there must be something to support this but nothing so far. Thank you for the effort anyways.
Die4ACause
A: 

An ugly solution but you could do it:

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.

Loren Pechtel
hrm.. yeah I'm sort of running out of ideas on how to do this so I'll consider your suggestion. thnkx.
Die4ACause