@@ -425,6 +425,7 @@ func regInteropFunc(f *excelize.File, fn map[string]interface{}) interface{} {
425
425
"SetColVisible" : SetColVisible (f ),
426
426
"SetColWidth" : SetColWidth (f ),
427
427
"SetConditionalFormat" : SetConditionalFormat (f ),
428
+ "SetCustomProps" : SetCustomProps (f ),
428
429
"SetDefaultFont" : SetDefaultFont (f ),
429
430
"SetDefinedName" : SetDefinedName (f ),
430
431
"SetDocProps" : SetDocProps (f ),
@@ -1154,7 +1155,7 @@ func AddDataValidation(f *excelize.File) func(this js.Value, args []js.Value) in
1154
1155
}
1155
1156
}
1156
1157
1157
- // AddFormControl provides the method to add form control button in a worksheet
1158
+ // AddFormControl provides the method to add form control object in a worksheet
1158
1159
// by given worksheet name and form control options. Supported form control
1159
1160
// type: button, check box, group box, label, option button, scroll bar and
1160
1161
// spinner. If set macro for the form control, the workbook extension should be
@@ -3636,6 +3637,45 @@ func SetConditionalFormat(f *excelize.File) func(this js.Value, args []js.Value)
3636
3637
}
3637
3638
}
3638
3639
3640
+ // SetCustomProps provides a function to set custom file properties by given
3641
+ // property name and value. If the property name already exists, it will be
3642
+ // updated, otherwise a new property will be added. The value can be of type
3643
+ // int32, float64, bool, string, time.Time or nil. The property will be delete
3644
+ // if the value is nil. The function returns an error if the property value is
3645
+ // not of the correct type.
3646
+ func SetCustomProps (f * excelize.File ) func (this js.Value , args []js.Value ) interface {} {
3647
+ return func (this js.Value , args []js.Value ) interface {} {
3648
+ ret := map [string ]interface {}{"error" : nil }
3649
+ if err := prepareArgs (args , []argsRule {
3650
+ {types : []js.Type {js .TypeObject }},
3651
+ }); err != nil {
3652
+ ret ["error" ] = err .Error ()
3653
+ return js .ValueOf (ret )
3654
+ }
3655
+ if _ , err := jsValueToGo (args [0 ], reflect .TypeOf (excelize.CustomProperty {})); err != nil {
3656
+ ret ["error" ] = err .Error ()
3657
+ return js .ValueOf (ret )
3658
+ }
3659
+ prop := excelize.CustomProperty {Name : args [0 ].Get ("Name" ).String ()}
3660
+ val := args [0 ].Get ("Value" )
3661
+ switch val .Type () {
3662
+ case js .TypeNull :
3663
+ prop .Value = nil
3664
+ case js .TypeBoolean :
3665
+ prop .Value = val .Bool ()
3666
+ case js .TypeNumber :
3667
+ prop .Value = val .Float ()
3668
+ default : // js.TypeString:
3669
+ prop .Value = val .String ()
3670
+ }
3671
+ if err := f .SetCustomProps (prop ); err != nil {
3672
+ ret ["error" ] = err .Error ()
3673
+ return js .ValueOf (ret )
3674
+ }
3675
+ return js .ValueOf (ret )
3676
+ }
3677
+ }
3678
+
3639
3679
// SetDefaultFont changes the default font in the workbook.
3640
3680
func SetDefaultFont (f * excelize.File ) func (this js.Value , args []js.Value ) interface {} {
3641
3681
return func (this js.Value , args []js.Value ) interface {} {
0 commit comments