We're sorry Aspose doesn't work properply without JavaScript enabled.

Free Support Forum - aspose.com

How to disable add row and column to work sheet

How to disable add row and column to work sheet ,when i tried below code it disable the add and delete property but it also make sheet as non-editable ,i want user can edit the content in sheet but he should not all to add or delete any row or any column to sheet.

static void Main(string[] args)
{
string root = @“D:\New folder”;
System.IO.DirectoryInfo di = new DirectoryInfo(root);
if (Directory.Exists(root))
{
foreach (FileInfo file in di.GetFiles())
{
file.Delete();
}
// Directory.Delete(root);
}

        Workbook excelbook = new Workbook();
        excelbook.Worksheets[0].IsGridlinesVisible = false;
        // Restricting users to edit contents of the worksheet
        excelbook.Worksheets[0].Protection.AllowEditingContent = false;
        // Restricting users to edit objects of the worksheet
        excelbook.Worksheets[0].Protection.AllowEditingObject = false;
        // Restricting users to edit scenarios of the worksheet
        excelbook.Worksheets[0].Protection.AllowEditingScenario = false;
        excelbook.Worksheets[0].Protection.AllowDeletingRow = false;
        excelbook.Worksheets[0].Protection.AllowDeletingColumn = false;
        excelbook.Worksheets[0].Protection.AllowInsertingColumn = false;
        excelbook.Worksheets[0].Protection.AllowInsertingRow = false;
        // Worksheet objtempworksheet = null;
        int row = 1;
        for (int ques = 1; ques <= 2; ques++)
        {

            //}
            int column = 1;
            Aspose.Cells.Drawing.GroupBox box = excelbook.Worksheets[0].Shapes.AddGroupBox(row, 0, column, 0, 50, 250);

            box.Name = "Example";
            //box.HasLine.
            box.IsHidden = false;
            int j = 1;


            List<Aspose.Cells.Drawing.RadioButton> listradio = new List<Aspose.Cells.Drawing.RadioButton>();
            for (int i = 1; i <= 3; i++)
            {
                listradio.Add(excelbook.Worksheets[0].Shapes.AddRadioButton(row, 0, column, 0, 30, 110));
                column++;
            }
            row++; row++; row++; row++;


            Aspose.Cells.Drawing.Shape[] shapeobjects = new Aspose.Cells.Drawing.Shape[4];
            shapeobjects[0] = box;
            //int i = 1;
            foreach (Aspose.Cells.Drawing.RadioButton item in listradio)
            {
                shapeobjects[j] = item;
                j++;
            }
            Aspose.Cells.Drawing.GroupShape group = excelbook.Worksheets[0].Shapes.Group(shapeobjects);
        }
        excelbook.Save("D:\\New folder\\" + "book1.xls");
        // The code provided will print ‘Hello World’ to the console.
        // Press Ctrl+F5 (or go to Debug > Start Without Debugging) to run your app.
        //string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        //string root = @"D:\New folder";
        // System.IO.DirectoryInfo di = new DirectoryInfo(root);
        //if (Directory.Exists(root))
        //{
        //    foreach (FileInfo file in di.GetFiles())
        //    {
        //        file.Delete();
        //    }
        //   // Directory.Delete(root);
        //}

        //Workbook excelbook = new Workbook();
        //excelbook.Worksheets[0].IsGridlinesVisible = false;
        //excelbook.Worksheets[0].Protection.AllowDeletingRow = false;
        //excelbook.Worksheets[0].Protection.AllowDeletingColumn = false;
        //excelbook.Worksheets[0].Protection.AllowInsertingColumn = false;
        //excelbook.Worksheets[0].Protection.AllowInsertingRow = false;
        //// Worksheet objtempworksheet = null;
        //int row = 1;
        //for (int ques = 1; ques <= 2; ques++)
        //{

        //    //}

        //        Aspose.Cells.Drawing.GroupBox box = excelbook.Worksheets[0].Shapes.AddGroupBox(row, 0, 1, 0, 100, 250);

        //    box.Name = "Example";
        //    //box.HasLine.
        //    int j = 1;

        //    List<RadioButton> listradio = new List<RadioButton>();
        //    for (int i = 1; i <= 3; i++)
        //    {
        //        listradio.Add(excelbook.Worksheets[0].Shapes.AddRadioButton(row, 0, 1, 0, 30, 110));
        //        row++;
        //    }
        //    row++;row++; row++; row++;


        //    Aspose.Cells.Drawing.Shape[] shapeobjects = new Aspose.Cells.Drawing.Shape[4];
        //    shapeobjects[0] = box;
        //    //int i = 1;
        //    foreach (RadioButton item in listradio)
        //    {
        //        shapeobjects[j] = item;
        //        j++;
        //    }
        //    Aspose.Cells.Drawing.GroupShape group = excelbook.Worksheets[0].Shapes.Group(shapeobjects);
        //}
        //excelbook.Save("D:\\New folder\\" + "book1.xls");

        // Go to http://aka.ms/dotnet-get-started-console to continue learning how to build a console app! 
    }

@kiranmurkal,

Thanks for sample code segment and details.

How could you accomplish the task in MS Excel?. I am afraid restricting users to add/insert or delete rows/cols attributes will be only possible when you protect the sheet precisely. For example, these three lines are equally important for protecting a sheet:

// Restricting users to edit contents of the worksheet
excelbook.Worksheets[0].Protection.AllowEditingContent = false;
// Restricting users to edit objects of the worksheet
excelbook.Worksheets[0].Protection.AllowEditingObject = false;
// Restricting users to edit scenarios of the worksheet
excelbook.Worksheets[0].Protection.AllowEditingScenario = false;

If you still have any issue or confusion, kindly provide your expected file (you may protect the sheet in MS Excel or set your desired options) where users’ could not insert or delete rows or columns but the sheet should be editable, we will check it on how to do it via Aspose.Cells APIs.