问题描述
大家好
我正在将VS2008,C#和WPF应用程序(WebBrowser和Microsoft.Office.Interop.Excel)一起使用
我有一个任务:以只读模式在WPF表单上托管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:
if ((WebBrowserExcel.Document as Excel.Workbook) == null) return;
try
{
_Book = WebBrowserExcel.Document as Excel.Workbook;
_Book.Protect("", Type.Missing, Type.Missing);
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
);
}
//In this moment - Exception
_Book.Application.GetType().InvokeMember("DisplayAlerts", BindingFlags.SetProperty, null, _Book.Application, new object[] { false });
如果我将所有代码都放在Project的启动窗口(StartUpWindow)中,则效果很好,但是如果我将所有代码都放在另一个窗口(Window1)中,并从启动窗口显示该窗口(Window1.Show())
If I place all code in the Startup Windows (StartUpWindow) of Project - works well, but if I place all code in the other window (Window1) and show this window from Startup (Window1.Show())
private void btn_ViewExcel_Click(object sender, RoutedEventArgs e)
{
Window1 _W1 = new Window1();
_W1.ShowDialog();
}
-效果很差:
- works badly:
InnerException = {"could Not set the property DisplayAlerts Application class"}
因为它可能是什么?
预先感谢Alex ...
Because of what it can be?
Thanks in advance, Alex...
推荐答案
这篇关于WebBrowser和Excel,取决于位置代码,发生异常...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!