c# - "Value does not fall within the expected range," when writing to Workbook.CustomDocumentProperties -


a simple assignment 1 below console application written in c#:

workbook.customdocumentproperties.item["propertyname"] = "property value"; 

produces following error:

{"value not fall within expected range."}     data: {system.collections.listdictionaryinternal}     hresult: -2147024809     helplink: null     ipforwatsonbuckets: 0x633f1015     innerexception: null     istransient: false     message: "value not fall within expected range."     paramname: null     remotestacktrace: null     source: "system.dynamic"     stacktrace: "   @ system.dynamic.comruntimehelpers.checkthrowexception(int32 hresult, excepinfo& excepinfo, uint32 argerr, string message)\r\n   @ callsite.target(closure , callsite , object , string , object )\r\n   @ system.dynamic.updatedelegates.updateandexecute3[t0,t1,t2,tret](callsite site, t0 arg0, t1 arg1, t2 arg2)\r\n   @ 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 not fall within 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 

i first tried calling add method on customdocumentproperties property so:

workbook.customdocumentproperties.add("propertyname", "property value"); 

when failed, reviewed the documentation, remarks follows (emphasis mine):

this property returns entire collection of custom document properties. use microsoft.office.core.documentproperties.item(system.object) property return single member of collection (a microsoft.office.core.documentproperties object) by specifying either name of property or collection index (as number).

in word (and presumably in excel), if property not exist, can set customdocumentproperties.add method. however, need sure pass type parameter, in case msodocproperties.msopropertytypestring.

hope helps.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -