Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
on: [push, pull_request]
on: [push, pull_request, release]
name: build

jobs:
Expand Down
17 changes: 17 additions & 0 deletions excelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -1740,6 +1740,23 @@ def get_sheet_index(self, sheet: str) -> Tuple[int, Optional[Exception]]:
err = res.err.decode(ENCODE)
return res.val, None if err == "" else Exception(err)

def get_sheet_name(self, sheet: int) -> str:
"""
Get the sheet name of the workbook by the given sheet index.
If the given sheet index is invalid or the sheet doesn't exist,
it will return an empty string.

Args:
sheet (int): The worksheet index

Returns:
str: The sheet name if the index is valid, otherwise an empty string.
"""
lib.GetSheetName.restype = types_go._StringErrorResult
res = lib.GetSheetName(self.file_index, c_int(sheet))
err = res.err.decode(ENCODE)
return res.val.decode(ENCODE) if err == "" else ""

def get_style(self, style_id: int) -> Tuple[Optional[Style], Optional[Exception]]:
"""
Get style definition by given style index.
Expand Down
12 changes: 12 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -1287,6 +1287,18 @@ func GetSheetIndex(idx int, sheet *C.char) C.struct_IntErrorResult {
return C.struct_IntErrorResult{val: C.int(idx), err: C.CString(emptyString)}
}

// GetSheetName provides a function to get the sheet name by the given worksheet index.
// If the given worksheet index is invalid, it will return an error.
//
//export GetSheetName
func GetSheetName(idx int, sheetIndex int) C.struct_StringErrorResult {
f, ok := files.Load(idx)
if !ok {
return C.struct_StringErrorResult{val: C.CString(emptyString), err: C.CString(errFilePtr)}
}
return C.struct_StringErrorResult{val: C.CString(f.(*excelize.File).GetSheetName(sheetIndex)), err: C.CString(emptyString)}
}

// GetStyle provides a function to get style definition by given style index.
//
//export GetStyle
Expand Down
1 change: 1 addition & 0 deletions test_excelize.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ def test_style(self):
index, err = f.get_sheet_index("Sheet2")
self.assertEqual(idx, index)
self.assertIsNone(err)
self.assertEqual(f.get_sheet_name(index), "Sheet2")

self.assertIsNone(f.set_col_outline_level("Sheet1", "D", 2))
level, err = f.get_col_outline_level("Sheet1", "D")
Expand Down