예제 #1
0
        static void CopyCustomDocumentProperties(Wd.Document target, Wd.Document source)
        {
            //dynamic source_props = source.CustomDocumentProperties;
            //dynamic target_props = target.CustomDocumentProperties;
            //foreach (dynamic prop in source_props)
            //    target_props.Add(prop.Name, prop.LinkToContent, prop.Type, prop.Value, prop.LinkSource);

            object source_props = source.GetType().InvokeMember("CustomDocumentProperties", BindingFlags.Default | BindingFlags.GetProperty, null, source, null);
            object target_props = target.GetType().InvokeMember("CustomDocumentProperties", BindingFlags.Default | BindingFlags.GetProperty, null, target, null);
            Type soure_typeProps = source_props.GetType();
            Type target_typeProps = target_props.GetType();
            int count = (int)soure_typeProps.InvokeMember("Count", BindingFlags.Default | BindingFlags.GetProperty, null, source_props, new object[] { });

            for (int i = 1; i <= count; i++)
            {
                object prop = soure_typeProps.InvokeMember("Item", BindingFlags.Default | BindingFlags.GetProperty, null, source_props, new object[] { i });
                Type typeProp = prop.GetType();
                var name = typeProp.InvokeMember("Name", BindingFlags.Default | BindingFlags.GetProperty, null, prop, new object[] { }).ToString();
                var value = typeProp.InvokeMember("Value", BindingFlags.Default | BindingFlags.GetProperty, null, prop, new object[] { }).ToString();

                object[] oArgs = { name, false, O.MsoDocProperties.msoPropertyTypeString, value };
                target_typeProps.InvokeMember("Add", BindingFlags.Default | BindingFlags.InvokeMethod, null, target_props, oArgs);
            }
        }