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.
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
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())
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.
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.
I got this when I forgot to unprotect workbook or sheet.
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.
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.
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.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.
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.
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.
Source: Stackoverflow.com