Advertisement

01.08.2005 at 06:49PM PST, ID: 21267120
[x]
Attachment Details

Exception from HRESULT: 0x800A03EC. with excel program in C#

Asked by mathieu_cupryk in C# Programming Language

Tags: 0x800a03ec, from, exception

Exception Details: System.Runtime.InteropServices.COMException: Exception from HRESULT: 0x800A03EC.

Source Error:


Line 32:                   xlApp.Visible = true;
Line 33:                   string strFileName = sFileName;
Line 34:                   Excel.Workbook xlWB =  xlApp.Workbooks.Open("ExcelData.xls",
Line 35:                         null,
Line 36:                         null,
 

Source File: c:\inetpub\wwwroot\webapplication1\webform2.aspx.cs    Line: 34

Code:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Diagnostics;
using System.Reflection;
using Excel= Microsoft.Office.Interop.Excel;
using System.Data.OleDb;
using System.IO;
using System.Text;
using System.Runtime.InteropServices; // For COMException

namespace WebApplication1
{
      /// <summary>
      /// Summary description for WebForm2.
      /// </summary>
      public class WebForm2 : System.Web.UI.Page
      {
            protected Excel.Application xlApp;
            protected Excel.Workbook xlWB1;
                  
            private void searchExcelSpreadSheet(string sFileName)
            {
                  Excel.Application xlApp = new Excel.Application();
                  xlApp.Visible = true;
                  string strFileName = sFileName;
                  Excel.Workbook xlWB =  xlApp.Workbooks.Open("ExcelData.xls",
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null,
                        null);
                  Excel.Worksheet xls = (Excel.Worksheet)xlWB.Sheets[1];

                  int intRows, intCols, r, c;

                  intRows = xls.UsedRange.Rows.Count;
                  intCols = xls.UsedRange.Columns.Count;

                  for(r = 1; r < intRows; r++)
                  {
                        for(c=1; c < intCols; c++)
                        {
                              string text = (string)((Excel.Range)xls.Cells[r,c]).Text;
                              Response.Write (text+"<br>");
                        }
                  }
               
                  xlWB.Close(false, null, null);
                  xlApp.Quit();
                  xls = null;
                  xlWB = null;
                  xlApp = null;

            }

            
            private void Page_Load(object sender, System.EventArgs e)
            {
                  // Put user code to initialize the page here
                  searchExcelSpreadSheet ("\\Excel\\ExcelData.xls");

            }

            #region Web Form Designer generated code
            override protected void OnInit(EventArgs e)
            {
                  //
                  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
                  //
                  InitializeComponent();
                  base.OnInit(e);
            }
            
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {    
                  this.Load += new System.EventHandler(this.Page_Load);
            }
            #endregion
      }
}
Start Free Trial
[+][-]01.10.2005 at 02:06AM PST, ID: 13001375

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]01.10.2005 at 02:08AM PST, ID: 13001385

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: C# Programming Language
Tags: 0x800a03ec, from, exception
Sign Up Now!
Solution Provided By: prakash_prk
Participating Experts: 2
Solution Grade: C
 
 
 
Loading Advertisement...
20080716-EE-VQP-32