Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to make a value in an excel cell read only using c#?

how to make a value in an excel cell read only using c#?

Scheduled Pinned Locked Moved C#
questioncsharpcomtutorial
6 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    abhiram_nayan
    wrote on last edited by
    #1

    hey ppl, am developing an excel com add-in using c# and displaying certain data over excel sheets. How can i make a cell or a range of cells or some arbitrary cells "read-only" using c# code?!

    D 1 Reply Last reply
    0
    • A abhiram_nayan

      hey ppl, am developing an excel com add-in using c# and displaying certain data over excel sheets. How can i make a cell or a range of cells or some arbitrary cells "read-only" using c# code?!

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      There is no "ReadOnly" attribute for cells or worksheets. You have to do this the exact same way you would if youwere to do it in Excel itself. Turn on the "Locked" property of the cell, then call the method to protect the worksheet to turn on all the protection. I don't the exact code or classes/methods to use since I don't normally do Office interop.

      A guide to posting questions on CodeProject[^]
      Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
           2006, 2007, 2008

      A 1 Reply Last reply
      0
      • D Dave Kreskowiak

        There is no "ReadOnly" attribute for cells or worksheets. You have to do this the exact same way you would if youwere to do it in Excel itself. Turn on the "Locked" property of the cell, then call the method to protect the worksheet to turn on all the protection. I don't the exact code or classes/methods to use since I don't normally do Office interop.

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

        A Offline
        A Offline
        abhiram_nayan
        wrote on last edited by
        #3

        Erm, i know this process, but was not finding a way to protect my active sheet. It would be gr8 to get the exact code to do so. Thanks.

        D 1 Reply Last reply
        0
        • A abhiram_nayan

          Erm, i know this process, but was not finding a way to protect my active sheet. It would be gr8 to get the exact code to do so. Thanks.

          D Offline
          D Offline
          Dave Kreskowiak
          wrote on last edited by
          #4

          A little Googling found this[^].

          A guide to posting questions on CodeProject[^]
          Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
               2006, 2007, 2008

          A 1 Reply Last reply
          0
          • D Dave Kreskowiak

            A little Googling found this[^].

            A guide to posting questions on CodeProject[^]
            Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                 2006, 2007, 2008

            A Offline
            A Offline
            abhiram_nayan
            wrote on last edited by
            #5

            I did try it before but, I want the remaining cells to remain unlocked!!where as this is protecting my entire sheet. I want for example, only my active cell to be made readonly. what has to be done then?

            D 1 Reply Last reply
            0
            • A abhiram_nayan

              I did try it before but, I want the remaining cells to remain unlocked!!where as this is protecting my entire sheet. I want for example, only my active cell to be made readonly. what has to be done then?

              D Offline
              D Offline
              Dave Kreskowiak
              wrote on last edited by
              #6

              All cells, by default, have Protection turned on. You have to specifically unprotect the cells you went to remain active when the sheet protection is turned on.

              A guide to posting questions on CodeProject[^]
              Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                   2006, 2007, 2008

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups