HRESULT 异常:0x800A03EC 错误 [英] Exception from HRESULT: 0x800A03EC Error
问题描述
使用以下代码运行 Excel 加载项时出现HRESULT:0x800A03EC"错误:
I am getting "HRESULT: 0x800A03EC" error when running Excel add-in with following code:
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 范围.我广泛搜索并尝试了多种设置单元格值的方法(例如 Cells[x,y]、range.set_Value()),但不知道为什么会发生此错误以及如何避免它.
When error happens X and Y are set to 1, thus Excel range is not violated. 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.
非常感谢任何帮助.
以下是异常详情:
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:UsersdshevelevDocumentsVisual Studio 2012ProjectsImportValidationImportValidationThisAddIn.cs:line 354
at ImportValidation.ThisAddIn.ReadHeaders(Hashtable columnAddress) in c:UsersdshevelevDocumentsVisual Studio 2012ProjectsImportValidationImportValidationThisAddIn.cs:line 123
at ImportValidation.ThisAddIn.mapColumns() in c:UsersdshevelevDocumentsVisual Studio 2012ProjectsImportValidationImportValidationThisAddIn.cs:line 493
at ImportValidation.Ribbon1.button6_Click(Object sender, RibbonControlEventArgs e) in c:UsersdshevelevDocumentsVisual Studio 2012ProjectsImportValidationImportValidationRibbon1.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?
这篇关于HRESULT 异常:0x800A03EC 错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!