I am trying to delete a row from excel, but I am getting like this "Type mismatch. (Exception from HRESULT: 0x80020005 (DISP_E_TYPEMISMATCH))". The code is given bellow
try
{
ExcelApplication = new Microsoft.Office.Interop.Excel.Application();
ExcelWorkbook = ExcelApplication.Workbooks.Open(ExcelFileName, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value, Missing.Value
, Missing.Value, Missing.Value, Missing.Value);
ExcelWorksheet = (Worksheet)ExcelWorkbook.Worksheets.get_Item(ExcelSheetName);
ExcelWorkSheetRange = (Range)ExcelWorksheet.Cells.Find("SNO22", "SNO22", XlFindLookIn.xlValues, XlLookAt.xlWhole, XlSearchOrder.xlByRows, XlSearchDirection.xlNext,Missing.Value, false, false);
ExcelWorkSheetRange = ExcelWorksheet.get_Range(CellRange1, CellRange2);
ExcelWorkSheetRange = ExcelWorkSheetRange.EntireRow;
ExcelWorkSheetRange.Delete(Missing.Value);
ExcelWorkbook.Save();
}
catch (Exception ex)
{
System.Windows.Forms.MessageBox.Show(ex.Message, "Error", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
}
finally
{
ExcelWorkbook.Close(false, Missing.Value, Missing.Value);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelWorkbook);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelWorksheet);
System.Runtime.InteropServices.Marshal.ReleaseComObject(ExcelApplication);
}
if some one knows my Mistake, Please Help me to put out
Thankx