Skip to content

Commit f0d2ad6

Browse files
committed
Add 2 new functions: delete_form_control and get_form_controls
- Add new drop_lines and high_low_lines fields in ChartAxis class - Upgrade the dependencies package version - Update unit tests
1 parent 2bd6377 commit f0d2ad6

File tree

9 files changed

+282
-76
lines changed

9 files changed

+282
-76
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
matrix:
1111
go-version: [1.25.x]
1212
os: [ubuntu-24.04, macos-latest, windows-latest]
13-
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15.0-alpha.3"]
13+
python-version: ["3.9", "3.10", "3.11", "3.12", "3.13", "3.14", "3.15.0-alpha.5"]
1414
targetplatform: [x64]
1515

1616
runs-on: ${{ matrix.os }}

excelize.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2674,6 +2674,40 @@ def delete_defined_name(self, defined_name: DefinedName) -> None:
26742674
if err != "":
26752675
raise RuntimeError(err)
26762676

2677+
def delete_form_control(self, sheet: str, cell: str) -> None:
2678+
"""
2679+
Delete form control in a worksheet by given worksheet name and cell
2680+
reference.
2681+
2682+
Args:
2683+
sheet (str): The worksheet name
2684+
cell (str): The cell reference
2685+
2686+
Returns:
2687+
None: Return None if no error occurred, otherwise raise a
2688+
RuntimeError with the message.
2689+
2690+
Example:
2691+
For example, delete the form control in Sheet1!$A$1:
2692+
2693+
```python
2694+
try:
2695+
f.delete_form_control("Sheet1", "A1")
2696+
except (RuntimeError, TypeError) as err:
2697+
print(err)
2698+
```
2699+
"""
2700+
prepare_args(
2701+
[sheet, cell],
2702+
[argsRule("sheet", [str]), argsRule("cell", [str])],
2703+
)
2704+
err, lib.DeleteFormControl.restype = None, c_char_p
2705+
err = lib.DeleteFormControl(
2706+
self.file_index, sheet.encode(ENCODE), cell.encode(ENCODE)
2707+
).decode(ENCODE)
2708+
if err != "":
2709+
raise RuntimeError(err)
2710+
26772711
def delete_picture(self, sheet: str, cell: str) -> None:
26782712
"""
26792713
Delete all pictures in a cell by given worksheet name and cell reference.
@@ -3297,6 +3331,31 @@ def get_doc_props(self) -> DocProperties:
32973331
return c_value_to_py(res.opts, DocProperties())
32983332
raise RuntimeError(err)
32993333

3334+
def get_form_controls(self, sheet: str) -> List[FormControl]:
3335+
"""
3336+
Retrieves all form controls in a worksheet by a given worksheet name.
3337+
Note that, this function does not support getting the width and height
3338+
of the form controls currently.
3339+
3340+
Args:
3341+
sheet (str): The worksheet name
3342+
3343+
Returns:
3344+
List[FormControl]: Return the form controls list if no error
3345+
occurred, otherwise raise a RuntimeError with the message.
3346+
"""
3347+
prepare_args([sheet], [argsRule("sheet", [str])])
3348+
lib.GetFormControls.restype = types_go._GetFormControlsResult
3349+
res = lib.GetFormControls(self.file_index, sheet.encode(ENCODE))
3350+
err = res.Err.decode(ENCODE)
3351+
if err == "":
3352+
arr = []
3353+
if res.FormControls:
3354+
for i in range(res.FormControlsLen):
3355+
arr.append(c_value_to_py(res.FormControls[i], FormControl()))
3356+
return arr
3357+
raise RuntimeError(err)
3358+
33003359
def get_merge_cells(self, sheet: str, *without_values: bool) -> List[MergeCell]:
33013360
"""
33023361
Get all merged cells from a specific worksheet. If the `without_values`

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ module github.com/xuri/excelize-py
33
go 1.24.0
44

