【问题标题】:Saving Word 2007 Document Properties in C# 2.0在 C# 2.0 中保存 Word 2007 文档属性
【发布时间】:2009-10-06 18:14:18
【问题描述】:

我正在尝试为 .docx 文档修改一些 CustomDocumentProperties。我已经能够读取当前值并对其进行修改,但是当我保存文档时,对自定义字段的更改会丢失。

我在 DocAccessor 类中有以下方法(用作我的 doc 文件的接口):

void SetInfo(string key, string val) {
    object custom_properties = current_doc.CustomDocumentProperties;
    Type custom_properties_type = custom_properties.GetType();
    custom_properties_type.InvokeMember("Item", BindingFlags.Default | BindingFlags.SetProperty, null, custom_properties, new object[] { key, val });
}

我在其他地方打电话:

doc_accessor.GetInfo("Number") //returns 5
doc_accessor.SetInfo("Number", "6");
doc_accessor.GetInfo("Number") //returns 6
doc_accessor.SaveAndClose();
doc_accessor.Open(); //it retains the path, so I don't need to respecify
doc_accessor.GetInfo("Number") //returns 5

我的 doc_accessor.SaveAndClose() 函数工作正常,因为我修改了保存到不同位置的路径并且确实如此......但没有编写修改后的 CustomDocumentProperties。这看起来好像我缺少某种提交步骤,但 current_doc.Save() 不应该处理它吗?

【问题讨论】:

    标签: c# .net properties ms-word


    【解决方案1】:

    http://support.microsoft.com/kb/195425

    http://msdn.microsoft.com/en-us/library/y1xatbkd(VS.80).aspx

    我不知道这些是否有帮助。 但这就是我要开始的地方。

    http://msdn.microsoft.com/en-us/library/microsoft.office.interop.word.documentclass.saved(office.11).aspx

    抱歉,我不得不删除协议标题的链接,因为堆栈认为我的答案中不应包含多个链接,因为我不是真正的成员

    【讨论】:

      【解决方案2】:

      我在 2 分钟前解决了同样的问题。

      当您添加/更改自定义属性时,文档似乎没有changed,所以WordApplication.ActiveDocument.Saved 仍然是true

      设置为false,然后调用Document的Save方法,就可以了!!

      【讨论】:

        猜你喜欢
        • 2011-06-15
        • 1970-01-01
        • 2011-02-07
        • 2011-12-24
        • 2010-11-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多