|
| 1 | +# Data |
| 2 | + |
| 3 | +## Add slicer {#AddSlicer} |
| 4 | + |
| 5 | +`SlicerOptions` represents the settings of the slicer. |
| 6 | + |
| 7 | +```python |
| 8 | +class SlicerOptions: |
| 9 | + name: str = "" |
| 10 | + cell: str = "" |
| 11 | + table_sheet: str = "" |
| 12 | + table_name: str = "" |
| 13 | + caption: str = "" |
| 14 | + macro: str = "" |
| 15 | + width: int = 0 |
| 16 | + height: int = 0 |
| 17 | + display_header: Optional[bool] = None |
| 18 | + item_desc: bool = False |
| 19 | + format: GraphicOptions = GraphicOptions |
| 20 | +``` |
| 21 | + |
| 22 | +`name` specifies the slicer name, should be an existing field name of the given table or pivot table, this setting is required. |
| 23 | + |
| 24 | +`table` specifies the name of the table or pivot table, this setting is required. |
| 25 | + |
| 26 | +`cell` specifies the left top cell coordinates the position for inserting the slicer, this setting is required. |
| 27 | + |
| 28 | +`caption` specifies the caption of the slicer, this setting is optional. |
| 29 | + |
| 30 | +`macro` used for set macro for the slicer, the workbook extension should be XLSM or XLTM. |
| 31 | + |
| 32 | +`width` specifies the width of the slicer, this setting is optional. |
| 33 | + |
| 34 | +`height` specifies the height of the slicer, this setting is optional. |
| 35 | + |
| 36 | +`display_header` specifies if display header of the slicer, this setting is optional, the default setting is display. |
| 37 | + |
| 38 | +`item_desc` specifies descending (Z-A) item sorting, this setting is optional, and the default setting is `false` (represents ascending). |
| 39 | + |
| 40 | +`format` specifies the format of the slicer, this setting is optional. |
| 41 | + |
| 42 | +```python |
| 43 | +def add_slicer(self, sheet: str, opts: SlicerOptions) -> None |
| 44 | +``` |
| 45 | + |
| 46 | +Inserts a slicer by giving the worksheet name and slicer settings. For example, insert a slicer on the `Sheet1!E1` with field `Column1` for the table named `Table1`: |
| 47 | + |
| 48 | +```python |
| 49 | +try: |
| 50 | + f.add_slicer( |
| 51 | + "Sheet1", |
| 52 | + excelize.SlicerOptions( |
| 53 | + name="Column1", |
| 54 | + cell="E1", |
| 55 | + table_sheet="Sheet1", |
| 56 | + table_name="Table1", |
| 57 | + caption="Column1", |
| 58 | + width=200, |
| 59 | + height=200, |
| 60 | + ), |
| 61 | + ) |
| 62 | +except (RuntimeError, TypeError) as err: |
| 63 | + print(err) |
| 64 | +``` |
| 65 | + |
| 66 | +## Delete slicer {#DeleteSlicer} |
| 67 | + |
| 68 | +```python |
| 69 | +def delete_slicer(self, name: str) -> None |
| 70 | +``` |
| 71 | + |
| 72 | +Delete a slicer by a given slicer name. |
0 commit comments