none
lock cells in excel & add checkbox from web application

    Question

  • in my web application i need to export data to excel from datatable in a particular format

    this has been done
    i need to lock some cells range to prevent editing in excel sheet 
    i tried  but it doesnot get locked
    ExcApp = New Excel.Application
    ExcWS = ExcApp.Worksheets("SHEET1")
    ExcWS.Range("A1", "C3").Locked = True
     ExcWS.Protect(False, False, False, False, False, False, False, False, False, False, False, False, False, False, False, False)

    i have above

    2) i need to display checkbox against each supplier no displayed in the sheet
    & when few of the suppliers are checked , need to import the checked data in the database

    svk

    Saturday, June 15, 2013 3:59 PM

Answers

  • Hello,

    1. The cells are not protected because you set every parameter of Worksheet.Protect to False.

    Please have a look at this document:

    Worksheet.Protect Method (Excel)

    The third parameter "Contents" indicates whether to protect the locked cells. The default value is True. If it is set to False, the locked cells won't be protected.

    Furthermore, the default value of Locked property is True, you don't need to set it unless you have ever modified it to False. If you want to protect some certain cells, you need to unlock all cells and lock these certain cells:

    'Protect A1 A2 and A3
    
    ExcWS.Cells.Locked = False
    ExcWS.Range("A1:A3").Locked = True
    ExcWS.Protect("111")

    2. What do you mean by the "supplier" of check box? Form check box or ActiveX check box?

    Thanks,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 19, 2013 1:46 PM
    Moderator

All replies

  • Hello,

    1. The cells are not protected because you set every parameter of Worksheet.Protect to False.

    Please have a look at this document:

    Worksheet.Protect Method (Excel)

    The third parameter "Contents" indicates whether to protect the locked cells. The default value is True. If it is set to False, the locked cells won't be protected.

    Furthermore, the default value of Locked property is True, you don't need to set it unless you have ever modified it to False. If you want to protect some certain cells, you need to unlock all cells and lock these certain cells:

    'Protect A1 A2 and A3
    
    ExcWS.Cells.Locked = False
    ExcWS.Range("A1:A3").Locked = True
    ExcWS.Protect("111")

    2. What do you mean by the "supplier" of check box? Form check box or ActiveX check box?

    Thanks,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, June 19, 2013 1:46 PM
    Moderator
  • Hi SRekha,

    Since you haven't responded for a few days, I temporarily mark my reply as answer because I think my suggestion works for your issue. If you disagree with it, please unmark it and post your doubt. Thanks for your understanding.

    Regards,


    Damon Zheng
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Sunday, June 23, 2013 12:08 PM
    Moderator