locked
Protect cells range in an Excel file from a web application RRS feed

  • Question

  • User1011991496 posted

    Hi everybody !!!

    I want to open an excel file from a web application only to protect some cells range.  I always began developing all my web apps creating first an empty solution and then I add an existing blank web site to it, and this was no the exception.

    My development environment has Windows Server 2003 R2, Visual Studio 2005 Proffesional Edition (C#), ASP.NET 2.0.

    I began trying to open the file with the following code (before trying to run this code I installed VSTO 2005 SE and MS Office 2007):

    Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
    
    ExcelApp.Visible = true;
    
    ExcelApp.UserControl = true;
    
    System.Globalization.CultureInfo oldCI = System.Threading.Thread.CurrentThread.CurrentCulture;
    
    System.Threading.Thread.CurrentThread.CurrentCulture = new System.Globalization.CultureInfo("en-US");
    
    ExcelApp.Workbooks.Open(@"c:\FileExported.xls", 2, false, 5, Type.Missing, Type.Missing, true, XlPlatform.xlWindows, Type.Missing, false, false, Type.Missing, false, false, XlCorruptLoad.xlNormalLoad);
    
    System.Threading.Thread.CurrentThread.CurrentCulture = oldCI;
    


    The first time the web application runs without doing nothing (dont open Excel application) and in later executions I have to stop them because I dont receive response from the server. I have not been able to continue writing code to protect cells. Any suggestions???


    As an additional requeriment, after protecting the cells range and whenever requested, this excel file must be shown to the user.

    Any suggestions???


    I really appreciate your help and support.

    Thanks a lot in advance.

    Regards.

    Friday, September 11, 2009 8:49 PM

All replies

  • User121973971 posted

     I haven't tried this with the Primary Interop Assemblies, but with the COM API I've used:

    Workbook = GetObject([your excel file name])

    Try it from a regular Windows form before doing it from a web page.  If it works from a Windows form and then it doesn't work from a web page then it probably comes down to either permissions or concurrency (or both).

    When it's time to return the file to the user, set the attributes in the response header.  For returning an MS Word document to the user from a Java servlet, it's something like this:

    response.setHeader("Content-Disposition","attachment;filename=\"MyWordDoc.doc\"");
    response.setHeader("Cache-Control", "no-store");
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setContentType("application/octet-stream");
    response.setContentLength(myfilelength);

     

    Hope this helps.

    Monday, September 14, 2009 1:59 PM