[{"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"}]}]
单元格按钮是一组预定义的按钮,可以添加到工作表单元格以配置其他功能。它们允许您为操作配置特定行为,例如当用户单击单元格按钮、编辑单元格或将鼠标悬停在单元格上时。cellbuttons 类型属于 Style 类,因此它允许您创建命名样式,这些样式可以选择性地轻松应用于任何单元格。
例如,您可以通过为单元格定义一个名为 style 的自定义颜色选择器来创建一个带有颜色选择器下拉菜单的按钮。这种样式可以重复使用并应用于任何其他单元格。
以下 GIF 显示了一些单元格按钮命令和属性的用法,以实现所需的自定义。
带有“插入”标题的单元格按钮
“启用”属性设置为 true 和 false 的单元格按钮
单元格按钮设置为下拉ButtonImageType枚举值和opencolorpicker命令
用户可以使用单元格按钮可用的不同属性来配置单元格按钮,如下表所述:
属性 | 描述 |
---|---|
ButtonPosition | 此属性是ButtonPosition 枚举类型,用于指定单元格按钮的位置。您可以将单元格按钮的位置设置为向左或向右,并创建自定义样式来显示这些按钮。 |
CaptionAlignment | 此属性是 CaptionAlignment 枚举类型,用于指定标题在单元格按钮中的位置。您可以将标题的位置配置为向左或向右。 |
ButtonImageType | 该属性是ButtonImageType枚举类型,指定单元格按钮的图像类型。您可以根据特定偏好配置按钮图像类型,例如下拉、搜索、撤消、重做。完整列表请参考ButtonImageType Enumeration。 |
ButtonVisibility | 此属性的类型为ButtonVisibility枚举,用于指定单元格按钮的可见性。 用户可以使用以下值选择在不同的单元状态下显示还是隐藏单元按钮: |
caption | 此属性指定将在标题中显示的按钮的文本。 |
position | 此属性指定按钮在单元格中的位置。 |
enabled | 此属性指定单元格按钮是否将响应用户操作。 默认值设置为true。 |
useButtonStyle | 此属性指定单元格按钮是否为按钮样式。 默认值为false。 |
width | 此属性指定按钮的宽度。 如果用户将此属性设置为“ null”或“ undefined”,则按钮的适合度将根据标题和图像大小自动进行调整。 |
visibility | 此属性指定按钮的可见性。 提供三个选项("always", "onselect" and "edit")。 |
imageType | 此属性指定用户要在按钮中显示的图像的类型。 此属性的默认值为“ custom”。 |
command | 此属性允许用户在单击单元格按钮时执行传播命令或回调。 |
imageSrc | 当imageType设置为custom时,此属性允许用户通过提供图像源来上传图像。 |
captionAlign | 此属性指定图像和标题的位置。 可用选项为“左”和“右”。 |
imageSize | 此属性指定图像大小。 默认值为16px。 |
hoverBackColor | 此属性指定当按钮可见并启用时单元格按钮的悬停颜色。 |
创建单元按钮后,用户可以根据下表中提供的选项指定不同的命令操作,以将不同的功能与按钮相关联。
命令选项 | 描述 |
---|---|
openColorPicker | 当用户要在按钮单击事件中打开颜色选择器时,可以使用此选项。 |
openDateTimePicker | 当用户要在按钮单击事件上打开日期时间选择器时,可以使用此选项。 |
openTimePicker | 当用户要在按钮单击事件上打开时间选择器时,可以使用此选项。 |
openMonthPicker | 当用户要在按钮单击事件上打开月份选择器时,可以使用此选项。 |
openSlider | 当用户要在按钮单击事件上打开滑块控件时,可以使用此选项。 |
openWorkflowList | 当用户要在按钮单击事件上打开工作流列表时,可以使用此选项。 |
openCalculator | 当用户要在单击按钮事件时打开计算器时,可以使用此选项。 |
openList | 当用户要在按钮单击事件上打开列表时,可以使用此选项。 |
请参考以下示例代码,以在表单中添加不同类型的单元格按钮。
$(document).ready(function ()
{
// 配置工作簿和表单
var spread = new GC.Spread.Sheets.Workbook($("#sampleDiv")[0]);
var activeSheet = spread.getActiveSheet();
activeSheet.setColumnWidth(3, 300);
activeSheet.setColumnWidth(4, 200);
// 添加带有文字的基本按钮
var basicButttonStyle = new GC.Spread.Sheets.Style();
basicButttonStyle.cellButtons =
[
{
caption: "Insert"
}
];
activeSheet.setText(2, 3, "Basic button with caption");
activeSheet.setStyle(2, 4, basicButttonStyle);
/* 具有不同配置设置的“添加”按钮,例如
位置,样式,启用/禁用 */
var customButtonStyle = new GC.Spread.Sheets.Style();
customButtonStyle.cellButtons =
[
{
caption: "enable",
useButtonStyle: true,
// enabled: true,
hoverBackColor: "#3390FF",
position: GC.Spread.Sheets.ButtonPosition.left
},
{
caption: "disabled",
useButtonStyle: false,
enabled: false,
position: GC.Spread.Sheets.ButtonPosition.right
}
];
activeSheet.setText(4, 3, "enabled/disabled buttons");
activeSheet.setStyle(4, 4, customButtonStyle);
// 带有内置和自定义图像的添加按钮
var ImageStyle = new GC.Spread.Sheets.Style();
ImageStyle.cellButtons =
[
{
useButtonStyle: true,
imageSize: {
height: 8,
width: 8
},
imageType: GC.Spread.Sheets.ButtonImageType.ellipsis
},
{
useButtonStyle: true,
imageType: GC.Spread.Sheets.ButtonImageType.custom,
imageSrc:"data:image/bmp;base64,
Qk1eAAAAAAAAAD4AAAAoAAAACAAAAAgAAAABAAEAAAAAACAAAADEDgAAxA4AAAAAAAAAAAAAAAAAAP///
wB+AAAApQAAANsAAAClAAAApQAAANsAAAClAAAAfgAAAA=="
}
];
activeSheet.setText(6, 3, "Image Buttons");
activeSheet.setStyle(6, 4, ImageStyle);
// 使用命令操作添加下拉菜单按钮
var dropdownStylecommand = new GC.Spread.Sheets.Style();
dropdownStylecommand.cellButtons =
[
{
imageType: GC.Spread.Sheets.ButtonImageType.dropdown,
useButtonStyle: true,
command: "openColorPicker"
}
];
activeSheet.setText(8, 3, "Dropdown button with command");
activeSheet.setStyle(8, 4, dropdownStylecommand);
// 使用命令功能添加下拉按钮
var buttonCommandfunction = new GC.Spread.Sheets.Style();
buttonCommandfunction.cellButtons =
[
{
imageType: GC.Spread.Sheets.ButtonImageType.search,
command: (sheet, row, col, option) =>
{
if (sheet.zoom() === 1) {
sheet.zoom(1.5);
} else {
sheet.zoom(1);
}
}
}
];
activeSheet.setText(10, 3, "Button with command function");
activeSheet.setStyle(10, 4, buttonCommandfunction);
// 添加带有警告命令操作的按钮
var visibleStyle = new GC.Spread.Sheets.Style();
visibleStyle.cellButtons =
[
{
caption:"Alert",
buttonBackColor: "#00C2D6",
command: (sheet, row, col, option) => {
alert("This is an alert.");
}
}
];
activeSheet.setStyle(7, 10, visibleStyle);
// 添加按钮可见性属性
var onScreenstyle = new GC.Spread.Sheets.Style();
onScreenstyle.cellButtons = [
{
caption: "On Select",
buttonBackColor:"#ffdc9d",
visibility: GC.Spread.Sheets.ButtonVisibility.onSelected
}
];
activeSheet.setStyle(10, 10, onScreenstyle);
activeSheet.getCell(10,10).value("Select cell..").vAlign(GC.Spread.Sheets.VerticalAlign.bottom);