odoe
[H]F Junkie
- Joined
- Oct 10, 2001
- Messages
- 9,796
I'm trying to work out a solution to open an Excel file on our network via C#. Eventually, I'll need to run a macro in the sheet, but I can't even get it open yet.
Here is what I have so far.
I get the following error.
"Attempted to read or write protected memory"
From what I can gather, this has to do with the excel file being read-only. Changing the permissions or getting the username/pass is not really an option at this time.
I can open the file by double-clicking it, no problem.
My goals here:
Open file as read-only.
(maybe need to add a sheet)
Launch macro that will read info from that sheet.
Let user close the file, no changes can be saved anyway.
Any nudge in a forward direction would be helpful, thanks.
If there is an easier way to do this in Python/Java or anything else I can run from a web service, I'm all ears.
Here is what I have so far.
Code:
string path = @"\\testserver1\Data\Flow\Sigma\Sigma_doc.xls";
try
{
Excel.Application excel = new Excel.Application();
Excel.Workbook wb = excel.Workbooks.Open(path, Missing.Value, true, Missing.Value, Missing.Value, Missing.Value, true, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
// the true values here have to do with opening in read-only mode, still fails
}
catch (Exception ex)
{
System.Console.WriteLine("shoot me in the head");
System.Console.WriteLine(ex.Message);
}
System.Console.ReadLine();
I get the following error.
"Attempted to read or write protected memory"
From what I can gather, this has to do with the excel file being read-only. Changing the permissions or getting the username/pass is not really an option at this time.
I can open the file by double-clicking it, no problem.
My goals here:
Open file as read-only.
(maybe need to add a sheet)
Launch macro that will read info from that sheet.
Let user close the file, no changes can be saved anyway.
Any nudge in a forward direction would be helpful, thanks.
If there is an easier way to do this in Python/Java or anything else I can run from a web service, I'm all ears.