简体   繁体   English

HRESULT 异常:0x800A03EC 错误

[英]Exception from HRESULT: 0x800A03EC Error

I am getting "HRESULT: 0x800A03EC" error when running Excel add-in with following code:使用以下代码运行 Excel 加载项时出现“HRESULT:0x800A03EC”错误:

Excel.Range rng = ActiveSheet.Cells[x, y] as Excel.Range;                
string before = rng.Value2; 
string cleanV = System.Text.RegularExpressions.Regex.Replace(before, @"\s+", "");
rng.set_Value(cleanV);

When error happens X and Y are set to 1, thus Excel range is not violated.发生错误时,X 和 Y 设置为 1,因此不会违反 Excel 范围。 I searched extensively and tried a number of ways of setting the cell value (eg. Cells[x,y], range.set_Value()) but am at loss why this error happens and how to avoid it.我进行了广泛的搜索并尝试了多种设置单元格值的方法(例如 Cells[x,y]、range.set_Value()),但不知道为什么会发生此错误以及如何避免它。

Any help is greatly appreciated.任何帮助是极大的赞赏。

Below are exception details:以下是异常详情:


System.Runtime.InteropServices.COMException was unhandled by user code
  HResult=-2146827284
  Message=Exception from HRESULT: 0x800A03EC
  Source=""
  ErrorCode=-2146827284
  StackTrace:
       at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       at Microsoft.Office.Interop.Excel.Range.set_Value(Object RangeValueDataType, Object value)
       at ImportValidation.ThisAddIn.removeAnySpaces(Int32 x, Int32 y) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\ThisAddIn.cs:line 354
       at ImportValidation.ThisAddIn.ReadHeaders(Hashtable columnAddress) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\ThisAddIn.cs:line 123
       at ImportValidation.ThisAddIn.mapColumns() in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\ThisAddIn.cs:line 493
       at ImportValidation.Ribbon1.button6_Click(Object sender, RibbonControlEventArgs e) in c:\Users\dshevelev\Documents\Visual Studio 2012\Projects\ImportValidation\ImportValidation\Ribbon1.cs:line 55
       at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ControlActionRaise(IRibbonControl control)
       at Microsoft.Office.Tools.Ribbon.RibbonPropertyStorage.ButtonClickCallback(RibbonComponentImpl component, Object[] args)
       at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.Invoke(RibbonComponentCallback callback, Object[] args)
       at Microsoft.Office.Tools.Ribbon.RibbonMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
       at Microsoft.Office.Tools.Ribbon.RibbonManagerImpl.System.Reflection.IReflect.InvokeMember(String name, BindingFlags invokeAttr, Binder binder, Object target, Object[] args, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParameters)
  InnerException: 

Got same error in this line在这一行得到同样的错误

 Object temp = range.Cells[i][0].Value;

Solved with non-zero based index用基于非零的索引解决

 Object temp = range.Cells[i][1].Value;

How is it possible that the guys who created this library thought it was a good idea to use non-zero based indexing?创建这个库的人怎么可能认为使用基于非零的索引是个好主意?

This is a common but poorly documented Excel COM Error.这是一个常见但记录不足的 Excel COM 错误。 I've seen it documented as "NAME_NOT_FOUND", meaning that Excel's COM layer is disabled, and can't find the COM property or method name.我已经看到它记录为“NAME_NOT_FOUND”,这意味着 Excel 的 COM 层被禁用,并且找不到 COM 属性或方法名称。

I get this error consistently when running the COM code while Excel is 'busy', for example if you set a timer that will start the code, and the code starts running while the user is editing a cell or pressing down their mouse button, then you'll always get this error.在 Excel 处于“忙碌”状态时运行 COM 代码时,我始终收到此错误,例如,如果您设置了一个将启动代码的计时器,并且在用户编辑单元格或按下鼠标按钮时代码开始运行,则你总是会收到这个错误。 This error only happens when the code runs on the main Excel thread, but seems to be the equivalent of error VBA_E_IGNORE = 0x800AC472, which you get when calling the Excel COM object model from another thread, while Excel is 'busy'.此错误仅在代码在 Excel 主线程上运行时发生,但似乎等同于错误 VBA_E_IGNORE = 0x800AC472,这是在 Excel 处于“忙”状态时从另一个线程调用 Excel COM 对象模型时得到的。

The only workaround seems to be to retry (with some small delay) the COM call until it succeeds - when Excel is no longer 'busy'.唯一的解决方法似乎是重试(有一些小的延迟)COM 调用,直到它成功 - 当 Excel 不再“忙”时。

Check your start indexes.检查您的启动索引。 Its start from 1 not 0 for Microsoft.Office.Interop.Excel range objects.对于 Microsoft.Office.Interop.Excel 范围对象,它从 1 开始,而不是 0。 I had received same error because of my loop start value.由于我的循环起始值,我收到了同样的错误。

