Skip to content

Commit 6429588

Browse files
authored
adjust ErrColumnNumber, rename TotalColumns to MaxColumns and add new constant MinColumns (qax-os#1272)
Signed-off-by: Benjamin Lösch <loesch.benny92@gmx.de>
1 parent e37724c commit 6429588

8 files changed

+21
-26
lines changed

calc.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -1419,7 +1419,7 @@ func (f *File) parseReference(ctx *calcContext, sheet, reference string) (arg fo
14191419
err = newInvalidColumnNameError(tokens[1])
14201420
return
14211421
}
1422-
cr.Col = TotalColumns
1422+
cr.Col = MaxColumns
14231423
}
14241424
}
14251425
if refs.Len() > 0 {
@@ -1439,7 +1439,7 @@ func (f *File) parseReference(ctx *calcContext, sheet, reference string) (arg fo
14391439
err = newInvalidColumnNameError(tokens[0])
14401440
return
14411441
}
1442-
cr.Col = TotalColumns
1442+
cr.Col = MaxColumns
14431443
}
14441444
cellRanges.PushBack(cellRange{
14451445
From: cellRef{Sheet: sheet, Col: cr.Col, Row: 1},
@@ -14457,8 +14457,8 @@ func (fn *formulaFuncs) COLUMNS(argsList *list.List) formulaArg {
1445714457
return newErrorFormulaArg(formulaErrorVALUE, "COLUMNS requires 1 argument")
1445814458
}
1445914459
min, max := calcColumnsMinMax(argsList)
14460-
if max == TotalColumns {
14461-
return newNumberFormulaArg(float64(TotalColumns))
14460+
if max == MaxColumns {
14461+
return newNumberFormulaArg(float64(MaxColumns))
1446214462
}
1446314463
result := max - min + 1
1446414464
if max == min {

errors.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ func newInvalidStyleID(styleID int) error {
6161
// newFieldLengthError defined the error message on receiving the field length
6262
// overflow.
6363
func newFieldLengthError(name string) error {
64-
return fmt.Errorf("field %s must be less or equal than 255 characters", name)
64+
return fmt.Errorf("field %s must be less than or equal to 255 characters", name)
6565
}
6666

6767
// newCellNameToCoordinatesError defined the error message on converts
@@ -76,10 +76,10 @@ var (
7676
ErrStreamSetColWidth = errors.New("must call the SetColWidth function before the SetRow function")
7777
// ErrColumnNumber defined the error message on receive an invalid column
7878
// number.
79-
ErrColumnNumber = errors.New("column number exceeds maximum limit")
79+
ErrColumnNumber = fmt.Errorf(`the column number must be greater than or equal to %d and less than or equal to %d`, MinColumns, MaxColumns)
8080
// ErrColumnWidth defined the error message on receive an invalid column
8181
// width.
82-
ErrColumnWidth = fmt.Errorf("the width of the column must be smaller than or equal to %d characters", MaxColumnWidth)
82+
ErrColumnWidth = fmt.Errorf("the width of the column must be less than or equal to %d characters", MaxColumnWidth)
8383
// ErrOutlineLevel defined the error message on receive an invalid outline
8484
// level number.
8585
ErrOutlineLevel = errors.New("invalid outline level")
@@ -102,7 +102,7 @@ var (
102102
ErrMaxRows = errors.New("row number exceeds maximum limit")
103103
// ErrMaxRowHeight defined the error message on receive an invalid row
104104
// height.
105-
ErrMaxRowHeight = fmt.Errorf("the height of the row must be smaller than or equal to %d points", MaxRowHeight)
105+
ErrMaxRowHeight = fmt.Errorf("the height of the row must be less than or equal to %d points", MaxRowHeight)
106106
// ErrImgExt defined the error message on receive an unsupported image
107107
// extension.
108108
ErrImgExt = errors.New("unsupported image extension")
@@ -143,7 +143,7 @@ var (
143143
ErrCustomNumFmt = errors.New("custom number format can not be empty")
144144
// ErrFontLength defined the error message on the length of the font
145145
// family name overflow.
146-
ErrFontLength = fmt.Errorf("the length of the font family name must be smaller than or equal to %d", MaxFontFamilyLength)
146+
ErrFontLength = fmt.Errorf("the length of the font family name must be less than or equal to %d", MaxFontFamilyLength)
147147
// ErrFontSize defined the error message on the size of the font is invalid.
148148
ErrFontSize = fmt.Errorf("font size must be between %d and %d points", MinFontSize, MaxFontSize)
149149
// ErrSheetIdx defined the error message on receive the invalid worksheet

lib.go

+2-5
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func ColumnNameToNumber(name string) (int, error) {
211211
}
212212
multi *= 26
213213
}
214-
if col > TotalColumns {
214+
if col > MaxColumns {
215215
return -1, ErrColumnNumber
216216
}
217217
return col, nil
@@ -225,10 +225,7 @@ func ColumnNameToNumber(name string) (int, error) {
225225
// excelize.ColumnNumberToName(37) // returns "AK", nil
226226
//
227227
func ColumnNumberToName(num int) (string, error) {
228-
if num < 1 {
229-
return "", fmt.Errorf("incorrect column number %d", num)
230-
}
231-
if num > TotalColumns {
228+
if num < MinColumns || num > MaxColumns {
232229
return "", ErrColumnNumber
233230
}
234231
var col string

lib_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func TestColumnNameToNumber_Error(t *testing.T) {
7979
}
8080
}
8181
_, err := ColumnNameToNumber("XFE")
82-
assert.EqualError(t, err, ErrColumnNumber.Error())
82+
assert.ErrorIs(t, err, ErrColumnNumber)
8383
}
8484

8585
func TestColumnNumberToName_OK(t *testing.T) {
@@ -103,8 +103,8 @@ func TestColumnNumberToName_Error(t *testing.T) {
103103
assert.Equal(t, "", out)
104104
}
105105

106-
_, err = ColumnNumberToName(TotalColumns + 1)
107-
assert.EqualError(t, err, ErrColumnNumber.Error())
106+
_, err = ColumnNumberToName(MaxColumns + 1)
107+
assert.ErrorIs(t, err, ErrColumnNumber)
108108
}
109109

110110
func TestSplitCellName_OK(t *testing.T) {

sheet.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ func replaceRelationshipsBytes(content []byte) []byte {
256256

257257
// SetActiveSheet provides a function to set the default active sheet of the
258258
// workbook by a given index. Note that the active index is different from the
259-
// ID returned by function GetSheetMap(). It should be greater or equal to 0
259+
// ID returned by function GetSheetMap(). It should be greater than or equal to 0
260260
// and less than the total worksheet numbers.
261261
func (f *File) SetActiveSheet(index int) {
262262
if index < 0 {

stream.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -387,10 +387,7 @@ func (sw *StreamWriter) SetColWidth(min, max int, width float64) error {
387387
if sw.sheetWritten {
388388
return ErrStreamSetColWidth
389389
}
390-
if min > TotalColumns || max > TotalColumns {
391-
return ErrColumnNumber
392-
}
393-
if min < 1 || max < 1 {
390+
if min < MinColumns || min > MaxColumns || max < MinColumns || max > MaxColumns {
394391
return ErrColumnNumber
395392
}
396393
if width > MaxColumnWidth {

stream_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func TestStreamWriter(t *testing.T) {
7575
assert.NoError(t, file.SaveAs(filepath.Join("test", "TestStreamWriter.xlsx")))
7676

7777
// Test set cell column overflow.
78-
assert.EqualError(t, streamWriter.SetRow("XFD1", []interface{}{"A", "B", "C"}), ErrColumnNumber.Error())
78+
assert.ErrorIs(t, streamWriter.SetRow("XFD1", []interface{}{"A", "B", "C"}), ErrColumnNumber)
7979

8080
// Test close temporary file error.
8181
file = NewFile()
@@ -139,8 +139,8 @@ func TestStreamSetColWidth(t *testing.T) {
139139
streamWriter, err := file.NewStreamWriter("Sheet1")
140140
assert.NoError(t, err)
141141
assert.NoError(t, streamWriter.SetColWidth(3, 2, 20))
142-
assert.EqualError(t, streamWriter.SetColWidth(0, 3, 20), ErrColumnNumber.Error())
143-
assert.EqualError(t, streamWriter.SetColWidth(TotalColumns+1, 3, 20), ErrColumnNumber.Error())
142+
assert.ErrorIs(t, streamWriter.SetColWidth(0, 3, 20), ErrColumnNumber)
143+
assert.ErrorIs(t, streamWriter.SetColWidth(MaxColumns+1, 3, 20), ErrColumnNumber)
144144
assert.EqualError(t, streamWriter.SetColWidth(1, 3, MaxColumnWidth+1), ErrColumnWidth.Error())
145145
assert.NoError(t, streamWriter.SetRow("A1", []interface{}{"A", "B", "C"}))
146146
assert.EqualError(t, streamWriter.SetColWidth(2, 3, 20), ErrStreamSetColWidth.Error())

xmlDrawing.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ const (
109109
MaxRowHeight = 409
110110
MinFontSize = 1
111111
TotalRows = 1048576
112-
TotalColumns = 16384
112+
MinColumns = 1
113+
MaxColumns = 16384
113114
TotalSheetHyperlinks = 65529
114115
TotalCellChars = 32767
115116
// pivotTableVersion should be greater than 3. One or more of the

0 commit comments

Comments
 (0)