File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -880,8 +880,26 @@ def get_formatted_cells(self) -> Iterable[ExcelCell]:
880880 def _num2excel (self , index : int ) -> str :
881881 """
882882 Convert 0-based column index to Excel column name.
883+
884+ Parameters
885+ ----------
886+ index : int
887+ The numeric column index to convert to a Excel column name.
888+
889+ Returns
890+ -------
891+ column_name : str
892+ The column name corresponding to the index.
893+
894+ Raises
895+ ------
896+ ValueError
897+ Index is negative
883898 """
899+ if index < 0 :
900+ raise ValueError (f"Index cannot be negative: { index } " )
884901 column_name = ""
902+ # while loop in case column name needs to be longer than 1 character
885903 while index > 0 or not column_name :
886904 index , remainder = divmod (index , 26 )
887905 column_name = chr (65 + remainder ) + column_name
You can’t perform that action at this time.
0 commit comments