Skip to content

Commit 023d402

Browse files
committed
Added unique return codes
The added return codes are from the workbook and worksheet classes Fixed SonarCloud issue and warnings
1 parent eac514b commit 023d402

File tree

9 files changed

+1613
-264
lines changed

9 files changed

+1613
-264
lines changed

dev/docs/source/page_setup.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,8 @@ worksheet.print_area()
571571
:type last_row: integer
572572
:type last_col: integer
573573

574-
:returns: 0: Success.
575-
:returns: -1: Row or column is out of worksheet bounds.
574+
:returns: ReturnCode.XW_NO_ERROR: Success.
575+
:returns: None : Max print area selected
576576

577577
This method is used to specify the area of the worksheet that will be printed.
578578

dev/docs/source/workbook.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,10 @@ workbook.set_custom_property()
531531
:type name: string
532532
:type property_type: string
533533

534+
:returns: XW_NO_ERROR: Success.
535+
:returns: XW_ERROR_INCORRECT_PARAMETER_OR_OPTION: Incorrect parameter or
536+
option.
537+
534538

535539
The ``set_custom_property()`` method can be used to set one or more custom
536540
document properties not covered by the standard properties in the
@@ -578,6 +582,10 @@ workbook.define_name()
578582
:param string name: The defined name.
579583
:param string formula: The cell or range that the defined name refers to.
580584

585+
:returns: XW_NO_ERROR: Success.
586+
:returns: XW_ERROR_INCORRECT_PARAMETER_OR_OPTION: Incorrect parameter or
587+
option.
588+
581589
This method is used to defined a name that can be used to represent a value, a
582590
single cell or a range of cells in a workbook. These are sometimes referred to
583591
as a "Named Range".

dev/docs/source/worksheet.rst

Lines changed: 130 additions & 68 deletions
Large diffs are not rendered by default.

examples/inheritance2.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from xlsxwriter.workbook import Workbook
1818
from xlsxwriter.worksheet import Worksheet
1919
from xlsxwriter.worksheet import convert_cell_args
20+
from xlsxwriter.returncodes import ReturnCode
2021

2122

2223
def excel_string_width(str):
@@ -48,7 +49,7 @@ def write_string(self, row, col, string, cell_format=None):
4849

4950
# Check that row and col are valid and store max and min values.
5051
if self._check_dimensions(row, col):
51-
return -1
52+
return ReturnCode.XW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE
5253

5354
# Set the min width for the cell. In some cases this might be the
5455
# default width of 8.43. In this case we use 0 and adjust for all

xlsxwriter/returncodes.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
###############################################################################
2+
#
3+
# ReturnCodes - A class for XlsxWriter return codes.
4+
#
5+
# SPDX-License-Identifier: BSD-2-Clause
6+
# Copyright 2013-2022, John McNamara, jmcnamara@cpan.org
7+
#
8+
9+
from enum import Enum
10+
11+
12+
class ReturnCode(str, Enum):
13+
"""Return codes enumeration for XlsxWriter functions
14+
15+
These values can be converted to string in different ways:
16+
- direct assignment: mystr = retcode
17+
- through format function: mystr = "Value {0}".format(retcode)
18+
- through f-string: mystr = f'Value {retcode}'
19+
20+
Conversion through str() function will result in the internal Enum
21+
representation, i.e. str(ReturnCode.XW_NO_ERROR) will return
22+
"ReturnCode.XW_NO_ERROR"
23+
"""
24+
25+
# Note: the following are not tuples, but strings on multiple lines
26+
# This is required to be compliant to E501
27+
28+
###########################################################################
29+
#
30+
# Values from libxlsxwriter library
31+
#
32+
###########################################################################
33+
34+
XW_NO_ERROR = "No error"
35+
XW_ERROR_MAX_STRING_LENGTH_EXCEEDED = ("String exceeds Excel's limit of "
36+
"32,767 characters")
37+
XW_ERROR_WORKSHEET_INDEX_OUT_OF_RANGE = ("Worksheet row or column index "
38+
"out of range")
39+
XW_ERROR_WORKSHEET_MAX_URL_LENGTH_EXCEEDED = ("Maximum hyperlink length "
40+
"(2079) exceeded")
41+
XW_ERROR_WORKSHEET_MAX_NUMBER_URLS_EXCEEDED = ("Maximum number of "
42+
"worksheet URLs (65530) "
43+
"exceeded")
44+
45+
###########################################################################
46+
#
47+
# Values added only for this library
48+
#
49+
###########################################################################
50+
51+
XW_ERROR_VBA_FILE_NOT_FOUND = "VBA project binary file not found"
52+
XW_ERROR_FORMULA_CANT_BE_NONE_OR_EMPTY = "Formula can't be None or empty"
53+
XW_ERROR_2_CONSECUTIVE_FORMATS = "2 consecutive formats used"
54+
XW_ERROR_EMPTY_STRING_USED = "Empty string used"
55+
XW_ERROR_INSUFFICIENT_PARAMETERS = "Insufficient parameters"
56+
XW_ERROR_IMAGE_FILE_NOT_FOUND = "Image file not found"
57+
XW_ERROR_INCORRECT_PARAMETER_OR_OPTION = "Incorrect parameter or option"
58+
XW_ERROR_NOT_SUPPORTED_COSTANT_MEMORY = ("Not supported in "
59+
"constant_memory mode")

0 commit comments

Comments
 (0)