Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WPF Excel webbrowser
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 });
 
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"}
 
Because of what it can be?
Thanks in advance, Alex...
Posted 10-Oct-12 1:34am
Edited 10-Oct-12 1:40am
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Maybe it will help? Solution
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 290
1 Jochen Arndt 150
2 Kornfeld Eliyahu Peter 149
3 PIEBALDconsult 110
4 Richard MacCutchan 105
0 OriginalGriff 6,080
1 DamithSL 4,648
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,624
4 Sergey Alexandrovich Kryukov 3,294


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100