Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
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");
2. In Event WebBrowserExcel_LoadCompleted
if ((WebBrowserExcel.Document as Excel.Workbook) == null) return;
      //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
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. Set property
_Book.Application.GetType().InvokeMember("DisplayAlerts", BindingFlags.SetProperty, null, _Book.Application, new object[] { false });
and have Exception :
InnerException = {"could Not set the property DisplayAlerts Application class"}
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...
Posted 9-Oct-12 0:09am
Edited 9-Oct-12 0:27am

1 solution

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

Solution 1


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

  Print Answers RSS
0 OriginalGriff 520
1 Maciej Los 205
2 Suvendu Shekhar Giri 159
3 Peter Leow 140
4 Kornfeld Eliyahu Peter 133
0 Sergey Alexandrovich Kryukov 9,623
1 OriginalGriff 8,895
2 Peter Leow 5,044
3 Kornfeld Eliyahu Peter 3,333
4 Maciej Los 2,561

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 11 Oct 2012
Copyright © CodeProject, 1999-2015
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