Click here to Skip to main content
15,891,895 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:
C#
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 });


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())
C#
private void btn_ViewExcel_Click(object sender, RoutedEventArgs e)
{
       Window1 _W1 = new Window1();
       _W1.ShowDialog();
 }

- works badly:
C#
InnerException = {"could Not set the property DisplayAlerts Application class"}


Because of what it can be?
Thanks in advance, Alex...
Posted
Updated 10-Oct-12 0:40am
v2

 
Share this answer
 
Maybe it will help? Solution
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900