This closes #2113, AddFormControl function support set cell link for check box

This commit is contained in:
xuri 2025-04-11 14:45:48 +08:00
parent 6007d25231
commit f85dae6cfa
No known key found for this signature in database
GPG Key ID: BA5E5BB1C948EDF7
2 changed files with 9 additions and 2 deletions

9
vml.go
View File

@ -372,7 +372,11 @@ func (f *File) commentsWriter() {
// by given worksheet name and form control options. Supported form control // by given worksheet name and form control options. Supported form control
// type: button, check box, group box, label, option button, scroll bar and // type: button, check box, group box, label, option button, scroll bar and
// spinner. If set macro for the form control, the workbook extension should be // spinner. If set macro for the form control, the workbook extension should be
// XLSM or XLTM. Scroll value must be between 0 and 30000. // XLSM or XLTM. Scroll value must be between 0 and 30000. Please note that if a
// cell link is set for a checkbox form control, Excelize will not assign a
// value to the linked cell when the checkbox is checked. To reflect the
// checkbox state, please use the 'SetCellValue' function to manually set the
// linked cell's value to true.
// //
// Example 1, add button form control with macro, rich-text, custom button size, // Example 1, add button form control with macro, rich-text, custom button size,
// print property on Sheet1!A2, and let the button do not move or size with // print property on Sheet1!A2, and let the button do not move or size with
@ -826,6 +830,9 @@ func (f *File) addFormCtrlShape(preset formCtrlPreset, col, row int, anchor stri
if (opts.Type == FormControlCheckBox || opts.Type == FormControlOptionButton) && opts.Checked { if (opts.Type == FormControlCheckBox || opts.Type == FormControlOptionButton) && opts.Checked {
sp.ClientData.Checked = 1 sp.ClientData.Checked = 1
} }
if opts.FormControl.Type == FormControlCheckBox {
sp.ClientData.FmlaLink = opts.CellLink
}
return &sp, sp.addFormCtrl(opts) return &sp, sp.addFormCtrl(opts)
} }

View File

@ -192,7 +192,7 @@ func TestFormControl(t *testing.T) {
}, },
{ {
Cell: "A6", Type: FormControlCheckBox, Text: "Check Box 2", Cell: "A6", Type: FormControlCheckBox, Text: "Check Box 2",
Format: GraphicOptions{Positioning: "twoCell"}, CellLink: "C5", Format: GraphicOptions{Positioning: "twoCell"},
}, },
{ {
Cell: "A7", Type: FormControlOptionButton, Text: "Option Button 1", Checked: true, Cell: "A7", Type: FormControlOptionButton, Text: "Option Button 1", Checked: true,