Write to an Excel file

R

Randy

Hello,
I'm trying to figure out how to do the above. I'm using a snippet of code I
found on the net (see below). My problem is when I hit the line (oXL = new
Excel.Application();) I get an exception which says..."Access is Denied".
Does anyone know what I'm doing wrong?

string strFileName = null;
string fileName = "Hockey";
Excel.Application oXL;
Excel._Workbook oWB;
Excel._Worksheet oSheet;

oXL = new Excel.Application();
oXL.Visible = false;
oWB= (Excel._Workbook)(oXL.Workbooks.Add( Missing.Value ));
oSheet = (Excel._Worksheet)oWB.ActiveSheet;
oSheet.Cells[1,1]="this is a test value";
((Range)oSheet.Cells[1,1]).ColumnWidth = 45;
((Range)oSheet.Cells[1,1]).EntireColumn.WrapText=true;
oWB.SaveAs(fileName,Excel.XlFileFormat.xlWorkbookNormal, null, null,false,
false, Excel.XlSaveAsAccessMode.xlShared, false, false, null,
null, null);
// Below line will kill the unkilled Excel process

Process[] pProcess;
pProcess = System.Diagnostics.Process.GetProcessesByName("Excel");
pProcess[0].Kill();

oSheet= null;
oWB = null;
oXL = null;
 
R

Randy

I found some information on the net that talked about having to handling
user rights to spawn Excel through the <identity> tag in the web.config
file?
Does anyone know what this is about?
 
A

Alvin Bruney [MVP - ASP.NET]

which line is dying?

--
Regards,
Alvin Bruney - ASP.NET MVP

[Shameless Author Plug]
The Microsoft Office Web Components Black Book with .NET
Now available @ www.lulu.com/owc, Amazon.com etc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top