Set custom document properties with Word interop

前端 未结 4 1306
春和景丽
春和景丽 2020-12-10 17:01

I want to set some custom document properties of a word document I\'m creating in my C# code. To do this, I followed this MSDN article and came up with this code:



        
4条回答
  •  悲哀的现实
    2020-12-10 17:39

    After asking the question in the MSDN forums, the answer was brought up. The problem is, that the way I tried was specific to VSTO. Due to my unknowing, I mixed up VSTO, Interop and other definitions, thus tagging this question wrong.

    It now works using the following code:

    logger.Info("Setting document properties");
    object properties = doc.CustomDocumentProperties;
    Type propertiesType = properties.GetType();
    
    object[] documentCodeProperty = { "Codice_documento", false, Core.MsoDocProperties.msoPropertyTypeString, args[3] };
    object[] documentVersionPoperty = { "Versione_documento", false, Core.MsoDocProperties.msoPropertyTypeString, args[4] };
    
    propertiesType.InvokeMember("Add", BindingFlags.InvokeMethod, null, properties, documentCodeProperty);
    propertiesType.InvokeMember("Add", BindingFlags.InvokeMethod, null, properties, documentVersionPoperty);
    

提交回复
热议问题