小编典典

HRESULT异常:0x800A03EC错误

c#

使用以下代码运行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范围。我进行了广泛的搜索,并尝试了多种设置单元格值的方法(例如,Cells
[x,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:

阅读 532

收藏
2020-05-19

共1个答案

小编典典

在这一行中得到了相同的错误

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

解决了基于非零的索引

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

创建此库的人怎么可能认为使用基于非零的索引是一个好主意?

2020-05-19