Go to Excel Options > Save > Save Files in this format > Select "Excel Workbook(*.xlsx)".转到 Excel 选项 > 保存 > 以这种格式保存文件 > 选择“Excel 工作簿(*.xlsx)”。 This problem occurs if you are using an older version of excel file (.xls) instead of .xlsx.如果您使用旧版本的 excel 文件 (.xls) 而不是 .xlsx,则会出现此问题。 The older version does not allow more than 65k rows in the excel sheet.旧版本不允许 Excel 工作表中超过 65k 行。

Once you have saved as .xslx, try executing your code again.保存为 .xslx 后,请再次尝试执行代码。

edit ----编辑 - -

Looking more into your problem, it seems that the problem might be locale specific.更深入地研究您的问题,似乎问题可能是特定于语言环境的。 Does the code work on another machine?代码在另一台机器上工作吗? What value does the cell have?细胞有什么价值? Is it datetime format?是日期时间格式吗? Have a look here:看看这里:

http://support.microsoft.com/kb/320369 http://support.microsoft.com/kb/320369

http://blogs.msdn.com/b/eric_carter/archive/2005/06/15/429515.aspx http://blogs.msdn.com/b/eric_carter/archive/2005/06/15/429515.aspx

Got this error also....也有这个错误....

it occurs when save to filepath contains invalid characters, in my case:当保存到文件路径包含无效字符时会发生这种情况,在我的情况下:

path = "C:/somefolder/anotherfolder\file.xls";

Note the existence of both \\ and /注意\\/的存在

*Also may occur if trying to save to directory which doesn't already exist. *如果尝试保存到尚不存在的目录,也可能发生。

We had the same problem and found for us the solution :我们遇到了同样的问题,并为我们找到了解决方案:

Please make this folder.请制作此文件夹。 C:\\Windows\\SysWOW64\\config\\systemprofile\\Desktop ·Windows 2008 Server x86 C:\\Windows\\SysWOW64\\config\\systemprofile\\Desktop ·Windows 2008 Server x86
Please make this folder.请制作此文件夹。 C:\\Windows\\System32\\config\\systemprofile\\Desktop C:\\Windows\\System32\\config\\systemprofile\\Desktop

I know this is old but just to pitch in my experience.我知道这很旧,但只是为了介绍我的经验。 I just ran into it this morning.我今天早上刚碰到它。 Turns our my error has nothing to do with .xls line limit or array index.原来我的错误与 .xls 行限制或数组索引无关。 It is caused by an incorrect formula.这是由错误的公式引起的。

I was exporting from database to Excel a sheet about my customers.我正在从数据库向 Excel 导出一张关于我的客户的表格。 Someone fill in the customer name as =90Erickson-King and apparently this is fine as a string-type field in the database, however will result in an error as a formula in Excel.有人将客户名称填写为=90Erickson-King ,显然这作为数据库中的字符串类型字段很好,但是会导致 Excel 中的公式错误。 Instead of showing #N/A like when you're using Excel, the program just froze and spilt that 0x800A03EC error a while later.当您使用 Excel 时,该程序#N/A像使用 Excel 那样显示#N/A ,而是在一段时间后冻结并溢出 0x800A03EC 错误。

I corrected this by deleting the equal sign and the dash in the customer's name.我通过删除客户姓名中的等号和破折号来更正此问题。 After that exporting went well.之后出口顺利。

I guess this error code is a bit too general as people are seen reporting quite a range of different possible causes.我想这个错误代码有点太笼统了,因为人们看到了很多不同的可能原因。

Got the same error when tried to export a large Excel file (~150.000 rows) Fixed with the following code尝试导出大型 Excel 文件(~150.000 行)时遇到相同的错误,使用以下代码修复

Application xlApp = new Application();
xlApp.DefaultSaveFormat = XlFileFormat.xlOpenXMLWorkbook;

I got the same error whilst using Excel 2003 DLLs and trying to write to the 257th column.我在使用 Excel 2003 DLL 并尝试写入第 257 列时遇到了同样的错误。 Excel 2003 limits maximum column per worksheet to 256, thus raising this exception. Excel 2003 将每个工作表的最大列数限制为 256,从而引发此异常。

For detailed limitations of Excel 2003, see http://office.microsoft.com/en-001/excel-help/excel-specifications-and-limits-HP005199291.aspx有关 Excel 2003 的详细限制,请参阅http://office.microsoft.com/en-001/excel-help/excel-specifications-and-limits-HP005199291.aspx

