c# - 在 C# 中编辑 Microsoft Word。但是,会弹出一个 Word 窗口并且有人正在编辑它
问题描述
我正在尝试使用 Microsoft.Office.Interop.Word API 编辑一个 word 文件(序列:创建一个没有任何内容的 .docx 文件(流)=> 使用 API 编辑 => 保存)但是当程序运行时,会弹出一个 word 窗口起来,就会出现这个窗口。说“(用户)正在编辑并被锁定。” 我应该怎么办?(当我关闭word窗口或单击“只读”按钮时出现错误。(我有一个办公室帐户))
代码:
string NewFile = rootPath + filename;
if (!File.Exists(NewFile))
{
FileStream stream = File.Create(NewFile);
stream.Close();
}
object end_of_doc = "\\endofdoc";
Word.Application writing = new Word.Application();
object fileName = rootPath + filename;
Word.Document doc = writing.Documents.Open(ref fileName);
//.........(Lots of codes)
doc.SaveAs2(ref fileName);
解决方案
推荐阅读
- python - 使用 djangocms 发布页面更改时出现“NodeAlreadySaved”错误
- flutter - how to Make whole page scrollable instead to GridView Builder in flutter?
- html - CSS - Align Buttons in the same line
- openvino - OpenVino toolkit training repo and pre-trained models
- flutter - How to resolve SocketException,errorno=7 in flutter Using Alert or SnackBar
- python - regex works fine on the limited input but script hangs when whole input file is given
- java - How to run .bat file when deploying java spring boot project on tomcat?
- domain-driven-design - DDD:DTO 和参数对象
- android - 在后台启动前台摄像头录制服务
- jenkins - Jenkins 作业失败 java.lang.NullPointerException:无法在空对象上调用方法 getAt()