양식 컨트롤
FormControl 은 양식 컨트롤 정보를 직접 매핑합니다.
type FormControl struct {
Cell string
Macro string
Width uint
Height uint
Checked bool
CurrentVal uint
MinVal uint
MaxVal uint
IncChange uint
PageChange uint
Horizontally bool
CellLink string
Text string
Paragraph []RichTextRun
Type FormControlType
Format GraphicOptions
}
양식 컨트롤 추가
func (f *File) AddFormControl(sheet string, opts FormControl) error
AddFormControl 은 지정된 워크시트 이름 및 양식 제어 옵션에 따라 워크시트에 양식 제어 단추를 추가하는 메서드를 제공합니다. 지원되는 양식 제어 유형: 단추, 확인란, 그룹 상자, 레이블, 옵션 단추, 스크롤 막대 및 스피너. 양식 컨트롤에 대해 매크로를 설정한 경우 통합 문서 확장은 .xlsm
또는 .xltm
이어야 합니다. 스크롤 값은 0 에서 30000 사이여야 합니다.
예제 1, 매크로, 서식 있는 텍스트, 사용자 지정 단추 크기, 인쇄 속성이 있는 단추 양식 컨트롤을 Sheet1!A2
로 설정하고 버튼이 셀과 함께 움직이거나 크기가 조정되지 않도록 합니다:
enable := true
err := f.AddFormControl("Sheet1", excelize.FormControl{
Cell: "A2",
Type: excelize.FormControlButton,
Macro: "Button1_Click",
Width: 140,
Height: 60,
Text: "Button 1\r\n",
Paragraph: []excelize.RichTextRun{
{
Font: &excelize.Font{
Bold: true,
Italic: true,
Underline: "single",
Family: "Times New Roman",
Size: 14,
Color: "777777",
},
Text: "C1=A1+B1",
},
},
Format: excelize.GraphicOptions{
PrintObject: &enable,
Positioning: "absolute",
},
})
예 2, Sheet1!A1
및 Sheet1!A2
에 체크 상태 및 텍스트가 있는 옵션 버튼 양식 컨트롤을 추가합니다:
if err := f.AddFormControl("Sheet1", excelize.FormControl{
Cell: "A1",
Type: excelize.FormControlOptionButton,
Text: "Option Button 1",
Checked: true,
Height: 20,
}); err != nil {
fmt.Println(err)
}
if err := f.AddFormControl("Sheet1", excelize.FormControl{
Cell: "A2",
Type: excelize.FormControlOptionButton,
Text: "Option Button 2",
Height: 20,
}); err != nil {
fmt.Println(err)
}
예 3, Sheet1!A1
의 값을 늘리거나 줄이기 위해 Sheet1!B1
에 스핀 버튼 양식 컨트롤을 추가합니다:
err := f.AddFormControl("Sheet1", excelize.FormControl{
Cell: "B1",
Type: excelize.FormControlSpinButton,
Width: 15,
Height: 40,
CurrentVal: 7,
MinVal: 5,
MaxVal: 10,
IncChange: 1,
CellLink: "A1",
})
예제 4, Sheet1!A2
에 가로 스크롤 막대 양식 컨트롤을 추가하여 스크롤 화살표를 클릭하거나 스크롤 상자를 드래그하여 Sheet1!A1
값을 변경합니다:
err := f.AddFormControl("Sheet1", excelize.FormControl{
Cell: "A2",
Type: excelize.FormControlScrollBar,
Width: 140,
Height: 20,
CurrentVal: 50,
MinVal: 10,
MaxVal: 100,
IncChange: 1,
PageChange: 1,
CellLink: "A1",
Horizontally: true,
})
양식 컨트롤 가져오기
func (f *File) GetFormControls(sheet string) ([]FormControl, error)
GetFormControls 는 지정된 워크시트 이름으로 워크시트의 모든 양식 컨트롤을 검색합니다. 이 함수는 현재 양식 컨트롤의 너비와 높이 가져오기를 지원하지 않습니다.
양식 컨트롤 삭제
func (f *File) DeleteFormControl(sheet, cell string) error
DeleteFormControl 은 지정된 워크시트 이름과 셀 참조에 따라 워크시트에서 양식 컨트롤을 삭제하는 메서드를 제공합니다. 예를 들어 Sheet1!$A$1
에서 양식 컨트롤을 삭제합니다.
err := f.DeleteFormControl("Sheet1", "A1")