如何使用只读保护打开Excel文件? [英] How to open Excel file with Read Only protection?

查看:171
本文介绍了如何使用只读保护打开Excel文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在我的C#WinForm应用程序中打开Excel文件,添加对 Microsoft.Office.Interop.Excel.dll 的引用,并使用DSO FRAMER CONTROL。但是我想用只读保护打开我的excel文件。我已经成功地为这样的WORD应用程序这样做了

  Word.Document wordDoc =(Word.Document)axFramerControl1.ActiveDocument; 
Word.Application wordApp = wordDoc.Application;
wordDoc.Protect(Word.WdProtectionType.wdAllowOnlyReading);

同样,我想为Excel做这项工作。但是我无法保护Excel文件。

  string path =C:\\test-wb.xlsx; 
axFramerControl1.Open(path,true,excel.sheet,,);

Excel._Workbook excelDoc =(Microsoft.Office.Interop.Excel._Workbook)axFramerControl1.ActiveDocument;
Excel.Application excelApp = excelDoc.Application;
//我应该写什么代码来保护Excel工作簿只读。
excelDoc.Protect(misval,true,misval); //它不工作。


解决方案

调用 code>方法与第三个参数( ReadOnly )= true



请参阅MSDN 文档



ReadOnly

可选对象。确实以只读模式打开工作簿。


I have opened Excel file in my C# WinForm Application adding reference to Microsoft.Office.Interop.Excel.dll and using DSO FRAMER CONTROL. But i want to open my excel file with read only protection.I have successfully done this for WORD Application like this

Word.Document wordDoc = (Word.Document)axFramerControl1.ActiveDocument;
Word.Application wordApp = wordDoc.Application;
wordDoc.Protect(Word.WdProtectionType.wdAllowOnlyReading);

In the same i want to do this work for Excel.But i couldn't able to protect Excel file on that way.

string path = "C:\\test-wb.xlsx";
axFramerControl1.Open(path, true,"excel.sheet", "", "");

Excel._Workbook excelDoc   =(Microsoft.Office.Interop.Excel._Workbook)axFramerControl1.ActiveDocument;
Excel.Application excelApp =excelDoc.Application;
//What code should i write to protect Excel Workbook with read - only.
excelDoc.Protect(misval, true, misval);//It is not working.

解决方案

Call theOpen method with third parameter (ReadOnly) = true.

See MSDN documentation :

ReadOnly
Optional Object. True to open the workbook in read-only mode.

这篇关于如何使用只读保护打开Excel文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