Disable copy and paste



I was wondering if there was a way to disable a user from copying and pasting within a column only? I can't seem to find a way for the user to edit the field manually, but disable them from copy and paste. Thanks for your help.



Thanks for considering Aspose.

Well I can't see this feature.. disabling copying or pasting within a column.. in Ms Excel. However, we may protect a sheet and disable selection within the column.

You may see all the protection options available in ExcelXP or greater and Aspose.Cells support all those options too .....Select Tools | Protection | Protect Sheet... You can check or uncheck different options related to allow or disallow different tasks. The first one is "Select Locked Cells" If you uncheck it you cannot select the cells.

Excel Procedure:

1. Select all the worksheet cells in ExcelXp file or Press CTRL + A.

2. Now select Format | Cells | Protection tab... and uncheck the Locked option.

3. Now select a Column, say Column C, whom you want to lock. you can click on the column header to select a column.

4. Now again select Format | Cells | Protection tab.....and check the Locked option.

5. Now either you can protect the sheet Selecting .. Tools | Protection | Protect Sheet... and uncheck the first option "Select Locked Cells" to disable the user from selecting the entire column


Save the file and using Aspose.Cells APIs like Worksheet.Protect() method to save the sheet.

With Pure Aspsoe.Cells APIs:

Workbook wb = new Workbook();


Worksheet sheet = wb.Worksheets[0];

Style style;

StyleFlag flag;

// unlock all the column first.

for(int i = 0; i <= 255; i ++)


style = sheet.Cells.Columns[(byte)i].Style;

style.IsLocked = false;

flag = new StyleFlag();

flag.Locked = true;

sheet.Cells.Columns[(byte)i].ApplyStyle(style, flag);


// Now lock 3rd column only

style = sheet.Cells.Columns[2].Style;

style.IsLocked = true;

flag = new StyleFlag();

flag.Locked = true;

sheet.Cells.Columns[2].ApplyStyle(style, flag);

// Protect the sheet.

Aspose.Cells.Protection protection = sheet.Protection;

// Disable the selection of the Locked cells of the 3rd column

protection.IsSelectingLockedCellsAllowed = false;

wb.Save("d:\\testlock1.xls", FileFormatType.Excel2003);


Amjad Sahi

Aspose Nanjing Team