WebBrowser和Excel,取决于位置代码,发生异常... [英] WebBrowser and Excel, depending on location code, occurs Exceptions...

查看:96
本文介绍了WebBrowser和Excel,取决于位置代码,发生异常...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我正在将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...

推荐答案

它的包包
http://support.microsoft.com/kb/165435/en [
it''s bag
http://support.microsoft.com/kb/165435/en[^]


也许会有所帮助吗? 解决方案
Maybe it will help? Solution


这篇关于WebBrowser和Excel,取决于位置代码,发生异常...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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