XLSX
工作表保护
锁定工作表,限制编辑操作
保护工作表
使用密码保护工作表并限制用户操作:
{
"worksheets": [
{
"name": "Protected",
"rows": [
{ "cells": [{ "value": "Quarter" }, { "value": "2023" }, { "value": "2024" }] },
{ "cells": [{ "value": "Q1" }, { "value": 100 }, { "value": 120 }] },
{ "cells": [{ "value": "Q2" }, { "value": 150 }, { "value": 170 }] }
],
"protection": {
"sheet": true,
"password": "secret",
"formatCells": false,
"insertRows": false,
"sort": false
}
}
]
}
{
name: "Protected",
rows: [
{ cells: [{ value: "Quarter" }, { value: "2023" }, { value: "2024" }] },
{ cells: [{ value: "Q1" }, { value: 100 }, { value: 120 }] },
{ cells: [{ value: "Q2" }, { value: 150 }, { value: 170 }] },
],
protection: {
sheet: true,
password: "secret",
formatCells: false,
insertRows: false,
sort: false,
},
}
保护选项参考
| 选项 | 类型 | 说明 |
|---|---|---|
sheet | boolean | 启用工作表保护 |
password | string | 保护密码 |
objects | boolean | 保护对象 |
scenarios | boolean | 保护方案 |
formatCells | boolean | 允许格式化单元格 |
formatColumns | boolean | 允许格式化列 |
formatRows | boolean | 允许格式化行 |
insertColumns | boolean | 允许插入列 |
insertRows | boolean | 允许插入行 |
insertHyperlinks | boolean | 允许插入超链接 |
deleteColumns | boolean | 允许删除列 |
deleteRows | boolean | 允许删除行 |
selectLockedCells | boolean | 允许选取锁定单元格 |
sort | boolean | 允许排序 |
autoFilter | boolean | 允许自动筛选 |
pivotTables | boolean | 允许数据透视表 |
selectUnlockedCells | boolean | 允许选取未锁定单元格 |