日期:2014-05-17  浏览次数:20858 次

C#生成word文件的时候,如何自动附加只读功能?
项目需要生成债券的缴款通知书,word格式的,但为了防止意外修改,要求做成只读的,也就是无法编辑和复制。
在界面操作,是“审阅”--》“保护文档”中设置限制编辑,但在Microsoft.Office.Interop.Word中貌似不能实现

------解决方案--------------------
word貌似有方法可以把上面的保存,另存和导出等菜单给隐藏了
依稀记得office2007以后,具体没做过,你可以搜搜

------解决方案--------------------
using Word = Microsoft.Office.Interop.Word;

var app = new Word.Application();
var doc = app.Documents.Open("d:/test.docx");
app.ActiveDocument.Protect(Word.WdProtectionType.wdAllowOnlyReading, Password: "xxxx");

------解决方案--------------------
引用:
using Word = Microsoft.Office.Interop.Word;

var app = new Word.Application();
var doc = app.Documents.Open("d:/test.docx");
app.ActiveDocument.Protect(Word.WdProtectionType.wdAllowOnlyReading, Password: "xxxx");
不错。。
------解决方案--------------------
System.IO.FileInfo fi = new System.IO.FileInfo("c:/d.doc");
        fi.Attributes = System.IO.FileAttributes.ReadOnly;

设置只读属性