adjust `ErrColumnNumber`, rename `TotalColumns` to `MaxColumns` and add new constant `MinColumns` (#1272)
Signed-off-by: Benjamin Lösch <loesch.benny92@gmx.de>
This commit is contained in:
parent
e37724c22b
commit
6429588e14
8
calc.go
8
calc.go
|
@ -1419,7 +1419,7 @@ func (f *File) parseReference(ctx *calcContext, sheet, reference string) (arg fo
|
|||
err = newInvalidColumnNameError(tokens[1])
|
||||
return
|
||||
}
|
||||
cr.Col = TotalColumns
|
||||
cr.Col = MaxColumns
|
||||
}
|
||||
}
|
||||
if refs.Len() > 0 {
|
||||
|
@ -1439,7 +1439,7 @@ func (f *File) parseReference(ctx *calcContext, sheet, reference string) (arg fo
|
|||
err = newInvalidColumnNameError(tokens[0])
|
||||
return
|
||||
}
|
||||
cr.Col = TotalColumns
|
||||
cr.Col = MaxColumns
|
||||
}
|
||||
cellRanges.PushBack(cellRange{
|
||||
From: cellRef{Sheet: sheet, Col: cr.Col, Row: 1},
|
||||
|
@ -14457,8 +14457,8 @@ func (fn *formulaFuncs) COLUMNS(argsList *list.List) formulaArg {
|
|||
return newErrorFormulaArg(formulaErrorVALUE, "COLUMNS requires 1 argument")
|
||||
}
|
||||
min, max := calcColumnsMinMax(argsList)
|
||||
if max == TotalColumns {
|
||||
return newNumberFormulaArg(float64(TotalColumns))
|
||||
if max == MaxColumns {
|
||||
return newNumberFormulaArg(float64(MaxColumns))
|
||||
}
|
||||
result := max - min + 1
|
||||
if max == min {
|
||||
|
|
10
errors.go
10
errors.go
|
@ -61,7 +61,7 @@ func newInvalidStyleID(styleID int) error {
|
|||
// newFieldLengthError defined the error message on receiving the field length
|
||||
// overflow.
|
||||
func newFieldLengthError(name string) error {
|
||||
return fmt.Errorf("field %s must be less or equal than 255 characters", name)
|
||||
return fmt.Errorf("field %s must be less than or equal to 255 characters", name)
|
||||
}
|
||||
|
||||
// newCellNameToCoordinatesError defined the error message on converts
|
||||
|
@ -76,10 +76,10 @@ var (
|
|||
ErrStreamSetColWidth = errors.New("must call the SetColWidth function before the SetRow function")
|
||||
// ErrColumnNumber defined the error message on receive an invalid column
|
||||
// number.
|
||||
ErrColumnNumber = errors.New("column number exceeds maximum limit")
|
||||
ErrColumnNumber = fmt.Errorf(`the column number must be greater than or equal to %d and less than or equal to %d`, MinColumns, MaxColumns)
|
||||
// ErrColumnWidth defined the error message on receive an invalid column
|
||||
// width.
|
||||
ErrColumnWidth = fmt.Errorf("the width of the column must be smaller than or equal to %d characters", MaxColumnWidth)
|
||||
ErrColumnWidth = fmt.Errorf("the width of the column must be less than or equal to %d characters", MaxColumnWidth)
|
||||
// ErrOutlineLevel defined the error message on receive an invalid outline
|
||||
// level number.
|
||||
ErrOutlineLevel = errors.New("invalid outline level")
|
||||
|
@ -102,7 +102,7 @@ var (
|
|||
ErrMaxRows = errors.New("row number exceeds maximum limit")
|
||||
// ErrMaxRowHeight defined the error message on receive an invalid row
|
||||
// height.
|
||||
ErrMaxRowHeight = fmt.Errorf("the height of the row must be smaller than or equal to %d points", MaxRowHeight)
|
||||
ErrMaxRowHeight = fmt.Errorf("the height of the row must be less than or equal to %d points", MaxRowHeight)
|
||||
// ErrImgExt defined the error message on receive an unsupported image
|
||||
// extension.
|
||||
ErrImgExt = errors.New("unsupported image extension")
|
||||
|
@ -143,7 +143,7 @@ var (
|
|||
ErrCustomNumFmt = errors.New("custom number format can not be empty")
|
||||
// ErrFontLength defined the error message on the length of the font
|
||||
// family name overflow.
|
||||
ErrFontLength = fmt.Errorf("the length of the font family name must be smaller than or equal to %d", MaxFontFamilyLength)
|
||||
ErrFontLength = fmt.Errorf("the length of the font family name must be less than or equal to %d", MaxFontFamilyLength)
|
||||
// ErrFontSize defined the error message on the size of the font is invalid.
|
||||
ErrFontSize = fmt.Errorf("font size must be between %d and %d points", MinFontSize, MaxFontSize)
|
||||
// ErrSheetIdx defined the error message on receive the invalid worksheet
|
||||
|
|
7
lib.go
7
lib.go
|
@ -211,7 +211,7 @@ func ColumnNameToNumber(name string) (int, error) {
|
|||
}
|
||||
multi *= 26
|
||||
}
|
||||
if col > TotalColumns {
|
||||
if col > MaxColumns {
|
||||
return -1, ErrColumnNumber
|
||||
}
|
||||
return col, nil
|
||||
|
@ -225,10 +225,7 @@ func ColumnNameToNumber(name string) (int, error) {
|
|||
// excelize.ColumnNumberToName(37) // returns "AK", nil
|
||||
//
|
||||
func ColumnNumberToName(num int) (string, error) {
|
||||
if num < 1 {
|
||||
return "", fmt.Errorf("incorrect column number %d", num)
|
||||
}
|
||||
if num > TotalColumns {
|
||||
if num < MinColumns || num > MaxColumns {
|
||||
return "", ErrColumnNumber
|
||||
}
|
||||
var col string
|
||||
|
|
|
@ -79,7 +79,7 @@ func TestColumnNameToNumber_Error(t *testing.T) {
|
|||
}
|
||||
}
|
||||
_, err := ColumnNameToNumber("XFE")
|
||||
assert.EqualError(t, err, ErrColumnNumber.Error())
|
||||
assert.ErrorIs(t, err, ErrColumnNumber)
|
||||
}
|
||||
|
||||
func TestColumnNumberToName_OK(t *testing.T) {
|
||||
|
@ -103,8 +103,8 @@ func TestColumnNumberToName_Error(t *testing.T) {
|
|||
assert.Equal(t, "", out)
|
||||
}
|
||||
|
||||
_, err = ColumnNumberToName(TotalColumns + 1)
|
||||
assert.EqualError(t, err, ErrColumnNumber.Error())
|
||||
_, err = ColumnNumberToName(MaxColumns + 1)
|
||||
assert.ErrorIs(t, err, ErrColumnNumber)
|
||||
}
|
||||
|
||||
func TestSplitCellName_OK(t *testing.T) {
|
||||
|
|
2
sheet.go
2
sheet.go
|
@ -256,7 +256,7 @@ func replaceRelationshipsBytes(content []byte) []byte {
|
|||
|
||||
// SetActiveSheet provides a function to set the default active sheet of the
|
||||
// workbook by a given index. Note that the active index is different from the
|
||||
// ID returned by function GetSheetMap(). It should be greater or equal to 0
|
||||
// ID returned by function GetSheetMap(). It should be greater than or equal to 0
|
||||
// and less than the total worksheet numbers.
|
||||
func (f *File) SetActiveSheet(index int) {
|
||||
if index < 0 {
|
||||
|
|
|
@ -387,10 +387,7 @@ func (sw *StreamWriter) SetColWidth(min, max int, width float64) error {
|
|||
if sw.sheetWritten {
|
||||
return ErrStreamSetColWidth
|
||||
}
|
||||
if min > TotalColumns || max > TotalColumns {
|
||||
return ErrColumnNumber
|
||||
}
|
||||
if min < 1 || max < 1 {
|
||||
if min < MinColumns || min > MaxColumns || max < MinColumns || max > MaxColumns {
|
||||
return ErrColumnNumber
|
||||
}
|
||||
if width > MaxColumnWidth {
|
||||
|
|
|
@ -75,7 +75,7 @@ func TestStreamWriter(t *testing.T) {
|
|||
assert.NoError(t, file.SaveAs(filepath.Join("test", "TestStreamWriter.xlsx")))
|
||||
|
||||
// Test set cell column overflow.
|
||||
assert.EqualError(t, streamWriter.SetRow("XFD1", []interface{}{"A", "B", "C"}), ErrColumnNumber.Error())
|
||||
assert.ErrorIs(t, streamWriter.SetRow("XFD1", []interface{}{"A", "B", "C"}), ErrColumnNumber)
|
||||
|
||||
// Test close temporary file error.
|
||||
file = NewFile()
|
||||
|
@ -139,8 +139,8 @@ func TestStreamSetColWidth(t *testing.T) {
|
|||
streamWriter, err := file.NewStreamWriter("Sheet1")
|
||||
assert.NoError(t, err)
|
||||
assert.NoError(t, streamWriter.SetColWidth(3, 2, 20))
|
||||
assert.EqualError(t, streamWriter.SetColWidth(0, 3, 20), ErrColumnNumber.Error())
|
||||
assert.EqualError(t, streamWriter.SetColWidth(TotalColumns+1, 3, 20), ErrColumnNumber.Error())
|
||||
assert.ErrorIs(t, streamWriter.SetColWidth(0, 3, 20), ErrColumnNumber)
|
||||
assert.ErrorIs(t, streamWriter.SetColWidth(MaxColumns+1, 3, 20), ErrColumnNumber)
|
||||
assert.EqualError(t, streamWriter.SetColWidth(1, 3, MaxColumnWidth+1), ErrColumnWidth.Error())
|
||||
assert.NoError(t, streamWriter.SetRow("A1", []interface{}{"A", "B", "C"}))
|
||||
assert.EqualError(t, streamWriter.SetColWidth(2, 3, 20), ErrStreamSetColWidth.Error())
|
||||
|
|
|
@ -109,7 +109,8 @@ const (
|
|||
MaxRowHeight = 409
|
||||
MinFontSize = 1
|
||||
TotalRows = 1048576
|
||||
TotalColumns = 16384
|
||||
MinColumns = 1
|
||||
MaxColumns = 16384
|
||||
TotalSheetHyperlinks = 65529
|
||||
TotalCellChars = 32767
|
||||
// pivotTableVersion should be greater than 3. One or more of the
|
||||
|
|
Loading…
Reference in New Issue