Is it possible to protect the contents of a specific column without having to do it cell by cell?
For example, I have 4 columns with this data:
sWorksheetGrid1.Cells[1,1] := 'Column1';
sWorksheetGrid1.Cells[1,2] := 200;
sWorksheetGrid1.Cells[1,3] := 124;
sWorksheetGrid1.Cells[1,4] := 682;
sWorksheetGrid1.Cells[1,5] := 456;
sWorksheetGrid1.Cells[2,1] := 'Column2';
sWorksheetGrid1.Cells[2,2] := 450;
sWorksheetGrid1.Cells[2,3] := 218;
sWorksheetGrid1.Cells[2,4] := 346;
sWorksheetGrid1.Cells[2,5] := 260;
sWorksheetGrid1.Cells[3,1] := 'Column3';
sWorksheetGrid1.Cells[3,2] := 120;
sWorksheetGrid1.Cells[3,3] := 368;
sWorksheetGrid1.Cells[3,4] := 874;
sWorksheetGrid1.Cells[3,5] := 240;
sWorksheetGrid1.Cells[4,1] := 'Column4';
sWorksheetGrid1.Cells[4,2] := 620;
sWorksheetGrid1.Cells[4,3] := 485;
sWorksheetGrid1.Cells[4,4] := 128;
sWorksheetGrid1.Cells[4,5] := 346;
If I only want to protect the contents of Column 1 and 3, cell by cell, I do:
var
cellprot: TsCellProtections;
cell: PCell;
i: integer;
begin
//Unlock Column 2
for i:=0 to 4 do
begin
cell := sWorksheetGrid1.Worksheet.FindCell(i,1);
cellprot := sWorksheetGrid1.Worksheet.ReadCellProtection(cell);
sWorksheetGrid1.Worksheet.WriteCellProtection(cell, cellprot - [cpLockCell]);
end;
//Unlock Column 4
for i:=0 to 4 do
begin
cell := sWorksheetGrid1.Worksheet.FindCell(i,3);
cellprot := sWorksheetGrid1.Worksheet.ReadCellProtection(cell);
sWorksheetGrid1.Worksheet.WriteCellProtection(cell, cellprot - [cpLockCell]);
end;
sWorksheetGrid1.Worksheet.Protect(true);
end;
However, I have some real cases where the number of rows is almost 1000...
I tried doing it with "WriteColFormatIndex":
var
fmt: TsCellFormat;
idx: Integer;
begin
InitFormatRecord(fmt);
fmt.Protection:=[cpLockCell];
fmt.UsedformattingFields := fmt.UsedFormattingFields + [uffProtection];
idx := sWorksheetGrid1.Workbook.AddCellFormat(fmt);
//Lock Column 1
sWorksheetGrid1.Worksheet.WriteColFormatIndex(1, idx);
//Lock Column 3
sWorksheetGrid1.Worksheet.WriteColFormatIndex(3, idx);
end
I appreciate any help you can give me.