@@ -1359,6 +1359,18 @@ def copy_sheet(self, src: int, to: int) -> None:
13591359 Returns:
13601360 None: Return None if no error occurred, otherwise raise a
13611361 RuntimeError with the message.
1362+
1363+ Example:
1364+ For example:
1365+
1366+ ```python
1367+ try:
1368+ # Sheet1 already exists...
1369+ index = f.new_sheet("Sheet2")
1370+ f.copy_sheet(0, index)
1371+ except RuntimeError as err:
1372+ print(err)
1373+ ```
13621374 """
13631375 err , lib .CopySheet .restype = None , c_char_p
13641376 err = lib .CopySheet (self .file_index , src , to ).decode (ENCODE )
@@ -1504,6 +1516,16 @@ def duplicate_row(self, sheet: str, row: int) -> None:
15041516 Returns:
15051517 None: Return None if no error occurred, otherwise raise a
15061518 RuntimeError with the message.
1519+
1520+ Example:
1521+ For example:
1522+
1523+ ```python
1524+ try:
1525+ f.duplicate_row("Sheet1", 2)
1526+ except RuntimeError as err:
1527+ print(err)
1528+ ```
15071529 """
15081530 err , lib .DuplicateRow .restype = None , c_char_p
15091531 err = lib .DuplicateRow (self .file_index , sheet .encode (ENCODE ), row ).decode (
@@ -1529,6 +1551,16 @@ def duplicate_row_to(self, sheet: str, row: int, row2: int) -> None:
15291551 Returns:
15301552 None: Return None if no error occurred, otherwise raise a
15311553 RuntimeError with the message.
1554+
1555+ Example:
1556+ For example:
1557+
1558+ ```python
1559+ try:
1560+ f.duplicate_row_to("Sheet1", 2, 7)
1561+ except RuntimeError as err:
1562+ print(err)
1563+ ```
15321564 """
15331565 err , lib .DuplicateRowTo .restype = None , c_char_p
15341566 err = lib .DuplicateRowTo (
@@ -2016,8 +2048,8 @@ def get_sheet_index(self, sheet: str) -> int:
20162048
20172049 def get_sheet_list (self ) -> List [str ]:
20182050 """
2019- GetSheetList provides a function to get worksheets, chart sheets, and
2020- dialog sheets name list of the workbook.
2051+ Get worksheets, chart sheets, and dialog sheets name list of the
2052+ workbook.
20212053
20222054 Returns:
20232055 List[str]: Return the sheet name list if no error occurred,
@@ -2030,12 +2062,32 @@ def get_sheet_list(self) -> List[str]:
20302062
20312063 def get_sheet_map (self ) -> Dict [int , str ]:
20322064 """
2033- GetSheetMap provides a function to get worksheets, chart sheets, dialog
2034- sheets ID, and name maps of the workbook.
2065+ Get worksheets, chart sheets, dialog sheets ID, and name maps of the
2066+ workbook.
20352067
20362068 Returns:
20372069 Dict[int, str]: Return the sheet ID and name map if no error
20382070 occurred, otherwise return an empty dictionary.
2071+
2072+ Example:
2073+ For example:
2074+
2075+ ```python
2076+ try:
2077+ f = excelize.open_file("Book1.xlsx")
2078+ except RuntimeError as err:
2079+ print(err)
2080+ exit()
2081+ try:
2082+ for index, name in f.get_sheet_map().items():
2083+ print(index, name)
2084+ except RuntimeError as err:
2085+ print(err)
2086+ finally:
2087+ err = f.close()
2088+ if err:
2089+ print(err)
2090+ ```
20392091 """
20402092 lib .GetSheetMap .restype = types_go ._GetSheetMapResult
20412093 sheet_map = dict ()
@@ -2468,7 +2520,7 @@ def protect_workbook(self, opts: WorkbookProtectionOptions) -> None:
24682520 """
24692521 Prevent other users from viewing hidden worksheets, adding, moving,
24702522 deleting, or hiding worksheets, and renaming worksheets in a workbook.
2471- The optional field AlgorithmName specified hash algorithm, support XOR,
2523+ The optional field algorithm_name specified hash algorithm, support XOR,
24722524 MD4, MD5, SHA-1, SHA2-56, SHA-384, and SHA-512 currently, if no hash
24732525 algorithm specified, will be using the XOR algorithm as default. The
24742526 generated workbook only works on Microsoft Office 2007 and later.
@@ -3127,6 +3179,15 @@ def set_col_visible(self, sheet: str, columns: str, visible: bool) -> None:
31273179 except RuntimeError as err:
31283180 print(err)
31293181 ```
3182+
3183+ Hide the columns from `D` to `F` (included):
3184+
3185+ ```python
3186+ try:
3187+ f.set_col_visible("Sheet1", "D:F", False)
3188+ except RuntimeError as err:
3189+ print(err)
3190+ ```
31303191 """
31313192 lib .SetColVisible .restype = c_char_p
31323193 err = lib .SetColVisible (
@@ -3238,18 +3299,39 @@ def set_defined_name(self, defined_name: DefinedName) -> None:
32383299 RuntimeError with the message.
32393300
32403301 Example:
3241- For example, create a table of A1:D5 on Sheet1 :
3302+ For example:
32423303
32433304 ```python
3244- try:
3245- f.set_defined_name(excelize.DefinedName(
3246- name="Amount",
3247- refers_to="Sheet1!$A$2:$D$5",
3248- comment="defined name comment",
3249- scope="Sheet2",
3250- ))
3251- except RuntimeError as err:
3252- print(err)
3305+ f.set_defined_name(excelize.DefinedName(
3306+ name="Amount",
3307+ refers_to="Sheet1!$A$2:$D$5",
3308+ comment="defined name comment",
3309+ scope="Sheet2",
3310+ ))
3311+ ```
3312+
3313+ If you fill the `refers_to` property with only one columns range
3314+ without a comma, it will work as "Columns to repeat at left" only.
3315+ For example:
3316+
3317+ ```python
3318+ f.set_defined_name(excelize.DefinedName(
3319+ name="_xlnm.Print_Titles",
3320+ refers_to="Sheet1!$A:$A",
3321+ scope="Sheet1"
3322+ ))
3323+ ```
3324+
3325+ If you fill the `refers_to` property with only one rows range
3326+ without a comma, it will work as "Rows to repeat at top" only.
3327+ For example:
3328+
3329+ ```python
3330+ f.set_defined_name(excelize.DefinedName(
3331+ name="_xlnm.Print_Titles",
3332+ refers_to="Sheet1!$1:$1",
3333+ scope="Sheet1"
3334+ ))
32533335 ```
32543336 """
32553337 lib .SetDefinedName .restype = c_char_p
@@ -3279,11 +3361,11 @@ def set_doc_props(self, doc_properties: DocProperties) -> None:
32793361 category="category",
32803362 content_status="Draft",
32813363 created="2019-06-04T22:00:10Z",
3282- creator="Go Excelize",
3283- description="This file created by Go Excelize",
3364+ creator="Excelize for Python ",
3365+ description="This file created by Excelize for Python ",
32843366 identifier="xlsx",
32853367 keywords="Spreadsheet",
3286- last_modified_by="Go Author",
3368+ last_modified_by="Author Name ",
32873369 modified="2019-06-04T22:00:10Z",
32883370 revision="0",
32893371 subject="Test Subject",
@@ -3440,7 +3522,7 @@ def set_row_height(self, sheet: str, row: int, height: float) -> None:
34403522 def set_row_outline_level (self , sheet : str , row : int , level : int ) -> None :
34413523 """
34423524 Set outline level number of a single row by given worksheet name and
3443- Excel row number. The value of parameter 'level' is 1- 7.
3525+ row number. The range of `level` parameter value from 1 to 7.
34443526
34453527 Args:
34463528 sheet (str): The worksheet name
@@ -3609,6 +3691,17 @@ def set_sheet_col(
36093691 Returns:
36103692 None: Return None if no error occurred, otherwise raise a
36113693 RuntimeError with the message.
3694+
3695+ Example:
3696+ For example, writes an array to column `B` start with the cell `B6`
3697+ on `Sheet1`:
3698+
3699+ ```python
3700+ try:
3701+ f.set_sheet_col("Sheet1", "B6", ["1", None, 2])
3702+ except RuntimeError as err:
3703+ print(err)
3704+ ```
36123705 """
36133706 lib .SetSheetCol .restype = c_char_p
36143707 vals = (types_go ._Interface * len (values ))()
@@ -3713,6 +3806,17 @@ def set_sheet_row(
37133806 Returns:
37143807 None: Return None if no error occurred, otherwise raise a
37153808 RuntimeError with the message.
3809+
3810+ Example:
3811+ For example, writes an array to row `6` start with the cell `B6` on
3812+ `Sheet1`:
3813+
3814+ ```python
3815+ try:
3816+ f.set_sheet_row("Sheet1", "B6", ["1", None, 2])
3817+ except RuntimeError as err:
3818+ print(err)
3819+ ```
37163820 """
37173821 lib .SetSheetRow .restype = c_char_p
37183822 vals = (types_go ._Interface * len (values ))()
@@ -3765,6 +3869,13 @@ def set_sheet_visible(self, sheet: str, visible: bool, *very_hidden: bool) -> No
37653869 Returns:
37663870 None: Return None if no error occurred, otherwise raise a
37673871 RuntimeError with the message.
3872+
3873+ Example:
3874+ For example, hide `Sheet1`:
3875+
3876+ ```python
3877+ f.set_sheet_visible("Sheet1", False)
3878+ ```
37683879 """
37693880 lib .SetSheetVisible .restype = c_char_p
37703881 vh = False
@@ -3957,7 +4068,7 @@ def new_file() -> File:
39574068
39584069def open_file (filename : str , * opts : Options ) -> File :
39594070 """
3960- OpenFile take the name of a spreadsheet file and returns a populated
4071+ This function take the name of a spreadsheet file and returns a populated
39614072 spreadsheet file struct for it.
39624073
39634074 Args:
0 commit comments