Kbase P104902: How to manage the protection of a cell in an Excel Spreadsheet
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  04/10/2005 |
|
Status: Unverified
GOAL:
How to manage the protection of a cell in an Excel Spreadsheet
GOAL:
How to block a range of Excel cells
FIX:
In order to block a cell you have to change its Locked property to True. Please note that locking cells has no effect unless the worksheet is protected. Therefore you have to also change the Protect attribute of the Worksheet object to True.
Here is a sample code:
DEFINE VARIABLE excelAppl AS COM-HANDLE.
DEFINE VARIABLE wBook AS COM-HANDLE.
DEFINE VARIABLE wRange AS COM-HANDLE.
CREATE "Excel.Application" excelAppl.
excelAppl:VISIBLE = TRUE.
excelAppl:Workbooks:ADD().
excelAppl:Workbooks:ITEM(1):Worksheets:ITEM(1):Name = "Vito sheet".
wbook = excelAppl:Workbooks:ITEM(1):Worksheets:ITEM(1).
wbook:range ("A1:I18") = "Free".
wbook:range ("A1:C3") = "Block".
wRange = wbook:Range(wbook:Cells(1,1), wbook:Cells(18,9) ).
wRange:Locked = FALSE.
wRange = wbook:Range(wbook:Cells(1,1), wbook:Cells(3,3) ).
wRange:Locked = True.
wbook:Protect.
RELEASE OBJECT wRange.
RELEASE OBJECT wBook.
RELEASE OBJECT excelAppl.