簡體   English   中英

如何使用c#刪除word文檔的readonly屬性?

[英]How can I remove the readonly attribute of a word document using c#?

我正在使用office 2013,我使用下面的代碼打開word文檔:

object fileName = FD.FileName;
object readOnly = false;
object isVisible = true;
WordApp.Visible = true;
aDoc = WordApp.Documents.Open(ref fileName, ref missing,
ref readOnly, ref missing, ref missing, ref missing,
ref missing, ref missing, ref missing, ref missing,
ref missing, ref isVisible, ref missing, ref missing,
ref missing, ref missing);
aDoc.Activate();

如何為在c#應用程序中打開的一些只讀單詞文件啟用編輯?

實際上它與Office-interop無關, ReadOnly是該文件的文件屬性 您可以通過它設置刪除此FileAttributeFileAttributes.Normal您打開文件之前。

您可以嘗試以下代碼:

string fileName = FD.FileName;
File.SetAttributes(fileName, FileAttributes.Normal);

aDoc = WordApp.Documents.Open(fileName, Visible: isVisible);
aDoc.Activate();

請記住,如果要在關閉文件后將其設置回ReadOnly ,請在調用aDoc.Close()后添加以下行:

File.SetAttributes(fileName, FileAttributes.ReadOnly);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM