ComException HRESULT:尝试将验证添加到范围时引发0x800A03EC
本文关键字:范围 0x800A03EC 添加 验证 HRESULT ComException | 更新日期: 2023-09-27 17:57:06
尝试使用Range.Validation.Add()
方法时,我总是收到一个非常不友好的错误:
************** Exception Text **************
System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
at Microsoft.Office.Interop.Excel.Validation.Add(XlDVType Type, Object AlertStyle, Object Operator, Object Formula1, Object Formula2)
at TravelPlannerTools.Sheet8.OperaCodesDropDown() in C:'Users'Michael Utz'Documents'Visual Studio 2015'Projects'TravelPlannerTools'TravelPlannerTools'Sheet8.cs:line 39
at TravelPlannerTools.Sheet8.Sheet8_Startup(Object sender, EventArgs e) in C:'Users'Michael Utz'Documents'Visual Studio 2015'Projects'TravelPlannerTools'TravelPlannerTools'Sheet8.cs:line 27
at Microsoft.Office.Tools.Excel.WorksheetImpl.OnStartup()
at Microsoft.Office.Tools.Excel.WorksheetImpl.WorksheetExtensionImpl.Microsoft.Office.Tools.EntryPoint.OnStartup()
at Microsoft.Office.Tools.Excel.WorksheetBase.OnStartup()
at TravelPlannerTools.Sheet8.FinishInitialization() in C:'Users'Michael Utz'Documents'Visual Studio 2015'Projects'TravelPlannerTools'TravelPlannerTools'Sheet8.Designer.cs:line 50
at Microsoft.Office.Tools.Excel.WorksheetBase.Microsoft.Office.Tools.EntryPoint.FinishInitialization()
at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.ExecutePhase(ExecutionPhases executionPhases)
at Microsoft.VisualStudio.Tools.Office.Runtime.DomainCreator.ExecuteCustomization.Microsoft.VisualStudio.Tools.Office.Runtime.Interop.IExecuteCustomization2.ExecuteEntryPoints()
************** Loaded Assemblies **************
我正在使用正确版本的Excel并尝试执行一项非常简单的任务。
var list = new List<string>();
list.Add("Lann");
list.Add("Latl");
list.Add("LBBB");
var flatList = string.Join(",", list.ToArray());
var cell = Globals.Sheet8.Cells.Range["A2"];
cell.Validation.Delete();
cell.Validation.Add(
Excel.XlDVType.xlValidateList,
Excel.XlDVAlertStyle.xlValidAlertStop,
Excel.XlFormatConditionOperator.xlBetween,
flatList,
System.Type.Missing
);
cell.Validation.IgnoreBlank = true;
cell.Validation.InCellDropdown = true;
有什么想法吗?
我尝试写入的单元格位于受保护的工作表上。使用Worksheet.Protect()
和Worksheet.Unprotect()
方法在操作前后切换保护清除错误!