Hi friends,
I have an application, written in C#, in which I am updating an Excel spreadsheet with data I pull from a sql database. When I try to select a cell in where I want to begin inserting my data I get the error -- Exception from HRESULT: 0x800A03EC (what does this mean?). I've searched the web and have been unsuccessful in finding a viable solution to the error. A snippet of my code is below:
Excel.Range cf = null;
// Create application object...
Excel.Application XcelApp = new Excel.ApplicationClass();
// I want to open an existing document for editing instead
// of creating a new one...
Excel.Workbook XcelWorkBook = XcelApp.Workbooks.Open(xlWorkBookPath,
0, false, 5, Type.Missing, Type.Missing, false,
Excel.XlPlatform.xlWindows, "", true, false, 0, true, false, false);
// initialize Excel objects...
Excel.Sheets XcelWorkSheets = XcelWorkBook.Worksheets;
Excel._Worksheet XcelWorkSheet = null;
// hide the app...
XcelApp.Visible = false;
Not ot bore anyone, but I open my workbook, locate and Activate my current worksheet; find the column I want and so on...
...
...
...
The error is when I try to select a specific location on my worksheet:
for (int i = 1; i <= dt.Rows.Count; i++)
{
curId = dt.Rows[i - 1].ItemArray[0].ToString();
if (counter.Equals(0)) row = 26; // next row...
if (counter.Equals(1)) row = 50; // ...
if (counter.Equals(2)) row = 74;
if (counter.Equals(3)) row = 98;
if (Int32.Parse(prvId) < Int32.Parse(curId)) // next row and so on...
{
This is where I get the exception
// It consistantly fails whenever counter is equal to 3.
XcelWorkSheet.Select(cellFound[row, col]);
prvId = curId; // current source id to previous source id
counter++;
...
... // do some more stuff...
}
}