L
luvic.vangool
Hello,
I have been stuck on this for some time now... no matter what I do, I
can't seem to programmatically delete a worksheet from a spreadsheet!
I've tried many different approaches, and none of them seem to work.
There must be something staring me in the face, but I just can't see
it!
Below is a stripped down app to delete a sheet (not working) - can
anyone identify why? or give me some pointers as to how to approach
this?
Many many thanks for your help
Luvic.
static void Main(string[] args)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new
ApplicationClass();
Workbook workbook = null;
try
{
workbook =
ExcelApp.Workbooks.Open(path,0,true,5,"","",true,XlPlatform.xlWindows,"",false,false,0,false,null,null);
ExcelApp.Visible = true;
ExcelApp.DisplayAlerts = false;
((Worksheet)workbook.Sheets["Sheet1"]).Delete();
}
catch { }
finally
{
NAR(workbook);
ExcelApp.Quit();
NAR(ExcelApp);
}
}
private static void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
}
catch { }
finally
{
o = null;
}
}
I have been stuck on this for some time now... no matter what I do, I
can't seem to programmatically delete a worksheet from a spreadsheet!
I've tried many different approaches, and none of them seem to work.
There must be something staring me in the face, but I just can't see
it!
Below is a stripped down app to delete a sheet (not working) - can
anyone identify why? or give me some pointers as to how to approach
this?
Many many thanks for your help
Luvic.
static void Main(string[] args)
{
Microsoft.Office.Interop.Excel.Application ExcelApp = new
ApplicationClass();
Workbook workbook = null;
try
{
workbook =
ExcelApp.Workbooks.Open(path,0,true,5,"","",true,XlPlatform.xlWindows,"",false,false,0,false,null,null);
ExcelApp.Visible = true;
ExcelApp.DisplayAlerts = false;
((Worksheet)workbook.Sheets["Sheet1"]).Delete();
}
catch { }
finally
{
NAR(workbook);
ExcelApp.Quit();
NAR(ExcelApp);
}
}
private static void NAR(object o)
{
try
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(o);
}
catch { }
finally
{
o = null;
}
}