[{"id":"b66f8b1e-cc14-4e89-9679-abd5687d283d","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"569bb90a-ea68-46c6-96f1-ab151c120714","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5eb52f08-2d1a-4362-9ffc-4871bdc10f3f","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"341dd607-b97d-4d70-bde2-53acda6b6c95","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"05349273-414f-4208-9ea2-c4fc8f4ea2cb","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"86089f76-b778-4d52-821e-6f27de3df613","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b81e4fd6-1fc5-43a0-a258-b6e16a5cbec6","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8aa8ce31-43e4-438e-951f-241608435260","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"37343f41-6ec2-4c7e-b21d-2cc18d5ce1e0","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"5915e52f-64f8-4146-b8bd-81bead6324a3","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"836ba889-af9e-460d-a4cc-c24d922795f2","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4ae14b06-bb68-4394-a210-a46b8f028346","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d8f42066-e9dc-4411-bdcf-43b1a203370c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"7ef86f16-b1a0-49f7-9592-612b9be02b25","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b29c7775-a9a4-451e-a1b5-01d19ed5ca5e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"e56f3989-8f81-46af-90fa-a4813eeb976f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"2526c963-f170-45a8-923e-91b0712a9810","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"24575cf0-501a-44f9-8426-c40f8f4b5552","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1a6f8d7f-acd6-42be-8c4f-f464c6218381","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"82b176fd-5cab-498c-909e-8fa7d29c38d8","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"1708b3a9-4f37-44a8-8f0e-f9a2d2e5d940","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"c9ac246e-29fb-4bc4-8231-8439795bb590","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"94f2a5c3-2539-436a-af75-23fbbd1a3957","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d99594f4-2d40-4df4-9419-ba2ca6aa3f7f","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"fd66e72d-0f10-4f57-9807-6db26290ab2e","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"8f344863-503d-4bc3-a594-3815e7d55f5c","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"9be82601-de9d-4c18-948a-23ab6f4dd431","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"6495f3c0-b463-47e0-b08a-ca949672211e","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"b4bede08-3f08-4839-ba4a-abc7ac195bde","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4afcdfc0-3ff5-4f2b-a223-f8fc042a5bbe","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"422062c4-fa40-4771-a86f-008efe6d86e5","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"d87e8013-86a7-4840-8d25-6f62e14eb4ac","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a6acedfd-4043-4c64-a5d1-aec3326df9e7","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"dbdc0b24-06c4-48b9-8d6c-7455119dc773","tags":[{"product":null,"links":null,"id":"9e117e35-984a-4c14-95ca-ef0ec7b9fb60","name":"\u65B0\u589E","color":"DarkGreen","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"a3856849-954a-4cfc-96a6-382e530d3638","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]},{"id":"4a39306b-ffa5-433d-80a3-28e41f929b72","tags":[{"product":null,"links":null,"id":"a2f84374-4a3f-4d22-96fd-765e9de495bf","name":"\u66F4\u65B0","color":"Coral","productId":"098be112-50ec-44e4-b746-6bc8bf76af97"}]}]
SpreadJS 允许您保护锁定所有单元格的工作表并防止其他用户更改、移动或删除数据。 但是,您仍然可以从锁定的单元格中复制数据。
isProtected 选项可以设置 为 true 以保护工作表和锁定方法可用于锁定或解锁单元格。
您可以通过将 locked 方法设置为False,允许用户编辑受保护工作表中的特定单元格。
sheet.getCell(1,1, GC.Spread.Sheets.SheetArea.viewport).locked(false);
sheet.setValue(1,1,"unLocked");
sheet.getRange(-1,3, -1, 1).locked(false);
sheet.getRange(5, -1, 1, -1).locked(false);
sheet.options.isProtected = true;
您可以按照以下步骤选择锁定受保护工作表中特定范围的单元格:
通过创建自定义样式并将 locked 方法设置为 False 来解锁所有单元格。
单独锁定您想要只读的单元格范围。
// 配置工作簿和工作表
var spread = new GC.Spread.Sheets.Workbook("ss");
var sheet = spread.getActiveSheet();
// Unlock all the cells in the worksheet via the styles
let style = new GC.Spread.Sheets.Style();
style.locked = false;
// 将样式设置为工作表中所有单元格的默认样式
sheet.setDefaultStyle(style);
// 单独锁定你想只读的单元格范围
new GC.Spread.Sheets.CellRange(sheet, 0, 0, 13, 4).locked(true);
// 设置要保护的工作表
sheet.options.isProtected = true;
options.protectionOptions 属性可用于指定可以更改的区域。 这些区域可以包括调整大小、拖动、插入或删除行或列等。
isProtected 选项设置为true时,以下属性设置为True时生效:
特性 | 说明 |
---|---|
allowDragInsertRows | 允许您在插入行时执行拖动操作。 |
allowDragInsertColumns | 允许您在插入列时执行拖动操作。 |
allowInsertRows | 允许您插入行。 |
allowInsertColumns | 允许您插入列。 |
allowDeleteRows | 允许您删除行。 |
allowDeleteColumns | 允许您删除列。 |
allowSelectLockedCells | 允许您选择锁定的单元格。 |
allowSelectUnlockedCells | 允许您选择未锁定的单元格。 |
allowSort | 允许您对范围进行排序。 |
allowFilter | 允许筛选范围。 |
allowEditObjects | 允许您编辑浮动对象。 |
allowResizeRows | 允许您调整行大小。 |
allowResizeColumns | 允许您调整列的大小。 |
allowOutlineRows | 允许您展开或折叠行组。 |
allowOutlineColumns | 允许您展开或折叠列组。 |
当 isProtected 选项设置为false时,上述保护选项将不起作用。
您可以保护工作表并启用 SpreadJS 中可用的各种保护选项。
var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
var sheet = spread.getActiveSheet();
sheet.options.isProtected = true;
sheet.options.protectionOptions.allowDeleteRows = true;
sheet.options.protectionOptions.allowDeleteColumns = true;
sheet.options.protectionOptions.allowInsertRows = true;
sheet.options.protectionOptions.allowInsertColumns = true;
sheet.options.protectionOptions.allowDargInsertRows = true;
sheet.options.protectionOptions.allowDragInsertColumns = true;
type=warning
注意: 保护选项:allowInsertRows,allowInsertColumns,allowDeleteRows和allowDeleteColumns仅在用户界面上执行操作时可用。 换句话说,该值将仅限制上下文菜单中行和列的插入和删除命令。
默认情况下,您不能在受保护的工作表中展开或折叠大纲行或列组。 触发了 invalidOperation 事件,您还可以绑定该事件以显示警告消息,如下所示:
// Set alert message
spread.bind(GC.Spread.Sheets.Events.InvalidOperation, (e, args) => {
if(args.invalidType === GC.Spread.Sheets.InvalidOperationType.groupProtected){
args.message="Expand or Collapse operation is not allowed for a protected worksheet.";
alert(args.message)
}
});
您可以选择在使用protect方法保护工作表的同时设置密码。但是,在调用 protect 方法时,isProtected选项将自动设置为 true。
//Protect the worksheet
var password = 'AddedPassword';
activeSheet.protect(password);
您可以通过将密码作为参数提供给取消保护方法来进一步取消对工作表的保护。
//unprotect the worksheet with a password
if(activeSheet.hasPassword()) {
activeSheet.unprotect(password);
} else {
activeSheet.unprotect();
}
您可以使用 Style 类的 hidden 属性或 CellRange 类的 hidden 方法来控制受保护工作表中公式单元格的可见性。默认情况下,hidden 属性设置为 false,表示公式不会被隐藏。
此外,它还支持 SSJSON、SJS 和 XLSX 的导出和导入。
hidden 属性在某些情况下非常有用,比如根据员工自评和主管评估生成 KPI 数据或年终奖金时,雇主希望隐藏相关公式并保护评估系统。
以下代码示例展示了如何使用 GC.Spread.Sheets.Style 类型的 hidden 属性来隐藏单元格。
// Sets whether the cell formula is visible when the sheet is protected.
activeSheet.options.isProtected = true;
// Create a style with hidden property true
var style = new GC.Spread.Sheets.Style();
style.hidden = true;
activeSheet.setStyle(1, 1, style, GC.Spread.Sheets.SheetArea.viewport);
// Apply style to a cell containing formula
activeSheet.setFormula(1, 1, "=SUM(1,2)");
或者,此代码示例使用 GC.Spread.Sheets.CellRange 类型中的隐藏方法
// Sets whether the cell formula is visible when the sheet is protected.
activeSheet.options.isProtected = true;
activeSheet.setFormula(1, 3, "=SUM(10,20)");
activeSheet.getRange(1, 3, GC.Spread.Sheets.SheetArea.viewport).hidden(true);
以下 SpreadJS 功能受 hidden 属性的影响:
当单元格设置了 hidden 属性时,公式栏和公式编辑器面板不会显示任何公式。
当隐藏单元格处于编辑模式时,输入编辑器中的默认数据为空。
隐藏单元格不会复制公式,只复制结果,但剪切操作始终包含公式。
但是,您可以通过将 locked 属性设置为 true 来防止这种情况。
showFormulas 属性不会显示隐藏单元格的公式。
如果 hidden 属性生效,FORMULATEXT() 方法无法获取单元格的公式。
请注意,hidden 和 locked 属性会互相影响其功能,如下表所示:
情况 | locked | hidden | 结果 |
---|---|---|---|
工作表未受保护 | True/False | True/False | locked 和 hidden 都不会生效 |
工作表受保护 | False | False | 单元格可编辑,公式正常显示 |
True | True | 单元格被锁定,无法编辑,但公式显示正常 | |
False | False | 单元格可编辑,但公式被隐藏,在编辑模式下,输入框显示为空 | |
True | True | 单元格锁定,不可编辑,且公式被隐藏 |
限制:
TableSheet、GanttSheet 和 ReportSheet 不支持 hidden 属性。
隐藏属性不会影响通过 API 访问的公式。
要访问“保护工作表”对话框,请通过右键单击选项卡条上显示的工作表名称导航到“保护工作表”选项。
使用保护工作表对话框保护和取消保护工作表的步骤
输入密码以保护工作表,并从“保护工作表”对话框的可用选项列表中选中/取消选中多个选项。
当您输入密码以保护工作表时,另一个对话框会确认密码。
成功设置密码后,您可以访问受保护的工作表,但不能对工作表进行任何更改。要取消保护工作表,请使用“取消保护工作表”对话框输入设置的密码。