Starting from Excel 2007, column limitation is increased to 16384 columns, see http://office.microsoft.com/en-001/excel-help/excel-specifications-and-limits-HP010073849.aspx从 Excel 2007 开始,列限制增加到 16384 列,请参阅http://office.microsoft.com/en-001/excel-help/excel-specifications-and-limits-HP010073849.aspx

I was receiving the same error some time back.前段时间我收到了同样的错误。 The issue was that my XLS file contained more than 65531 records(500 thousand to be precise).问题是我的 XLS 文件包含超过 65531 条记录(准确地说是 50 万条)。 I was attempting to read a range of cells.我试图读取一系列单元格。

Excel.Range rng = (Excel.Range) myExcelWorkbookObj.UsedRange.Rows[i];

The exception was thrown while trying to read the range of cells when my counter, ie 'i', exceeded this limit of 65531 records.当我的计数器(即“i”)超过 65531 条记录的限制时,尝试读取单元格范围时抛出异常。

Adding one more possible issue causing this: the formula was wrong because I was using the wrong list separator according to my locale.添加另一个可能导致此问题的问题:公式错误,因为我根据我的语言环境使用了错误的列表分隔符。 Using CultureInfo.CurrentCulture.TextInfo.ListSeparator;使用CultureInfo.CurrentCulture.TextInfo.ListSeparator; corrected the issue.更正了问题。

Note that the exception was thrown on the following line of code...请注意,在以下代码行中引发了异常...

This must be the world's most generic error message because I got it today on the following command using Excel Interop:这一定是世界上最通用的错误消息,因为我今天使用 Excel Interop 通过以下命令得到了它:

Excel.WorkbookConnection conn;
conn.ODBCConnection.Connection = "DSN=myserver;";

What fixed it was specifying ODBC in the connection string:修复它的是在连接字符串中指定 ODBC:

conn.ODBCConnection.Connection = "ODBC;DSN=myserver;";

On the off chance anyone else has this error, I hope it helps.如果其他人有这个错误,我希望它有所帮助。

调用此代码时出现此错误: wks.Range[startCell, endCell]其中startCell Range 和endCell Range 指向不同的工作表,然后指向变量wks

An additional cause for this error.此错误的另一个原因。 The code sample below returns the error when the datatable (dtTable) has a blank tablename:当数据表 (dtTable) 具有空白表名时,以下代码示例返回错误:

  ' Open Excel workbook
  objExcelApp = New Application
  objExcelWorkbook = objExcelApp.Workbooks.Add()
  objExcelSheet = objExcelWorkbook.ActiveSheet
  objExcelSheet.Name = dtTable.TableName

Still seeing this error in 2020. As was stated by stt106 above, there are many, many possible causes. 2020年还是看到这个错误。正如上面stt106所说的,有很多很多可能的原因。 In my case, it was during automated insertion of data into a worksheet, and a date had been incorrectly typed in as year 1019 instead of 2019. Since i was inserting using a data array, it was difficult to find the problem until I switched to row-by-row insertion.就我而言,是在自动将数据插入工作表的过程中,日期被错误地输入为 1019 年而不是 2019 年。由于我使用数据数组插入,因此在我切换到之前很难找到问题逐行插入。

This was my old code, which "hid" the problem data.这是我的旧代码,它“隐藏”了问题数据。

    Dim DataArray(MyDT.Rows.Count + 1, MyDT.Columns.Count + 1) As Object
    Try
        XL.Range(XL.Cells(2, 1), XL.Cells(MyDT.Rows.Count, MyDT.Columns.Count)).Value = DataArray
    Catch ex As Exception
        MsgBox("Fatal Error in F100 at 1270: " & ex.Message)
        End
    End Try

When inserting the same data by single rows at a time, it stopped with the same error but now it was easy to find the offending data.当一次按单行插入相同的数据时,它会因相同的错误而停止,但现在很容易找到有问题的数据。

I am adding this information so many years later, in case this helps someone else.多年后我将添加此信息,以防它对其他人有所帮助。

Issue that i have was on assigning the cell value..the value that i retrieved from DataTable columns has curly braces in it.我遇到的问题是分配单元格值。我从 DataTable 列中检索到的值中有花括号。 the i need to ensure the data retrieved using.ToString() method.this exception is thrown to me when the value is not appropriate.我需要确保使用.ToString() 方法检索到的数据。当值不合适时,会向我抛出此异常。 hope this helps:D希望这会有所帮助:D

I was getting the same error but it's sorted now.我遇到了同样的错误,但现在已经排序。 In my case, I had columns with the heading "Key1", "Key2", and "Key3".就我而言,我有标题为“Key1”、“Key2”和“Key3”的列。 I have changed the column names to something else and it's sorted.我已将列名称更改为其他名称并已排序。

It seems that these are reserved keywords.这些似乎是保留关键字。

Regards, Mahesh问候, 马赫什

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM