Reputation: 1536
I am working with Window Service project. that have to write data to a sheet in Excel file in a sequence times.
But sometimes, just sometimes, the service throw out the exception "Exception from HRESULT: 0x800A03EC" while it's trying to get range with cell's name.
I have put the code of opening excel sheet, and getting cell here.
1: Opening excel sheet
m_WorkBook = m_WorkBooks.Open(this.FilePath, 0, false, 5,
"", "", true, Excels.XlPlatform.xlWindows, ";",
true, false, 0, true, 0, 0);
2: Getting cell to write
protected object m_MissingValue = System.Reflection.Missing.Value;
Range range = m_WorkSheet.get_Range(cell.CellName, m_MissingValue);
// error from this method, and cell name is string.
Upvotes: 31
Views: 148918
Reputation: 35400
For me this was happening because I was doing this:
System.Windows.Forms.Clipboard.SetDataObject(SomeSerializedObject);
ws.Range[selectionAddress].Select();
ws.Paste();
For some reason, Excel needs some "breathing time" before we could issue Paste command. After spending a lot of time digging this cryptic error, I found this reason and added the following delay mechanism:
System.Windows.Forms.Clipboard.SetDataObject(SomeSerializedObject);
ws.Range[selectionAddress].Select();
Dispatcher.CurrentDispatcher.BeginInvoke(new System.Action(() =>
{
ws.Paste();
}));
and it started behaving correctly. Note that I was using WPF and had to use BeginInvoke
through the current Dispatcher
object. It's basically running the Paste()
function asynchronously to free up Excel application to do whatever it need to do before pasting.
Upvotes: 0
Reputation: 1
I found the answer to my problem. ((Excel.Range)worksheet.Cells[x, y]).Text, where x & y have to be greater than 0. (Starting from 1.)
Upvotes: 0
Reputation: 1093
Excel Range index is None-Zero and start from 1.
If you call sheet.Rows[0]
or sheet.Columns[0]
or sheet.Cells[0]
exception was thrown, because index is start from 1 and 0 is invalid index.
Upvotes: 2
Reputation: 1
Hi was Facing the same issue
Steps
make sure you are accessing the excel file, not in read-only mode(protected mode) while trying edit and save changes.
If it happens after that as well you can go to excel file-->Options-->Formulas and here disable the error checking(which is cause for almost most of the HRESULT errors)
Upvotes: 0
Reputation: 1331
Interesting enough, this error also occurs, at time of opening when the .XLS?
file is incorrectly formed or require repairs.
A hard to find error is to many rows on a .xls (old excel) file.
Test it: manually open the affected file with excel desktop .
I use automation to process a few hundred files daily, when this error show up, I notify the owner via mail and save the unprocessed file on a temporary location.
Upvotes: 0
Reputation: 1
I ran to a similar error running Excel in VBA, what I've learned is that when I pull data from MSSQL, and then using get_range
and .Value2
apply it's out of the range, any value that was of type uniqueidentifier
(GUID) resulted in this error.
Only when I cast the value to nvarcahr(max)
it worked.
Upvotes: 0
Reputation: 357
Using Dominic's answer I found the answer to my problem specifically was an invalid DateTiime in the source data before it was applied to the range. Somewhere between the database, .NET and Excel the conversion of the date defaulted down to "1/1/1899 12:00:00 AM". I had to check it and convert it to an empty string and it fixed it for me.
if (objectArray[row, col].ToString() == "1/1/1899 12:00:00 AM")
{
objectArray[row, col] = string.Empty;
}
This is probably a pretty specific example but hopefully it will save somebody else some time if they are trying to track down a piece of invalid data.
Upvotes: 1
Reputation: 8138
The meaning of the completely undocumented error 800A03EC (shame on Microsoft!) is something like "OPERATION NOT SUPPORTED".
It may happen
But mostly you will see this error due to severe bugs in Excel.
Application.Visible=true
and Application.WindowState = XlWindowState.xlMinimized
then you will get hundreds of 800A03EC errors from different functions (like Range.Merge(), CheckBox.Text, Shape.TopLeftCell, Shape.Locked and many more). This bug does not exist in Excel 2007 and 2010.Upvotes: 5
Reputation: 381
I ran into this error because I was attempting to write a string to a cell which started with an "=".
The solution was to put an "'" (apostrophe) before the equals sign, which is a way to tell excel that you're not, in fact, trying to write a formula, and just want to print the equals sign.
Upvotes: 7
Reputation: 11
I had this problem when I was trying to use the range.AddComment() function. I was able to solve this by calling range.ClearComment() before adding the comment.
Upvotes: 1
Reputation: 65554
I got the error with a space in a Sheet Name:
using (var range = _excelApp.Range["Sheet Name Had Space!$A$1"].WithComCleanup())
I fixed it by putting single quotes around Sheet Names with spaces:
using (var range = _excelApp.Range["'Sheet Name Had Space'!$A$1"].WithComCleanup())
Upvotes: 4
Reputation:
I found a possible solution here: http://www.made4dotnet.com/Default.aspx?tabid=141&aid=15
Edit:
If you automate Microsoft Excel with Microsoft Visual Basic .NET, Microsoft Visual C# .NET, or Microsoft Visual C++, you may receive the following errors when calling certain methods because the machine has the locale set to something other than US English (locale ID or LCID 1033):
Exception from HRESULT: 0x800A03EC
and/or
Old format or invalid type library
SOLUTION 1:
To get around this error you can set CurrentCulture to en-US when executing code related to Excel and reset back to your originale by using these 2 functions.
//declare a variable to hold the CurrentCulture
System.Globalization.CultureInfo oldCI;
//get the old CurrenCulture and set the new, en-US
void SetNewCurrentCulture()
{
oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
}
//reset Current Culture back to the originale
void ResetCurrentCulture()
{
System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
}
SOLUTION 2:
Another solution that could work, create a 1033 directory under Microsoft Office\Office11 (or your corresponding office-version), copy excel.exe to the 1033 directory, and rename it to xllex.dll.
Although you might solve the problem using one off these solutions, when you call the Excel object model in locales other than US English, the Excel object model can act differently and your code can fail in ways you may not have thought of. For example, you might have code that sets the value of a range to a date:
yourRange.Value2 = "10/10/09"
Depending on the locale this code can act differently resulting in Excel putting into the range any of the following values:
October 10, 2009 September 10, 2009 October 9, 2010
Upvotes: 5
Reputation: 4464
If you can copy the whole exception it would be much more better, but once I faced with this Exception and this is because the function calling from your dll file which I guess is Aspose.dll hasn't been signed well. I think it would be the possible duplicate of this
FYI, in order to find out if your dll hasn't been signed well you should right-click on that and go to the signiture and it will tell you if it has been electronically signed well or not.
Upvotes: -2
Reputation: 8444
The error code 0x800A03EC
(or -2146827284) means NAME_NOT_FOUND; in other words, you've asked for something, and Excel can't find it.
This is a generic code, which can apply to lots of things it can't find e.g. using properties which aren't valid at that time like PivotItem.SourceNameStandard
throws this when a PivotItem doesn't have a filter applied. Worksheets["BLAHBLAH"]
throws this, when the sheet doesn't exist etc. In general, you are asking for something with a specific name and it doesn't exist. As for why, that will taking some digging on your part.
Check your sheet definitely does have the Range you are asking for, or that the .CellName
is definitely giving back the name of the range you are asking for.
Upvotes: 31
Reputation: 10460
I have encountered this error code when enumerating names and calling worksheet.get_Range(name). It seems to occur when the name does NOT apply to a range, in my case it is the name of a macro.
Upvotes: 0