WebBrowser,如何以只读模式打开Excel的文件? [英] WebBrowser, how to open Excel's file in mode readonly?
问题描述
大家好,
我正在将VS2008,C#和WPF应用程序(WebBrowser和Microsoft.Office.Interop.Excel)一起使用
我有一个任务:以只读模式在WPF表单上托管Excel.
我该怎么做:
1.在WebBrowser中加载Excel文件
Hi All,
I am using VS2008, C#, with WPF application (WebBrowser and Microsoft.Office.Interop.Excel)
I have a task : Hosting Excel on WPF-form in mode readonly.
How can i do this:
1. Loading Excel file in WebBrowser
Uri _uri = new Uri("FilePath");
WebBrowserExcel.Navigate(_uri);
2.在事件中WebBrowserExcel_LoadCompleted
2. In Event WebBrowserExcel_LoadCompleted
if ((WebBrowserExcel.Document as Excel.Workbook) == null) return;
try
{
//Get loading WorkBook and set "Protect" for disable editing
_Book = WebBrowserExcel.Document as Excel.Workbook;
_Book.Protect("", Type.Missing, Type.Missing);
//Set "Protect" for disable editing to WorkSheet
foreach (Excel.Worksheet _sheet in _Book.Sheets)
{
_sheet.Protect("", Type.Missing,Type.Missing,
Type.Missing,Type.Missing, true,Type.Missing,
Type.Missing, Type.Missing, Type.Missing,
Type.Missing, Type.Missing,Type.Missing,
Type.Missing, Type.Missing, Type.Missing
);
}
}
.....
之后,当我尝试在WebBrowser中编辑文件时,我有一个Excel的MessageBox. MessageBox的文本:
此书受保护...等"或此工作表受保护...等"
要隐藏此消息框,我需要设置属性
After this I have an Excel''s MessageBox, when I try to edit file in WebBrowser. MessageBox''s text:
"This Book is Protected...etc" or "This Sheet is Protected...etc"
To hide this messagebox i need to set the property
Excel.Application.DisplayAlerts = false;
3.设置属性
3. Set property
_Book.Application.GetType().InvokeMember("DisplayAlerts", BindingFlags.SetProperty, null, _Book.Application, new object[] { false });
并具有Exception:
and have Exception :
InnerException = {"could Not set the property DisplayAlerts Application class"}
但是,如果创建应用程序(不是从WebBrowserExcel.Document获取),则可以设置DisplayAlerts,但不能将Excel.Application托管到WebBrowser中,只有Excel的文件...
有没有办法将Web浏览器中的Excel文件设置为只读?或如何设置"DisplayAlerts"?
预先感谢Alex ...
but if create Application (not get from WebBrowserExcel.Document) I can set DisplayAlerts, but I can''t hosting Excel.Application into WebBrowser, only Excel''s file...
Are there ways to set Excel''s file readonly inside WebBrowser? or how to set ''DisplayAlerts''?
Thanks in advance, Alex...
推荐答案
这是一个袋子
http://support.microsoft.com/kb/165435/en [
It''s a Bag
http://support.microsoft.com/kb/165435/en[^]
这篇关于WebBrowser,如何以只读模式打开Excel的文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!