我想使用 Python 和 Excel 对象模型库将验证代码添加到 Excel 工作簿中的单元格。我的代码如下:
valid = config.optionsSheet.Range('A2').Validation
valid.Delete()
valid.Add(XlDVType.xlValidateList, XlDVAlertStyle.xlValidAlertStop, \
XlFormatConditionOperator.xlBetween, "=R20C4:R21C4", None)
上面的最后一行失败并出现以下错误:感谢任何帮助。
EnvironmentError: System.Runtime.InteropServices.COMException (0x800A03EC): Exception from HRESULT: 0x800A03EC
Server stack trace:
at Microsoft.Scripting.ComInterop.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)
at CallSite.Target(Closure , CallSite , Object , Object , Object , Object , String , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute6[T0,T1,T2,T3,T4,T5,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5)
at CallSite.Target(Closure , CallSite , CodeContext , Object , Object , Object , Object , String , Object )
at System.Dynamic.UpdateDelegates.UpdateAndExecute7[T0,T1,T2,T3,T4,T5,T6,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2, T3 arg3, T4 arg4, T5 arg5, T6 arg6)
at Microsoft.Scripting.Interpreter.DynamicInstruction`8.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.Interpreter.Run(InterpretedFrame frame)
at Microsoft.Scripting.Interpreter.LightLambda.Run2[T0,T1,TRet](T0 arg0, T1 arg1)