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;
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()

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;