c# - 由于某种原因,C# Word Interop 无法更改文档属性中内置的“创建日期”
问题描述
我使用的代码:
string fullPath = null;
DateTime creationDate = new DateTime();
string creatorName = null;
foreach (var arg in args) {
if (arg.Contains("--path")) {
fullPath = arg.Substring(7);
}
if (arg.Contains("--creationDate")) {
creationDate = DateTime.Parse(arg.Substring(15));
}
if (arg.Contains("--creatorName")) {
creatorName = arg.Substring(14);
}
}
var wordInterop = new Microsoft.Office.Interop.Word.Application();
var wordWorkBook = wordInterop.Documents.Open(fullPath);
wordWorkBook.BuiltInDocumentProperties["Creation Date"].Value = creationDate;
wordWorkBook.BuiltInDocumentProperties["Author"].Value = creatorName;
wordWorkBook.Save();
wordInterop.Quit();
Marshal.ReleaseComObject(wordWorkBook);
Marshal.ReleaseComObject(wordInterop);
File.SetCreationTime(fullPath, creationDate);
每当我打印出创建日期时,它都保持不变。设置作者属性有效。
我尝试用这种方法欺骗 Excel,它有效。
解决方案
推荐阅读
- android - 如何检测android上的屏幕亮度范围?
- javascript - node.js:如何将多个变量传递到视图中?
- libcurl - 如何使用 libcurl 实现 http 流式传输
- python - 函数 plt.show() 在 Spyder 中不起作用
- javascript - 文件加载弹出与功能一起出现,输入被隐藏
- centos - PHP 7.2 没有从易受攻击的 7.2.10 更新?
- python - 为什么我会收到“您的 SQL 语法有错误;” 尝试使用 pymysql 运行“状态”后出错?
- mongodb - 为什么mongo在这种情况下选择这个索引?
- ios - 将我的应用程序与社交媒体深度链接在 iOS 上是否仍然有效?
- node.js - 在 Windows 上指定 PORT 环境变量