【发布时间】: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