View Full Version : Spreadsheet cell protection with c#


texlnghorn
05-11-2006, 11:20 PM
I am trying to setup my Spreadsheet so that only certain cells are protected.
I can protect my entire active Spreadsheet by specifying:
axSpreadsheet1.ActiveSheet.Protection.Enabled = true;

Is there a way to set up a range of cells to protect? What I really want to
do is protect the first n columns as these correspond to display values only.
I then want to unprotect the remaining columns as these correspond to
editable values. I am using C# to program my OWC Spreadsheet application.

Thanks,
Mike

Alvin Bruney
05-12-2006, 12:34 AM
the range object contains a protect method that you can use to protect the
selected range

--

________________________
Warm regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
Professional VSTO.NET - Wrox/Wiley
The O.W.C. Black Book with .NET
www.lulu.com/owc, Amazon
Blog: http://www.msmvps.com/blogs/alvin
-------------------------------------------------------

"texlnghorn" <texlnghorn@discussions.microsoft.com> wrote in message
news:9AC09CCE-CD2C-4A98-A6B8-3684220073C7@microsoft.com...
>I am trying to setup my Spreadsheet so that only certain cells are
>protected.
> I can protect my entire active Spreadsheet by specifying:
> axSpreadsheet1.ActiveSheet.Protection.Enabled = true;
>
> Is there a way to set up a range of cells to protect? What I really want
> to
> do is protect the first n columns as these correspond to display values
> only.
> I then want to unprotect the remaining columns as these correspond to
> editable values. I am using C# to program my OWC Spreadsheet application.
>
> Thanks,
> Mike

texlnghorn
05-12-2006, 05:11 PM
Alvin,
Thanks for your reply. I'm looking at the Range object but I don't see a
Protect method. There is a Worksheet method that I can protect but it seems
to protect the entire worksheet and not the Range.

-Mike

"Alvin Bruney" wrote:

> the range object contains a protect method that you can use to protect the
> selected range
>
> --
>
> ________________________
> Warm regards,
> Alvin Bruney [MVP ASP.NET]
>
> [Shameless Author plug]
> Professional VSTO.NET - Wrox/Wiley
> The O.W.C. Black Book with .NET
> www.lulu.com/owc, Amazon
> Blog: http://www.msmvps.com/blogs/alvin
> -------------------------------------------------------

texlnghorn
05-12-2006, 09:46 PM
I figured out my problem. I first needed to unlock the range of cells I want
to make editable and then Protect the entire worksheet.

myrange.set_Locked(false);
sp.ActiveWorkSheet.Protection.Enabled = true;

Thanks,
Mike

"texlnghorn" wrote:

> Alvin,
> Thanks for your reply. I'm looking at the Range object but I don't see a
> Protect method. There is a Worksheet method that I can protect but it seems
> to protect the entire worksheet and not the Range.
>
> -Mike
>
> "Alvin Bruney" wrote:
>
> > the range object contains a protect method that you can use to protect the
> > selected range
> >
> > --
> >
> > ________________________
> > Warm regards,
> > Alvin Bruney [MVP ASP.NET]
> >
> > [Shameless Author plug]
> > Professional VSTO.NET - Wrox/Wiley
> > The O.W.C. Black Book with .NET
> > www.lulu.com/owc, Amazon
> > Blog: http://www.msmvps.com/blogs/alvin
> > -------------------------------------------------------