Skip to content

Commit

Permalink
Add new function: get_col_outline_level (#10)
Browse files Browse the repository at this point in the history
- Update unie tests
  • Loading branch information
hly-717 authored Feb 10, 2025
1 parent da46454 commit 38ad3b2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
29 changes: 29 additions & 0 deletions excelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1536,6 +1536,35 @@ def get_cell_value(
err = res.err.decode(ENCODE)
return res.val.decode(ENCODE), None if err == "" else Exception(err)

def get_col_outline_level(
self, sheet: str, col: str
) -> Tuple[int, Optional[Exception]]:
"""
Get outline level of a single column by given worksheet name and column
name.
Args:
sheet (str): The worksheet name
col (str): The column name
Returns:
Tuple[int, Optional[Exception]]: A tuple containing the column
outline level and an exception if an error occurred, otherwise None.
Example:
For example, get outline level of column D in Sheet1:
.. code-block:: python
level, err = f.get_col_outline_level("Sheet1", "D")
"""
lib.GetColOutlineLevel.restype = types_go._IntErrorResult
res = lib.GetColOutlineLevel(
self.file_index, sheet.encode(ENCODE), col.encode(ENCODE)
)
err = res.err.decode(ENCODE)
return res.val, None if err == "" else Exception(err)

def get_col_style(self, sheet: str, col: str) -> Tuple[int, Optional[Exception]]:
"""
Get column style ID by given worksheet name and column name.
Expand Down
16 changes: 16 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,22 @@ func GetCellValue(idx int, sheet, cell *C.char, opts *C.struct_Options) C.struct
return C.struct_StringErrorResult{val: C.CString(val), err: C.CString(emptyString)}
}

// GetColOutlineLevel provides a function to get outline level of a single
// column by given worksheet name and column name.
//
//export GetColOutlineLevel
func GetColOutlineLevel(idx int, sheet, col *C.char) C.struct_IntErrorResult {
f, ok := files.Load(idx)
if !ok {
return C.struct_IntErrorResult{val: C.int(0), err: C.CString(errFilePtr)}
}
val, err := f.(*excelize.File).GetColOutlineLevel(C.GoString(sheet), C.GoString(col))
if err != nil {
return C.struct_IntErrorResult{val: C.int(int32(val)), err: C.CString(err.Error())}
}
return C.struct_IntErrorResult{val: C.int(int32(val)), err: C.CString(emptyString)}
}

// GetColStyle provides a function to get column style ID by given worksheet
// name and column name. This function is concurrency safe.
//
Expand Down
3 changes: 3 additions & 0 deletions test_excelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@ def test_style(self):
self.assertIsNone(err)

self.assertIsNone(f.set_col_outline_level("Sheet1", "D", 2))
level, err = f.get_col_outline_level("Sheet1", "D")
self.assertEqual(level, 2)
self.assertIsNone(err)
self.assertIsNone(f.set_row_outline("Sheet1", 2, 1))

self.assertIsNone(f.set_sheet_background("Sheet2", "chart.png"))
Expand Down

0 comments on commit 38ad3b2

Please sign in to comment.