Handling Exception from HRESULT: 0x800401A8

2

I have a application where on Button click excel sheet will be opened and Data will be inserted into it. If i close excel sheet before inserting data folloeing exception occurs..
Exception from HRESULT: 0x800401A8

Is ther any way to handle this. My code is

   Excel.Application objApp = null;
        Excel._Workbook objBook = null;
        Excel.Workbooks objBooks = null;
        Excel.Worksheet workSheet = null;

        objApp = new Excel.Application();
        objBooks = objApp.Workbooks;

        objBook = objBooks.Open(path, 2, false, 5, "", "", true, Excel.XlPlatform.xlWindows, "\t", true, false, 0, true);
        objBook.Activate();
        objApp.Visible = true;
        workSheet = (Excel.Worksheet)objBook.Worksheets[1];

        //sqlQueryForShoppingCenter.Append(" select shp_ctr_id,ctr_name,addr_city,addr_line1 from shp_ctr where shp_ctr_id='SCL00002' ");

        sqlQueryForShoppingCenter.Append(" select Shp_ctr_id,Ctr_Name,addr_city,Addr_line1 from shp_ctr  where shp_ctr_id='68729'");
        using (OracleDataReader reader1 = SqlStatementUtil.ExecuteReader(sqlQueryForShoppingCenter.ToString()))
        {
            while (reader1.Read())
            {
                if (workSheet != null)
                {
                    workSheet.Cells[4, 6] = reader1["Shp_ctr_id"].ToString();
                    workSheet.Cells[5, 6] = reader1["Ctr_Name"].ToString();
                    workSheet.Cells[6, 6] = reader1["addr_city"].ToString();
                    workSheet.Cells[7, 6] = reader1["Addr_line1"].ToString();
                }
            }
        }

If Excel is not closed data will be successfully inserted. But if excel is closed before inserting data , i want to skip insertion how to handle it...

I have tried to handle this by putting various conditions.. Please help

excel
c#-4.0
exception-handling
asked on Stack Overflow May 23, 2013 by Suresh

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0