55
require (
6-
github.com/xuri/excelize/v2 v2.10.1-0.20260118024929-7b57409533bd
6+
github.com/xuri/excelize/v2 v2.10.1-0.20260127013103-4917cff6d84d
77
golang.org/x/image v0.34.0
88
)
99

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ github.com/tiendc/go-deepcopy v1.7.2 h1:Ut2yYR7W9tWjTQitganoIue4UGxZwCcJy3orjrrI
1212
github.com/tiendc/go-deepcopy v1.7.2/go.mod h1:4bKjNC2r7boYOkD2IOuZpYjmlDdzjbpTRyCx+goBCJQ=
1313
github.com/xuri/efp v0.0.1 h1:fws5Rv3myXyYni8uwj2qKjVaRP30PdjeYe2Y6FDsCL8=
1414
github.com/xuri/efp v0.0.1/go.mod h1:ybY/Jr0T0GTCnYjKqmdwxyxn2BQf2RcQIIvex5QldPI=
15-
github.com/xuri/excelize/v2 v2.10.1-0.20260118024929-7b57409533bd h1:IQ0K+7drQi4hLaAD2NigwJyEE1mU5B4aj6vGzFy4oOs=
16-
github.com/xuri/excelize/v2 v2.10.1-0.20260118024929-7b57409533bd/go.mod h1:vNleVHp3A4VEl9OnVNy3obCTtjqlOq/k0r5ik1PX4h0=
15+
github.com/xuri/excelize/v2 v2.10.1-0.20260127013103-4917cff6d84d h1:+hP0nTSblrRkY9x2N9NqQWGsy3J/J5PErvr58I3Wcec=
16+
github.com/xuri/excelize/v2 v2.10.1-0.20260127013103-4917cff6d84d/go.mod h1:vNleVHp3A4VEl9OnVNy3obCTtjqlOq/k0r5ik1PX4h0=
1717
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9 h1:+C0TIdyyYmzadGaL/HBLbf3WdLgC29pgyhTjAT/0nuE=
1818
github.com/xuri/nfp v0.0.2-0.20250530014748-2ddeb826f9a9/go.mod h1:WwHg+CVyzlv/TX9xqBFXEZAuxOPxn2k1GNHwG41IIUQ=
1919
golang.org/x/crypto v0.47.0 h1:V6e3FRj+n4dbpw86FJ8Fv7XVOql7TEwpHapKoMJ/GO8=

main.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,21 @@ func DeleteDefinedName(idx int, definedName *C.struct_DefinedName) *C.char {
986986
return C.CString(emptyString)
987987
}
988988

989+
// DeleteFormControl provides the method to delete form control in a worksheet
990+
// by given worksheet name and cell reference.
991+
//
992+
//export DeleteFormControl
993+
func DeleteFormControl(idx int, sheet, cell *C.char) *C.char {
994+
f, ok := files.Load(idx)
995+
if !ok {
996+
return C.CString(errFilePtr)
997+
}
998+
if err := f.(*excelize.File).DeleteFormControl(C.GoString(sheet), C.GoString(cell)); err != nil {
999+
return C.CString(err.Error())
1000+
}
1001+
return C.CString(emptyString)
1002+
}
1003+
9891004
// DeletePicture provides a function to delete charts in spreadsheet by given
9901005
// worksheet name and cell reference. Note that the image file won't be
9911006
// deleted from the document currently.
@@ -1427,6 +1442,31 @@ func GetDocProps(idx int) C.struct_GetDocPropsResult {
14271442
return C.struct_GetDocPropsResult{opts: cVal.Elem().Interface().(C.struct_DocProperties), err: C.CString(emptyString)}
14281443
}
14291444

1445+
// GetFormControls retrieves all form controls in a worksheet by a given
1446+
// worksheet name. Note that, this function does not support getting the width
1447+
// and height of the form controls currently.
1448+
//
1449+
//export GetFormControls
1450+
func GetFormControls(idx int, sheet *C.char) C.struct_GetFormControlsResult {
1451+
f, ok := files.Load(idx)
1452+
if !ok {
1453+
return C.struct_GetFormControlsResult{Err: C.CString(errFilePtr)}
1454+
}
1455+
opts, err := f.(*excelize.File).GetFormControls(C.GoString(sheet))
1456+
if err != nil {
1457+
return C.struct_GetFormControlsResult{Err: C.CString(err.Error())}
1458+
}
1459+
cArray := C.malloc(C.size_t(len(opts)) * C.size_t(unsafe.Sizeof(C.struct_FormControl{})))
1460+
for i, dn := range opts {
1461+
cVal, err := goValueToC(reflect.ValueOf(dn), reflect.ValueOf(&C.struct_FormControl{}))
1462+
if err != nil {
1463+
return C.struct_GetFormControlsResult{Err: C.CString(err.Error())}
1464+
}
1465+
*(*C.struct_FormControl)(unsafe.Pointer(uintptr(unsafe.Pointer(cArray)) + uintptr(i)*unsafe.Sizeof(C.struct_FormControl{}))) = cVal.Elem().Interface().(C.struct_FormControl)
1466+
}
1467+
return C.struct_GetFormControlsResult{FormControlsLen: C.int(len(opts)), FormControls: (*C.struct_FormControl)(cArray), Err: C.CString(emptyString)}
1468+
}
1469+
14301470
// GetMergeCells provides a function to get all merged cells from a specific
14311471
// worksheet. If the `withoutValues` parameter is set to true, it will not
14321472
// return the cell values of merged cells, only the range reference will be

0 commit comments

Comments
 (0)