|
1 | | -"""Copyright 2024 The excelize Authors. All rights reserved. Use of this source |
2 | | -code is governed by a BSD-style license that can be found in the LICENSE file. |
| 1 | +"""Copyright 2024 - 2025 The excelize Authors. All rights reserved. Use of this |
| 2 | +source code is governed by a BSD-style license that can be found in the LICENSE |
| 3 | +file. |
3 | 4 |
|
4 | 5 | Package excelize-py is a Python port of Go Excelize library, providing a set of |
5 | 6 | functions that allow you to write and read from XLAM / XLSM / XLSX / XLTM / XLTX |
@@ -1079,6 +1080,33 @@ def delete_comment(self, sheet: str, cell: str) -> Optional[Exception]: |
1079 | 1080 | ).decode(ENCODE) |
1080 | 1081 | return None if err == "" else Exception(err) |
1081 | 1082 |
|
| 1083 | + def delete_defined_name(self, defined_name: DefinedName) -> Optional[Exception]: |
| 1084 | + """ |
| 1085 | + Delete the defined names of the workbook or worksheet. If not specified |
| 1086 | + scope, the default scope is workbook. |
| 1087 | +
|
| 1088 | + Args: |
| 1089 | + defined_name (DefinedName): The defined name options |
| 1090 | +
|
| 1091 | + Returns: |
| 1092 | + Optional[Exception]: Returns None if no error occurred, |
| 1093 | + otherwise returns an Exception with the message. |
| 1094 | +
|
| 1095 | + Example: |
| 1096 | + For example: |
| 1097 | +
|
| 1098 | + .. code-block:: python |
| 1099 | +
|
| 1100 | + err = f.delete_defined_name(excelize.DefinedName( |
| 1101 | + name="Amount", |
| 1102 | + scope="Sheet2", |
| 1103 | + )) |
| 1104 | + """ |
| 1105 | + lib.DeleteDefinedName.restype = c_char_p |
| 1106 | + options = py_value_to_c(defined_name, types_go._DefinedName()) |
| 1107 | + err = lib.DeleteDefinedName(self.file_index, byref(options)).decode(ENCODE) |
| 1108 | + return None if err == "" else Exception(err) |
| 1109 | + |
1082 | 1110 | def delete_picture(self, sheet: str, cell: str) -> Optional[Exception]: |
1083 | 1111 | """ |
1084 | 1112 | Delete all pictures in a cell by given worksheet name and cell reference. |
@@ -1265,6 +1293,25 @@ def get_cell_hyperlink( |
1265 | 1293 | None if err == "" else Exception(err), |
1266 | 1294 | ) |
1267 | 1295 |
|
| 1296 | + def get_cell_style(self, sheet: str, cell: str) -> Tuple[int, Optional[Exception]]: |
| 1297 | + """ |
| 1298 | + Get cell style index by given worksheet name and cell reference. |
| 1299 | +
|
| 1300 | + Args: |
| 1301 | + sheet (str): The worksheet name |
| 1302 | + cell (str): The cell reference |
| 1303 | +
|
| 1304 | + Returns: |
| 1305 | + Tuple[int, Optional[Exception]]: A tuple containing the cell style, |
| 1306 | + and an Exception object if an error occurred, otherwise None. |
| 1307 | + """ |
| 1308 | + lib.GetCellStyle.restype = types_go._IntErrorResult |
| 1309 | + res = lib.GetCellStyle( |
| 1310 | + self.file_index, sheet.encode(ENCODE), cell.encode(ENCODE) |
| 1311 | + ) |
| 1312 | + err = res.err.decode(ENCODE) |
| 1313 | + return res.val, None if err == "" else Exception(err) |
| 1314 | + |
1268 | 1315 | def get_cell_value( |
1269 | 1316 | self, sheet: str, cell: str, *opts: Options |
1270 | 1317 | ) -> Tuple[str, Optional[Exception]]: |
@@ -1650,6 +1697,53 @@ def remove_col(self, sheet: str, col: str) -> Optional[Exception]: |
1650 | 1697 | ).decode(ENCODE) |
1651 | 1698 | return None if err == "" else Exception(err) |
1652 | 1699 |
|
| 1700 | + def remove_page_break(self, sheet: str, cell: str) -> Optional[Exception]: |
| 1701 | + """ |
| 1702 | + Remove a page break by given worksheet name and cell reference. |
| 1703 | +
|
| 1704 | + Args: |
| 1705 | + sheet (str): The worksheet name |
| 1706 | + cell (str): The cell reference |
| 1707 | +
|
| 1708 | + Returns: |
| 1709 | + Optional[Exception]: Returns None if no error occurred, |
| 1710 | + otherwise returns an Exception with the message. |
| 1711 | + """ |
| 1712 | + lib.RemovePageBreak.restype = c_char_p |
| 1713 | + err = lib.RemovePageBreak( |
| 1714 | + self.file_index, sheet.encode(ENCODE), cell.encode(ENCODE) |
| 1715 | + ).decode(ENCODE) |
| 1716 | + return None if err == "" else Exception(err) |
| 1717 | + |
| 1718 | + def remove_row(self, sheet: str, row: int) -> Optional[Exception]: |
| 1719 | + """ |
| 1720 | + Remove single row by given worksheet name and Excel row number. Use this |
| 1721 | + method with caution, which will affect changes in references such as |
| 1722 | + formulas, charts, and so on. If there is any referenced value of the |
| 1723 | + worksheet, it will cause a file error when you open it. The excelize |
| 1724 | + only partially updates these references currently. |
| 1725 | +
|
| 1726 | + Args: |
| 1727 | + sheet (str): The worksheet name |
| 1728 | + row (int): The row number |
| 1729 | +
|
| 1730 | + Returns: |
| 1731 | + Optional[Exception]: Returns None if no error occurred, |
| 1732 | + otherwise returns an Exception with the message. |
| 1733 | +
|
| 1734 | + Example: |
| 1735 | + For example, remove row 3 in Sheet1: |
| 1736 | +
|
| 1737 | + .. code-block:: python |
| 1738 | +
|
| 1739 | + err = f.remove_row("Sheet1", 3) |
| 1740 | + """ |
| 1741 | + lib.RemoveRow.restype = c_char_p |
| 1742 | + err = lib.RemoveRow(self.file_index, sheet.encode(ENCODE), c_int(row)).decode( |
| 1743 | + ENCODE |
| 1744 | + ) |
| 1745 | + return None if err == "" else Exception(err) |
| 1746 | + |
1653 | 1747 | def set_active_sheet(self, index: int) -> Optional[Exception]: |
1654 | 1748 | """ |
1655 | 1749 | Set the default active sheet of the workbook by a given index. Note that |
|
0 commit comments