This is a migrated thread and some comments may be shown as answers.

[Solved] Protect column in ExportToExcel

2 Answers 120 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ram
Top achievements
Rank 1
Ram asked on 26 Jul 2013, 08:32 AM

Hi there

I am exporting a Grid in Biff Format which is successfully exporting - however I want to allow the user to be able to change values in one column only (e.g column 3)

If the user attempts to changes any other columns they would get a warning from Excel advising them the cell is protected.

I believe this can be done in the "ExcelMLWorkBookCreated" but am not sure what the code needs to be so it can loop through all the columns - below is what I have so far....

Any help much appreciated....

protected void gridPricing_ExportToExcel_ExcelMLWorkBookCreated(object sender, Telerik.Web.UI.GridExcelBuilder.GridExcelMLWorkBookCreatedEventArgs e)
       {
           e.WorkBook.Worksheets[0].IsProtected = true;
           StyleElement protectionStyle = new StyleElement("ProtectionStyle");
           protectionStyle.CellProtection.IsProtected = false;
           e.WorkBook.Styles.Add(protectionStyle);
             
           foreach (ColumnElement column in e.WorkBook.Worksheets[0].Table.Columns)
           {
               int columnindex = e.WorkBook.Worksheets[0].Table.Columns.IndexOf(column);
               if (columnindex == 3)
               {
                    
                   //code NEEDED in here needs to loop through cells or columns 
                   //and get cellelement or columnelement
                   // so I can set the cell.stylevalue for this column
               }
           }

2 Answers, 1 is accepted

Sort by
0
Ram
Top achievements
Rank 1
answered on 26 Jul 2013, 09:46 AM
no-one can help?
0
Kostadin
Telerik team
answered on 31 Jul 2013, 06:11 AM
Hello Ram,

I would recommend you to examine the last section of the following help article which demonstrates how to set cell protection.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Ram
Top achievements
Rank 1
Answers by
Ram
Top achievements
Rank 1
Kostadin
Telerik team
Share this question
or