Click here to Skip to main content
15,891,951 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:
1. Loading Excel file in WebBrowser
C#
Uri _uri = new Uri("FilePath");
WebBrowserExcel.Navigate(_uri);

2. In Event WebBrowserExcel_LoadCompleted
C#
if ((WebBrowserExcel.Document as Excel.Workbook) == null) return;
   try
   {
      //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
C#
Excel.Application.DisplayAlerts = false;


3. Set property
C#
_Book.Application.GetType().InvokeMember("DisplayAlerts", BindingFlags.SetProperty, null, _Book.Application, new object[] { false });

and have Exception :
C#
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
Updated 8-Oct-12 23:27pm
v3

1 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