Results 1 to 2 of 2
  1. #1
    Join Date
    Oct 2002
    Posts
    48

    Unanswered: Protect Excel Sheet, after creating/opening it in .asp/javascript.

    Sorry, if I have placed myquestion at wrong place.

    Hi,

    I am generating Excel Report output using .asp.

    I am opening one existing .xls template. I am inserting data and picture in to cells. At last, I am using 'Saveas' other name.

    So, all content of .xls sheet will be stored under new .xls file name. Now, I am showing this new .xls filereport in another window of .asp.

    But this .xls file under browser is not protected. One can delete content or copy content(picture of signature).

    So, I want to do one of this things.
    1. Protect .xls sheet for delete/copy content of any cell in it.
    2. I want to stop 'Right click event' and 'certain menu option' in excel sheet opened in new Window.
    3. I want to open .xls in window in such a mode so, user can not copy any content from it.


    I have done following ton create .xls file report. I used VB script and JavaScript also.
    ------------
    Set ExcelApp = CreateObject("Excel.Application")
    ExcelApp.Application.Visible = True

    ' Close all pending books
    ExcelApp.Workbooks.Close

    'Open the template
    Set ExcelBook = ExcelApp.Workbooks.Open("C:\Inetpub\iissamples\te\ TE_Supplement_Template.XLS", , True)
    lsFullFileName = "C:\Inetpub\iissamples\te\TE_Supplement_Template2. XLS"

    Set oFS = CreateObject("Scripting.FileSystemObject")
    if (oFs.FileExists(lsFullFileName) = TRUE) then
    oFS.DeleteFile(lsFullFileName)
    End if

    ''''''assiging data stuff to cells.

    ExcelBook.SaveAs lsFullFileName

    ExcelApp.WorkBooks.Close

    ExcelApp.Application.Quit
    Set ExcelApp = Nothing
    ----------

    I have used following to open this file from Java script.

    ====
    window.open('c:/inetpub/iissamples/te/TE_supplement_template2.xls','CapitalExpenditure', 'menubar=yes,scrollbars=yes,resizable=yes,width=80 0,height=500')
    ====

    Thanks in advance.....

  2. #2
    Join Date
    Oct 2002
    Posts
    48

    Got Solution.

    I used following way.

    ExcelBook.Sheets(1).Protect DrawingObjects=False, Contents=False, Scenarios=False, Password="Chicago"

    and it works. My .xls sheet is protected. But, if I want to unprotect using 'chicago' password. It is not. But, I am okay as long as .xls sheet gets protected.

    So, my corrected code is as below in .asp.

    ------------
    Set ExcelApp = CreateObject("Excel.Application")
    ExcelApp.Application.Visible = True

    ' Close all pending books
    ExcelApp.Workbooks.Close

    'Open the template
    Set ExcelBook = ExcelApp.Workbooks.Open("C:\Inetpub\iissamples\te\ TE_Supplement_Template.XLS", , True)

    lsFullFileName = "C:\Inetpub\iissamples\te\TE_Supplement_Template2. XLS"

    Set oFS = CreateObject("Scripting.FileSystemObject")
    if (oFs.FileExists(lsFullFileName) = TRUE) then
    oFS.DeleteFile(lsFullFileName)
    End if

    ''''''assiging data stuff to cells.

    ExcelBook.Sheets(1).Protect DrawingObjects=False, Contents=False, Scenarios=False, Password="Chicago"

    ExcelBook.SaveAs lsFullFileName

    ExcelApp.WorkBooks.Close

    ExcelApp.Application.Quit
    Set ExcelApp = Nothing

    ------------

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •