使用以下代码运行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);
当错误发生时,X和Y设置为1,因此不会违反Excel范围。我进行了广泛的搜索,并尝试了许多设置单元格值的方法(例如。Cellsx,y,range.set_Value(),但是我不知道为什么会发生这个错误,以及如何避免它。
任何帮助都是非常感谢的。
以下是例外细节:
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:
发布于 2013-01-16 17:54:27
在这一行中有相同的错误
Object temp = range.Cells[i][0].Value;
用非零基索引求解
Object temp = range.Cells[i][1].Value;
创建这个库的人怎么可能认为使用非零基础索引是个好主意呢?
发布于 2012-10-15 10:29:07
这是一个常见但文档贫乏的Excel错误。我看到它被记录为"NAME_NOT_FOUND",这意味着Excel的COM层是禁用的,无法找到COM属性或方法名。
在Excel“忙”时运行COM代码时,我会一致地看到这个错误,例如,如果您设置了一个启动代码的计时器,并且当用户正在编辑一个单元格或按下他们的鼠标按钮时,代码就会开始运行,那么您将始终得到这个错误。此错误仅在代码在主Excel线程上运行时发生,但似乎相当于错误VBA_E_IGNORE = 0x800AC472,这是在从另一个线程调用Excel对象模型时得到的,而Excel是“繁忙”的。
唯一的解决办法似乎是重新尝试(稍微延迟一些) COM调用,直到它成功--当Excel不再“繁忙”时。
发布于 2012-10-15 10:12:24
检查您的开始索引。对于Microsoft.Office.Interop.Excel范围对象,它从1开始,而不是从0开始。由于循环开始值,我收到了相同的错误。
https://stackoverflow.com/questions/12714626
复制相似问题