Une mission simple comme celui ci-dessous à partir d'une application console écrite en C#:« La valeur ne tombe pas dans la plage attendue, » lors de l'écriture à Workbook.CustomDocumentProperties
workbook.CustomDocumentProperties.Item["PropertyName"] = "Property Value";
produit l'erreur suivante:
{"Value does not fall within the expected range."}
Data: {System.Collections.ListDictionaryInternal}
HResult: -2147024809
HelpLink: null
IPForWatsonBuckets: 0x633f1015
InnerException: null
IsTransient: false
Message: "Value does not fall within the expected range."
ParamName: null
RemoteStackTrace: null
Source: "System.Dynamic"
StackTrace: " at System.Dynamic.ComRuntimeHelpers.CheckThrowException(Int32 hresult, ExcepInfo& excepInfo, UInt32 argErr, String message)\r\n at CallSite.Target(Closure , CallSite , Object , String , Object)\r\n at System.Dynamic.UpdateDelegates.UpdateAndExecute3[T0,T1,T2,TRet](CallSite site, T0 arg0, T1 arg1, T2 arg2)\r\n at CustomDocumentProperties.Program.WriteToExcelCustomDocumentProperties(String excelFile, String outputFolder, String propertyName, Object propertyValue) in C:\\Sathyaish\\DotNet\\CustomDocumentProperties\\CustomDocumentProperties\\Program.cs:line 100"
TargetSite: {Void CheckThrowException(Int32, System.Dynamic.ExcepInfo ByRef, UInt32, System.String)}
WatsonBuckets: null
_HResult: -2147024809
_className: null
_data: {System.Collections.ListDictionaryInternal}
_dynamicMethods: {object[2]}
_exceptionMethod: {Void CheckThrowException(Int32, System.Dynamic.ExcepInfo ByRef, UInt32, System.String)}
_exceptionMethodString: null
_helpURL: null
_innerException: null
_ipForWatsonBuckets: 0x633f1015
_message: "Value does not fall within the expected range."
_remoteStackIndex: 0
_remoteStackTraceString: null
_safeSerializationManager: {System.Runtime.Serialization.SafeSerializationManager}
_source: "System.Dynamic"
_stackTrace: {sbyte[96]}
_stackTraceString: null
_watsonBuckets: null
_xcode: -532462766
_xptrs: 0x00000000
m_paramName: null
J'ai d'abord essayé d'appeler la méthode Add
sur la propriété CustomDocumentProperties
comme ceci:
workbook.CustomDocumentProperties.Add("PropertyName", "Property Value");
Quand cela a échoué, j'ai examiné the documentation, qui remarque comme suit (Souligné par l'auteur):
This property returns the entire collection of custom document properties. Use the Microsoft.Office.Core.DocumentProperties.Item(System.Object) property to return a single member of the collection (a Microsoft.Office.Core.DocumentProperties object) by specifying either the name of the property or the collection index (as a number).
En réalité, avez-vous littéralement utilisé '" PropertyName "' comme nom de la propriété? – oerkelens
Non et oui. Le code ci-dessus est un espace réservé. Lorsque j'ai essayé avec mes valeurs réelles et que cela n'a pas fonctionné, j'ai essayé avec '' 'PropertyName '' comme nom de propriété. Pourquoi? –