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.Applicati on();) I get an exception which says..."Access is Denied".
Does anyone know what I'm doing wrong?
string strFileName = null;
string fileName = "Hockey";
Excel.Applicati on oXL;
Excel._Workbook oWB;
Excel._Workshee t oSheet;
oXL = new Excel.Applicati on();
oXL.Visible = false;
oWB= (Excel._Workboo k)(oXL.Workbook s.Add( Missing.Value ));
oSheet = (Excel._Workshe et)oWB.ActiveSh eet;
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(file Name,Excel.XlFi leFormat.xlWork bookNormal, null, null,false,
false, Excel.XlSaveAsA ccessMode.xlSha red, false, false, null,
null, null);
// Below line will kill the unkilled Excel process
Process[] pProcess;
pProcess = System.Diagnost ics.Process.Get ProcessesByName ("Excel");
pProcess[0].Kill();
oSheet= null;
oWB = null;
oXL = null;
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.Applicati on();) I get an exception which says..."Access is Denied".
Does anyone know what I'm doing wrong?
string strFileName = null;
string fileName = "Hockey";
Excel.Applicati on oXL;
Excel._Workbook oWB;
Excel._Workshee t oSheet;
oXL = new Excel.Applicati on();
oXL.Visible = false;
oWB= (Excel._Workboo k)(oXL.Workbook s.Add( Missing.Value ));
oSheet = (Excel._Workshe et)oWB.ActiveSh eet;
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(file Name,Excel.XlFi leFormat.xlWork bookNormal, null, null,false,
false, Excel.XlSaveAsA ccessMode.xlSha red, false, false, null,
null, null);
// Below line will kill the unkilled Excel process
Process[] pProcess;
pProcess = System.Diagnost ics.Process.Get ProcessesByName ("Excel");
pProcess[0].Kill();
oSheet= null;
oWB = null;
oXL = null;
Comment