This sorted exported error constants by name and listed them in one place
This commit is contained in:
parent
c62d23e0a1
commit
1c23dc3507
2
cell.go
2
cell.go
|
@ -923,7 +923,7 @@ func (f *File) SetCellHyperLink(sheet, cell, link, linkType string, opts ...Hype
|
|||
Location: link,
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("invalid link type %q", linkType)
|
||||
return newInvalidLinkTypeError(linkType)
|
||||
}
|
||||
|
||||
for _, o := range opts {
|
||||
|
|
484
errors.go
484
errors.go
|
@ -16,64 +16,168 @@ import (
|
|||
"fmt"
|
||||
)
|
||||
|
||||
// newInvalidColumnNameError defined the error message on receiving the
|
||||
// invalid column name.
|
||||
func newInvalidColumnNameError(col string) error {
|
||||
return fmt.Errorf("invalid column name %q", col)
|
||||
var (
|
||||
// ErrAddVBAProject defined the error message on add the VBA project in
|
||||
// the workbook.
|
||||
ErrAddVBAProject = errors.New("unsupported VBA project")
|
||||
// ErrAttrValBool defined the error message on marshal and unmarshal
|
||||
// boolean type XML attribute.
|
||||
ErrAttrValBool = errors.New("unexpected child of attrValBool")
|
||||
// ErrCellCharsLength defined the error message for receiving a cell
|
||||
// characters length that exceeds the limit.
|
||||
ErrCellCharsLength = fmt.Errorf("cell value must be 0-%d characters", TotalCellChars)
|
||||
// ErrCellStyles defined the error message on cell styles exceeds the limit.
|
||||
ErrCellStyles = fmt.Errorf("the cell styles exceeds the %d limit", MaxCellStyles)
|
||||
// ErrColumnNumber defined the error message on receive an invalid column
|
||||
// number.
|
||||
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 less than or equal to %d characters", MaxColumnWidth)
|
||||
// ErrCoordinates defined the error message on invalid coordinates tuples
|
||||
// length.
|
||||
ErrCoordinates = errors.New("coordinates length must be 4")
|
||||
// ErrCustomNumFmt defined the error message on receive the empty custom number format.
|
||||
ErrCustomNumFmt = errors.New("custom number format can not be empty")
|
||||
// ErrDataValidationFormulaLength defined the error message for receiving a
|
||||
// data validation formula length that exceeds the limit.
|
||||
ErrDataValidationFormulaLength = fmt.Errorf("data validation must be 0-%d characters", MaxFieldLength)
|
||||
// ErrDataValidationRange defined the error message on set decimal range
|
||||
// exceeds limit.
|
||||
ErrDataValidationRange = errors.New("data validation range exceeds limit")
|
||||
// ErrDefinedNameDuplicate defined the error message on the same name
|
||||
// already exists on the scope.
|
||||
ErrDefinedNameDuplicate = errors.New("the same name already exists on the scope")
|
||||
// ErrDefinedNameScope defined the error message on not found defined name
|
||||
// in the given scope.
|
||||
ErrDefinedNameScope = errors.New("no defined name on the scope")
|
||||
// ErrExistsSheet defined the error message on given sheet already exists.
|
||||
ErrExistsSheet = errors.New("the same name sheet already exists")
|
||||
// ErrExistsTableName defined the error message on given table already exists.
|
||||
ErrExistsTableName = errors.New("the same name table already exists")
|
||||
// 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 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)
|
||||
// ErrFormControlValue defined the error message for receiving a scroll
|
||||
// value exceeds limit.
|
||||
ErrFormControlValue = fmt.Errorf("scroll value must be between 0 and %d", MaxFormControlValue)
|
||||
// ErrGroupSheets defined the error message on group sheets.
|
||||
ErrGroupSheets = errors.New("group worksheet must contain an active worksheet")
|
||||
// ErrImgExt defined the error message on receive an unsupported image
|
||||
// extension.
|
||||
ErrImgExt = errors.New("unsupported image extension")
|
||||
// ErrInvalidFormula defined the error message on receive an invalid
|
||||
// formula.
|
||||
ErrInvalidFormula = errors.New("formula not valid")
|
||||
// ErrMaxFilePathLength defined the error message on receive the file path
|
||||
// length overflow.
|
||||
ErrMaxFilePathLength = fmt.Errorf("file path length exceeds maximum limit %d characters", MaxFilePathLength)
|
||||
// ErrMaxRowHeight defined the error message on receive an invalid row
|
||||
// height.
|
||||
ErrMaxRowHeight = fmt.Errorf("the height of the row must be less than or equal to %d points", MaxRowHeight)
|
||||
// ErrMaxRows defined the error message on receive a row number exceeds maximum limit.
|
||||
ErrMaxRows = errors.New("row number exceeds maximum limit")
|
||||
// ErrNameLength defined the error message on receiving the defined name or
|
||||
// table name length exceeds the limit.
|
||||
ErrNameLength = fmt.Errorf("the name length exceeds the %d characters limit", MaxFieldLength)
|
||||
// ErrOptionsUnzipSizeLimit defined the error message for receiving
|
||||
// invalid UnzipSizeLimit and UnzipXMLSizeLimit.
|
||||
ErrOptionsUnzipSizeLimit = errors.New("the value of UnzipSizeLimit should be greater than or equal to UnzipXMLSizeLimit")
|
||||
// ErrOutlineLevel defined the error message on receive an invalid outline
|
||||
// level number.
|
||||
ErrOutlineLevel = errors.New("invalid outline level")
|
||||
// ErrParameterInvalid defined the error message on receive the invalid
|
||||
// parameter.
|
||||
ErrParameterInvalid = errors.New("parameter is invalid")
|
||||
// ErrParameterRequired defined the error message on receive the empty
|
||||
// parameter.
|
||||
ErrParameterRequired = errors.New("parameter is required")
|
||||
// ErrPasswordLengthInvalid defined the error message on invalid password
|
||||
// length.
|
||||
ErrPasswordLengthInvalid = errors.New("password length invalid")
|
||||
// ErrSave defined the error message for saving file.
|
||||
ErrSave = errors.New("no path defined for file, consider File.WriteTo or File.Write")
|
||||
// ErrSheetIdx defined the error message on receive the invalid worksheet
|
||||
// index.
|
||||
ErrSheetIdx = errors.New("invalid worksheet index")
|
||||
// ErrSheetNameBlank defined the error message on receive the blank sheet
|
||||
// name.
|
||||
ErrSheetNameBlank = errors.New("the sheet name can not be blank")
|
||||
// ErrSheetNameInvalid defined the error message on receive the sheet name
|
||||
// contains invalid characters.
|
||||
ErrSheetNameInvalid = errors.New("the sheet can not contain any of the characters :\\/?*[or]")
|
||||
// ErrSheetNameLength defined the error message on receiving the sheet
|
||||
// name length exceeds the limit.
|
||||
ErrSheetNameLength = fmt.Errorf("the sheet name length exceeds the %d characters limit", MaxSheetNameLength)
|
||||
// ErrSheetNameSingleQuote defined the error message on the first or last
|
||||
// character of the sheet name was a single quote.
|
||||
ErrSheetNameSingleQuote = errors.New("the first or last character of the sheet name can not be a single quote")
|
||||
// ErrSparkline defined the error message on receive the invalid sparkline
|
||||
// parameters.
|
||||
ErrSparkline = errors.New("must have the same number of 'Location' and 'Range' parameters")
|
||||
// ErrSparklineLocation defined the error message on missing Location
|
||||
// parameters
|
||||
ErrSparklineLocation = errors.New("parameter 'Location' is required")
|
||||
// ErrSparklineRange defined the error message on missing sparkline Range
|
||||
// parameters
|
||||
ErrSparklineRange = errors.New("parameter 'Range' is required")
|
||||
// ErrSparklineStyle defined the error message on receive the invalid
|
||||
// sparkline Style parameters.
|
||||
ErrSparklineStyle = errors.New("parameter 'Style' must between 0-35")
|
||||
// ErrSparklineType defined the error message on receive the invalid
|
||||
// sparkline Type parameters.
|
||||
ErrSparklineType = errors.New("parameter 'Type' must be 'line', 'column' or 'win_loss'")
|
||||
// ErrStreamSetColWidth defined the error message on set column width in
|
||||
// stream writing mode.
|
||||
ErrStreamSetColWidth = errors.New("must call the SetColWidth function before the SetRow function")
|
||||
// ErrStreamSetPanes defined the error message on set panes in stream
|
||||
// writing mode.
|
||||
ErrStreamSetPanes = errors.New("must call the SetPanes function before the SetRow function")
|
||||
// ErrTotalSheetHyperlinks defined the error message on hyperlinks count
|
||||
// overflow.
|
||||
ErrTotalSheetHyperlinks = errors.New("over maximum limit hyperlinks in a worksheet")
|
||||
// ErrUnknownEncryptMechanism defined the error message on unsupported
|
||||
// encryption mechanism.
|
||||
ErrUnknownEncryptMechanism = errors.New("unknown encryption mechanism")
|
||||
// ErrUnprotectSheet defined the error message on worksheet has set no
|
||||
// protection.
|
||||
ErrUnprotectSheet = errors.New("worksheet has set no protect")
|
||||
// ErrUnprotectSheetPassword defined the error message on remove sheet
|
||||
// protection with password verification failed.
|
||||
ErrUnprotectSheetPassword = errors.New("worksheet protect password not match")
|
||||
// ErrUnprotectWorkbook defined the error message on workbook has set no
|
||||
// protection.
|
||||
ErrUnprotectWorkbook = errors.New("workbook has set no protect")
|
||||
// ErrUnprotectWorkbookPassword defined the error message on remove workbook
|
||||
// protection with password verification failed.
|
||||
ErrUnprotectWorkbookPassword = errors.New("workbook protect password not match")
|
||||
// ErrUnsupportedEncryptMechanism defined the error message on unsupported
|
||||
// encryption mechanism.
|
||||
ErrUnsupportedEncryptMechanism = errors.New("unsupported encryption mechanism")
|
||||
// ErrUnsupportedHashAlgorithm defined the error message on unsupported
|
||||
// hash algorithm.
|
||||
ErrUnsupportedHashAlgorithm = errors.New("unsupported hash algorithm")
|
||||
// ErrUnsupportedNumberFormat defined the error message on unsupported number format
|
||||
// expression.
|
||||
ErrUnsupportedNumberFormat = errors.New("unsupported number format token")
|
||||
// ErrWorkbookFileFormat defined the error message on receive an
|
||||
// unsupported workbook file format.
|
||||
ErrWorkbookFileFormat = errors.New("unsupported workbook file format")
|
||||
// ErrWorkbookPassword defined the error message on receiving the incorrect
|
||||
// workbook password.
|
||||
ErrWorkbookPassword = errors.New("the supplied open workbook password is not correct")
|
||||
)
|
||||
|
||||
// ErrSheetNotExist defined an error of sheet that does not exist.
|
||||
type ErrSheetNotExist struct {
|
||||
SheetName string
|
||||
}
|
||||
|
||||
// newInvalidRowNumberError defined the error message on receiving the invalid
|
||||
// row number.
|
||||
func newInvalidRowNumberError(row int) error {
|
||||
return fmt.Errorf("invalid row number %d", row)
|
||||
}
|
||||
|
||||
// newInvalidCellNameError defined the error message on receiving the invalid
|
||||
// cell name.
|
||||
func newInvalidCellNameError(cell string) error {
|
||||
return fmt.Errorf("invalid cell name %q", cell)
|
||||
}
|
||||
|
||||
// newInvalidSlicerNameError defined the error message on receiving the invalid
|
||||
// slicer name.
|
||||
func newInvalidSlicerNameError(name string) error {
|
||||
return fmt.Errorf("invalid slicer name %q", name)
|
||||
}
|
||||
|
||||
// newInvalidExcelDateError defined the error message on receiving the data
|
||||
// with negative values.
|
||||
func newInvalidExcelDateError(dateValue float64) error {
|
||||
return fmt.Errorf("invalid date value %f, negative values are not supported", dateValue)
|
||||
}
|
||||
|
||||
// newInvalidNameError defined the error message on receiving the invalid
|
||||
// defined name or table name.
|
||||
func newInvalidNameError(name string) error {
|
||||
return fmt.Errorf("invalid name %q, the name should be starts with a letter or underscore, can not include a space or character, and can not conflict with an existing name in the workbook", name)
|
||||
}
|
||||
|
||||
// newUnsupportedChartType defined the error message on receiving the chart
|
||||
// type are unsupported.
|
||||
func newUnsupportedChartType(chartType ChartType) error {
|
||||
return fmt.Errorf("unsupported chart type %d", chartType)
|
||||
}
|
||||
|
||||
// newUnzipSizeLimitError defined the error message on unzip size exceeds the
|
||||
// limit.
|
||||
func newUnzipSizeLimitError(unzipSizeLimit int64) error {
|
||||
return fmt.Errorf("unzip size exceeds the %d bytes limit", unzipSizeLimit)
|
||||
}
|
||||
|
||||
// newInvalidStyleID defined the error message on receiving the invalid style
|
||||
// ID.
|
||||
func newInvalidStyleID(styleID int) error {
|
||||
return fmt.Errorf("invalid style ID %d", styleID)
|
||||
}
|
||||
|
||||
// newFieldLengthError defined the error message on receiving the field length
|
||||
// overflow.
|
||||
func newFieldLengthError(name string) error {
|
||||
return fmt.Errorf("field %s must be less than or equal to 255 characters", name)
|
||||
// Error returns the error message on receiving the non existing sheet name.
|
||||
func (err ErrSheetNotExist) Error() string {
|
||||
return fmt.Sprintf("sheet %s does not exist", err.SheetName)
|
||||
}
|
||||
|
||||
// newCellNameToCoordinatesError defined the error message on converts
|
||||
|
@ -82,10 +186,82 @@ func newCellNameToCoordinatesError(cell string, err error) error {
|
|||
return fmt.Errorf("cannot convert cell %q to coordinates: %v", cell, err)
|
||||
}
|
||||
|
||||
// newNoExistSheetError defined the error message on receiving the non existing
|
||||
// sheet name.
|
||||
func newNoExistSheetError(name string) error {
|
||||
return fmt.Errorf("sheet %s does not exist", name)
|
||||
// newCoordinatesToCellNameError defined the error message on converts [X, Y]
|
||||
// coordinates to alpha-numeric cell name.
|
||||
func newCoordinatesToCellNameError(col, row int) error {
|
||||
return fmt.Errorf("invalid cell reference [%d, %d]", col, row)
|
||||
}
|
||||
|
||||
// newFieldLengthError defined the error message on receiving the field length
|
||||
// overflow.
|
||||
func newFieldLengthError(name string) error {
|
||||
return fmt.Errorf("field %s must be less than or equal to 255 characters", name)
|
||||
}
|
||||
|
||||
// newInvalidAutoFilterColumnError defined the error message on receiving the
|
||||
// incorrect index of column.
|
||||
func newInvalidAutoFilterColumnError(col string) error {
|
||||
return fmt.Errorf("incorrect index of column %q", col)
|
||||
}
|
||||
|
||||
// newInvalidAutoFilterExpError defined the error message on receiving the
|
||||
// incorrect number of tokens in criteria expression.
|
||||
func newInvalidAutoFilterExpError(exp string) error {
|
||||
return fmt.Errorf("incorrect number of tokens in criteria %q", exp)
|
||||
}
|
||||
|
||||
// newInvalidAutoFilterOperatorError defined the error message on receiving the
|
||||
// incorrect expression operator.
|
||||
func newInvalidAutoFilterOperatorError(op, exp string) error {
|
||||
return fmt.Errorf("the operator %q in expression %q is not valid in relation to Blanks/NonBlanks", op, exp)
|
||||
}
|
||||
|
||||
// newInvalidCellNameError defined the error message on receiving the invalid
|
||||
// cell name.
|
||||
func newInvalidCellNameError(cell string) error {
|
||||
return fmt.Errorf("invalid cell name %q", cell)
|
||||
}
|
||||
|
||||
// newInvalidColumnNameError defined the error message on receiving the
|
||||
// invalid column name.
|
||||
func newInvalidColumnNameError(col string) error {
|
||||
return fmt.Errorf("invalid column name %q", col)
|
||||
}
|
||||
|
||||
// newInvalidExcelDateError defined the error message on receiving the data
|
||||
// with negative values.
|
||||
func newInvalidExcelDateError(dateValue float64) error {
|
||||
return fmt.Errorf("invalid date value %f, negative values are not supported", dateValue)
|
||||
}
|
||||
|
||||
// newInvalidLinkTypeError defined the error message on receiving the invalid
|
||||
// hyper link type.
|
||||
func newInvalidLinkTypeError(linkType string) error {
|
||||
return fmt.Errorf("invalid link type %q", linkType)
|
||||
}
|
||||
|
||||
// newInvalidNameError defined the error message on receiving the invalid
|
||||
// defined name or table name.
|
||||
func newInvalidNameError(name string) error {
|
||||
return fmt.Errorf("invalid name %q, the name should be starts with a letter or underscore, can not include a space or character, and can not conflict with an existing name in the workbook", name)
|
||||
}
|
||||
|
||||
// newInvalidRowNumberError defined the error message on receiving the invalid
|
||||
// row number.
|
||||
func newInvalidRowNumberError(row int) error {
|
||||
return fmt.Errorf("invalid row number %d", row)
|
||||
}
|
||||
|
||||
// newInvalidSlicerNameError defined the error message on receiving the invalid
|
||||
// slicer name.
|
||||
func newInvalidSlicerNameError(name string) error {
|
||||
return fmt.Errorf("invalid slicer name %q", name)
|
||||
}
|
||||
|
||||
// newInvalidStyleID defined the error message on receiving the invalid style
|
||||
// ID.
|
||||
func newInvalidStyleID(styleID int) error {
|
||||
return fmt.Errorf("invalid style ID %d", styleID)
|
||||
}
|
||||
|
||||
// newNoExistTableError defined the error message on receiving the non existing
|
||||
|
@ -100,174 +276,44 @@ func newNotWorksheetError(name string) error {
|
|||
return fmt.Errorf("sheet %s is not a worksheet", name)
|
||||
}
|
||||
|
||||
// newPivotTableDataRangeError defined the error message on receiving the
|
||||
// invalid pivot table data range.
|
||||
func newPivotTableDataRangeError(msg string) error {
|
||||
return fmt.Errorf("parameter 'DataRange' parsing error: %s", msg)
|
||||
}
|
||||
|
||||
// newPivotTableRangeError defined the error message on receiving the invalid
|
||||
// pivot table range.
|
||||
func newPivotTableRangeError(msg string) error {
|
||||
return fmt.Errorf("parameter 'PivotTableRange' parsing error: %s", msg)
|
||||
}
|
||||
|
||||
// newStreamSetRowError defined the error message on the stream writer
|
||||
// receiving the non-ascending row number.
|
||||
func newStreamSetRowError(row int) error {
|
||||
return fmt.Errorf("row %d has already been written", row)
|
||||
}
|
||||
|
||||
// newViewIdxError defined the error message on receiving a invalid sheet view
|
||||
// index.
|
||||
func newViewIdxError(viewIndex int) error {
|
||||
return fmt.Errorf("view index %d out of range", viewIndex)
|
||||
}
|
||||
|
||||
// newUnknownFilterTokenError defined the error message on receiving a unknown
|
||||
// filter operator token.
|
||||
func newUnknownFilterTokenError(token string) error {
|
||||
return fmt.Errorf("unknown operator: %s", token)
|
||||
}
|
||||
|
||||
var (
|
||||
// ErrStreamSetColWidth defined the error message on set column width in
|
||||
// stream writing mode.
|
||||
ErrStreamSetColWidth = errors.New("must call the SetColWidth function before the SetRow function")
|
||||
// ErrStreamSetPanes defined the error message on set panes in stream
|
||||
// writing mode.
|
||||
ErrStreamSetPanes = errors.New("must call the SetPanes function before the SetRow function")
|
||||
// ErrColumnNumber defined the error message on receive an invalid column
|
||||
// number.
|
||||
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 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")
|
||||
// ErrCoordinates defined the error message on invalid coordinates tuples
|
||||
// length.
|
||||
ErrCoordinates = errors.New("coordinates length must be 4")
|
||||
// ErrExistsSheet defined the error message on given sheet already exists.
|
||||
ErrExistsSheet = errors.New("the same name sheet already exists")
|
||||
// ErrTotalSheetHyperlinks defined the error message on hyperlinks count
|
||||
// overflow.
|
||||
ErrTotalSheetHyperlinks = errors.New("over maximum limit hyperlinks in a worksheet")
|
||||
// ErrInvalidFormula defined the error message on receive an invalid
|
||||
// formula.
|
||||
ErrInvalidFormula = errors.New("formula not valid")
|
||||
// ErrAddVBAProject defined the error message on add the VBA project in
|
||||
// the workbook.
|
||||
ErrAddVBAProject = errors.New("unsupported VBA project")
|
||||
// ErrMaxRows defined the error message on receive a row number exceeds maximum limit.
|
||||
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 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")
|
||||
// ErrWorkbookFileFormat defined the error message on receive an
|
||||
// unsupported workbook file format.
|
||||
ErrWorkbookFileFormat = errors.New("unsupported workbook file format")
|
||||
// ErrMaxFilePathLength defined the error message on receive the file path
|
||||
// length overflow.
|
||||
ErrMaxFilePathLength = fmt.Errorf("file path length exceeds maximum limit %d characters", MaxFilePathLength)
|
||||
// ErrUnknownEncryptMechanism defined the error message on unsupported
|
||||
// encryption mechanism.
|
||||
ErrUnknownEncryptMechanism = errors.New("unknown encryption mechanism")
|
||||
// ErrUnsupportedEncryptMechanism defined the error message on unsupported
|
||||
// encryption mechanism.
|
||||
ErrUnsupportedEncryptMechanism = errors.New("unsupported encryption mechanism")
|
||||
// ErrUnsupportedHashAlgorithm defined the error message on unsupported
|
||||
// hash algorithm.
|
||||
ErrUnsupportedHashAlgorithm = errors.New("unsupported hash algorithm")
|
||||
// ErrUnsupportedNumberFormat defined the error message on unsupported number format
|
||||
// expression.
|
||||
ErrUnsupportedNumberFormat = errors.New("unsupported number format token")
|
||||
// ErrPasswordLengthInvalid defined the error message on invalid password
|
||||
// length.
|
||||
ErrPasswordLengthInvalid = errors.New("password length invalid")
|
||||
// ErrParameterRequired defined the error message on receive the empty
|
||||
// parameter.
|
||||
ErrParameterRequired = errors.New("parameter is required")
|
||||
// ErrParameterInvalid defined the error message on receive the invalid
|
||||
// parameter.
|
||||
ErrParameterInvalid = errors.New("parameter is invalid")
|
||||
// ErrDefinedNameScope defined the error message on not found defined name
|
||||
// in the given scope.
|
||||
ErrDefinedNameScope = errors.New("no defined name on the scope")
|
||||
// ErrDefinedNameDuplicate defined the error message on the same name
|
||||
// already exists on the scope.
|
||||
ErrDefinedNameDuplicate = errors.New("the same name already exists on the scope")
|
||||
// ErrCustomNumFmt defined the error message on receive the empty custom number format.
|
||||
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 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
|
||||
// index.
|
||||
ErrSheetIdx = errors.New("invalid worksheet index")
|
||||
// ErrUnprotectSheet defined the error message on worksheet has set no
|
||||
// protection.
|
||||
ErrUnprotectSheet = errors.New("worksheet has set no protect")
|
||||
// ErrUnprotectSheetPassword defined the error message on remove sheet
|
||||
// protection with password verification failed.
|
||||
ErrUnprotectSheetPassword = errors.New("worksheet protect password not match")
|
||||
// ErrGroupSheets defined the error message on group sheets.
|
||||
ErrGroupSheets = errors.New("group worksheet must contain an active worksheet")
|
||||
// ErrDataValidationFormulaLength defined the error message for receiving a
|
||||
// data validation formula length that exceeds the limit.
|
||||
ErrDataValidationFormulaLength = fmt.Errorf("data validation must be 0-%d characters", MaxFieldLength)
|
||||
// ErrDataValidationRange defined the error message on set decimal range
|
||||
// exceeds limit.
|
||||
ErrDataValidationRange = errors.New("data validation range exceeds limit")
|
||||
// ErrCellCharsLength defined the error message for receiving a cell
|
||||
// characters length that exceeds the limit.
|
||||
ErrCellCharsLength = fmt.Errorf("cell value must be 0-%d characters", TotalCellChars)
|
||||
// ErrOptionsUnzipSizeLimit defined the error message for receiving
|
||||
// invalid UnzipSizeLimit and UnzipXMLSizeLimit.
|
||||
ErrOptionsUnzipSizeLimit = errors.New("the value of UnzipSizeLimit should be greater than or equal to UnzipXMLSizeLimit")
|
||||
// ErrSave defined the error message for saving file.
|
||||
ErrSave = errors.New("no path defined for file, consider File.WriteTo or File.Write")
|
||||
// ErrAttrValBool defined the error message on marshal and unmarshal
|
||||
// boolean type XML attribute.
|
||||
ErrAttrValBool = errors.New("unexpected child of attrValBool")
|
||||
// ErrSparklineType defined the error message on receive the invalid
|
||||
// sparkline Type parameters.
|
||||
ErrSparklineType = errors.New("parameter 'Type' must be 'line', 'column' or 'win_loss'")
|
||||
// ErrSparklineLocation defined the error message on missing Location
|
||||
// parameters
|
||||
ErrSparklineLocation = errors.New("parameter 'Location' is required")
|
||||
// ErrSparklineRange defined the error message on missing sparkline Range
|
||||
// parameters
|
||||
ErrSparklineRange = errors.New("parameter 'Range' is required")
|
||||
// ErrSparkline defined the error message on receive the invalid sparkline
|
||||
// parameters.
|
||||
ErrSparkline = errors.New("must have the same number of 'Location' and 'Range' parameters")
|
||||
// ErrSparklineStyle defined the error message on receive the invalid
|
||||
// sparkline Style parameters.
|
||||
ErrSparklineStyle = errors.New("parameter 'Style' must between 0-35")
|
||||
// ErrWorkbookPassword defined the error message on receiving the incorrect
|
||||
// workbook password.
|
||||
ErrWorkbookPassword = errors.New("the supplied open workbook password is not correct")
|
||||
// ErrSheetNameInvalid defined the error message on receive the sheet name
|
||||
// contains invalid characters.
|
||||
ErrSheetNameInvalid = errors.New("the sheet can not contain any of the characters :\\/?*[or]")
|
||||
// ErrSheetNameSingleQuote defined the error message on the first or last
|
||||
// character of the sheet name was a single quote.
|
||||
ErrSheetNameSingleQuote = errors.New("the first or last character of the sheet name can not be a single quote")
|
||||
// ErrSheetNameBlank defined the error message on receive the blank sheet
|
||||
// name.
|
||||
ErrSheetNameBlank = errors.New("the sheet name can not be blank")
|
||||
// ErrSheetNameLength defined the error message on receiving the sheet
|
||||
// name length exceeds the limit.
|
||||
ErrSheetNameLength = fmt.Errorf("the sheet name length exceeds the %d characters limit", MaxSheetNameLength)
|
||||
// ErrNameLength defined the error message on receiving the defined name or
|
||||
// table name length exceeds the limit.
|
||||
ErrNameLength = fmt.Errorf("the name length exceeds the %d characters limit", MaxFieldLength)
|
||||
// ErrExistsTableName defined the error message on given table already exists.
|
||||
ErrExistsTableName = errors.New("the same name table already exists")
|
||||
// ErrCellStyles defined the error message on cell styles exceeds the limit.
|
||||
ErrCellStyles = fmt.Errorf("the cell styles exceeds the %d limit", MaxCellStyles)
|
||||
// ErrUnprotectWorkbook defined the error message on workbook has set no
|
||||
// protection.
|
||||
ErrUnprotectWorkbook = errors.New("workbook has set no protect")
|
||||
// ErrUnprotectWorkbookPassword defined the error message on remove workbook
|
||||
// protection with password verification failed.
|
||||
ErrUnprotectWorkbookPassword = errors.New("workbook protect password not match")
|
||||
// ErrorFormControlValue defined the error message for receiving a scroll
|
||||
// value exceeds limit.
|
||||
ErrorFormControlValue = fmt.Errorf("scroll value must be between 0 and %d", MaxFormControlValue)
|
||||
)
|
||||
// newUnsupportedChartType defined the error message on receiving the chart
|
||||
// type are unsupported.
|
||||
func newUnsupportedChartType(chartType ChartType) error {
|
||||
return fmt.Errorf("unsupported chart type %d", chartType)
|
||||
}
|
||||
|
||||
// newUnzipSizeLimitError defined the error message on unzip size exceeds the
|
||||
// limit.
|
||||
func newUnzipSizeLimitError(unzipSizeLimit int64) error {
|
||||
return fmt.Errorf("unzip size exceeds the %d bytes limit", unzipSizeLimit)
|
||||
}
|
||||
|
||||
// newViewIdxError defined the error message on receiving a invalid sheet view
|
||||
// index.
|
||||
func newViewIdxError(viewIndex int) error {
|
||||
return fmt.Errorf("view index %d out of range", viewIndex)
|
||||
}
|
||||
|
|
|
@ -261,7 +261,7 @@ func (f *File) workSheetReader(sheet string) (ws *xlsxWorksheet, err error) {
|
|||
return
|
||||
}
|
||||
if name, ok = f.getSheetXMLPath(sheet); !ok {
|
||||
err = newNoExistSheetError(sheet)
|
||||
err = ErrSheetNotExist{sheet}
|
||||
return
|
||||
}
|
||||
if worksheet, ok := f.Sheet.Load(name); ok && worksheet != nil {
|
||||
|
|
|
@ -399,8 +399,8 @@ func TestSetCellHyperLink(t *testing.T) {
|
|||
Tooltip: &tooltip,
|
||||
}))
|
||||
// Test set cell hyperlink with invalid sheet name
|
||||
assert.EqualError(t, f.SetCellHyperLink("Sheet:1", "A1", "Sheet1!D60", "Location"), ErrSheetNameInvalid.Error())
|
||||
assert.EqualError(t, f.SetCellHyperLink("Sheet2", "C3", "Sheet1!D8", ""), `invalid link type ""`)
|
||||
assert.Equal(t, ErrSheetNameInvalid, f.SetCellHyperLink("Sheet:1", "A1", "Sheet1!D60", "Location"))
|
||||
assert.Equal(t, newInvalidLinkTypeError(""), f.SetCellHyperLink("Sheet2", "C3", "Sheet1!D8", ""))
|
||||
assert.EqualError(t, f.SetCellHyperLink("Sheet2", "", "Sheet1!D60", "Location"), `invalid cell name ""`)
|
||||
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetCellHyperLink.xlsx")))
|
||||
assert.NoError(t, f.Close())
|
||||
|
@ -1236,7 +1236,7 @@ func TestConditionalFormat(t *testing.T) {
|
|||
// Test create conditional format with invalid custom number format
|
||||
var exp string
|
||||
_, err = f.NewConditionalStyle(&Style{CustomNumFmt: &exp})
|
||||
assert.EqualError(t, err, ErrCustomNumFmt.Error())
|
||||
assert.Equal(t, ErrCustomNumFmt, err)
|
||||
|
||||
// Set conditional format with file without dxfs element should not return error
|
||||
f, err = OpenFile(filepath.Join("test", "Book1.xlsx"))
|
||||
|
|
2
lib.go
2
lib.go
|
@ -261,7 +261,7 @@ func CellNameToCoordinates(cell string) (int, int, error) {
|
|||
// excelize.CoordinatesToCellName(1, 1, true) // returns "$A$1", nil
|
||||
func CoordinatesToCellName(col, row int, abs ...bool) (string, error) {
|
||||
if col < 1 || row < 1 {
|
||||
return "", fmt.Errorf("invalid cell reference [%d, %d]", col, row)
|
||||
return "", newCoordinatesToCellNameError(col, row)
|
||||
}
|
||||
sign := ""
|
||||
for _, a := range abs {
|
||||
|
|
|
@ -222,9 +222,9 @@ func TestCoordinatesToRangeRef(t *testing.T) {
|
|||
_, err := f.coordinatesToRangeRef([]int{})
|
||||
assert.EqualError(t, err, ErrCoordinates.Error())
|
||||
_, err = f.coordinatesToRangeRef([]int{1, -1, 1, 1})
|
||||
assert.EqualError(t, err, "invalid cell reference [1, -1]")
|
||||
assert.Equal(t, newCoordinatesToCellNameError(1, -1), err)
|
||||
_, err = f.coordinatesToRangeRef([]int{1, 1, 1, -1})
|
||||
assert.EqualError(t, err, "invalid cell reference [1, -1]")
|
||||
assert.Equal(t, newCoordinatesToCellNameError(1, -1), err)
|
||||
ref, err := f.coordinatesToRangeRef([]int{1, 1, 1, 1})
|
||||
assert.NoError(t, err)
|
||||
assert.EqualValues(t, ref, "A1:A1")
|
||||
|
|
|
@ -189,7 +189,7 @@ func (f *File) parseFormatPivotTableSet(opts *PivotTableOptions) (*xlsxWorksheet
|
|||
}
|
||||
pivotTableSheetName, _, err := f.adjustRange(opts.PivotTableRange)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("parameter 'PivotTableRange' parsing error: %s", err.Error())
|
||||
return nil, "", newPivotTableRangeError(err.Error())
|
||||
}
|
||||
if len(opts.Name) > MaxFieldLength {
|
||||
return nil, "", ErrNameLength
|
||||
|
@ -201,7 +201,7 @@ func (f *File) parseFormatPivotTableSet(opts *PivotTableOptions) (*xlsxWorksheet
|
|||
}
|
||||
dataSheetName, _, err := f.adjustRange(dataRange)
|
||||
if err != nil {
|
||||
return nil, "", fmt.Errorf("parameter 'DataRange' parsing error: %s", err.Error())
|
||||
return nil, "", newPivotTableDataRangeError(err.Error())
|
||||
}
|
||||
dataSheet, err := f.workSheetReader(dataSheetName)
|
||||
if err != nil {
|
||||
|
@ -209,7 +209,7 @@ func (f *File) parseFormatPivotTableSet(opts *PivotTableOptions) (*xlsxWorksheet
|
|||
}
|
||||
pivotTableSheetPath, ok := f.getSheetXMLPath(pivotTableSheetName)
|
||||
if !ok {
|
||||
return dataSheet, pivotTableSheetPath, fmt.Errorf("sheet %s does not exist", pivotTableSheetName)
|
||||
return dataSheet, pivotTableSheetPath, ErrSheetNotExist{pivotTableSheetName}
|
||||
}
|
||||
return dataSheet, pivotTableSheetPath, err
|
||||
}
|
||||
|
@ -254,7 +254,7 @@ func (f *File) getTableFieldsOrder(sheetName, dataRange string) ([]string, error
|
|||
}
|
||||
dataSheet, coordinates, err := f.adjustRange(ref)
|
||||
if err != nil {
|
||||
return order, fmt.Errorf("parameter 'DataRange' parsing error: %s", err.Error())
|
||||
return order, newPivotTableDataRangeError(err.Error())
|
||||
}
|
||||
for col := coordinates[0]; col <= coordinates[2]; col++ {
|
||||
coordinate, _ := CoordinatesToCellName(col, coordinates[1])
|
||||
|
@ -278,7 +278,7 @@ func (f *File) addPivotCache(pivotCacheXML string, opts *PivotTableOptions) erro
|
|||
}
|
||||
dataSheet, coordinates, err := f.adjustRange(dataRange)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parameter 'DataRange' parsing error: %s", err.Error())
|
||||
return newPivotTableDataRangeError(err.Error())
|
||||
}
|
||||
// data range has been checked
|
||||
order, _ := f.getTableFieldsOrder(opts.pivotTableSheetName, opts.DataRange)
|
||||
|
@ -320,7 +320,7 @@ func (f *File) addPivotTable(cacheID, pivotTableID int, pivotTableXML string, op
|
|||
// validate pivot table range
|
||||
_, coordinates, err := f.adjustRange(opts.PivotTableRange)
|
||||
if err != nil {
|
||||
return fmt.Errorf("parameter 'PivotTableRange' parsing error: %s", err.Error())
|
||||
return newPivotTableRangeError(err.Error())
|
||||
}
|
||||
|
||||
hCell, _ := CoordinatesToCellName(coordinates[0], coordinates[1])
|
||||
|
@ -727,7 +727,7 @@ func (f *File) GetPivotTables(sheet string) ([]PivotTableOptions, error) {
|
|||
var pivotTables []PivotTableOptions
|
||||
name, ok := f.getSheetXMLPath(sheet)
|
||||
if !ok {
|
||||
return pivotTables, newNoExistSheetError(sheet)
|
||||
return pivotTables, ErrSheetNotExist{sheet}
|
||||
}
|
||||
rels := "xl/worksheets/_rels/" + strings.TrimPrefix(name, "xl/worksheets/") + ".rels"
|
||||
sheetRels, err := f.relsReader(rels)
|
||||
|
|
|
@ -182,61 +182,61 @@ func TestPivotTable(t *testing.T) {
|
|||
Name: strings.Repeat("c", MaxFieldLength+1),
|
||||
}))
|
||||
// Test invalid data range
|
||||
assert.EqualError(t, f.AddPivotTable(&PivotTableOptions{
|
||||
assert.Equal(t, newPivotTableDataRangeError("parameter is invalid"), f.AddPivotTable(&PivotTableOptions{
|
||||
DataRange: "Sheet1!A1:A1",
|
||||
PivotTableRange: "Sheet1!U34:O2",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
|
||||
Data: []PivotTableField{{Data: "Sales"}},
|
||||
}), `parameter 'DataRange' parsing error: parameter is invalid`)
|
||||
}))
|
||||
// Test the data range of the worksheet that is not declared
|
||||
assert.EqualError(t, f.AddPivotTable(&PivotTableOptions{
|
||||
assert.Equal(t, newPivotTableDataRangeError("parameter is invalid"), f.AddPivotTable(&PivotTableOptions{
|
||||
DataRange: "A1:E31",
|
||||
PivotTableRange: "Sheet1!U34:O2",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
|
||||
Data: []PivotTableField{{Data: "Sales"}},
|
||||
}), `parameter 'DataRange' parsing error: parameter is invalid`)
|
||||
}))
|
||||
// Test the worksheet declared in the data range does not exist
|
||||
assert.EqualError(t, f.AddPivotTable(&PivotTableOptions{
|
||||
assert.Equal(t, ErrSheetNotExist{"SheetN"}, f.AddPivotTable(&PivotTableOptions{
|
||||
DataRange: "SheetN!A1:E31",
|
||||
PivotTableRange: "Sheet1!U34:O2",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
|
||||
Data: []PivotTableField{{Data: "Sales"}},
|
||||
}), "sheet SheetN does not exist")
|
||||
}))
|
||||
// Test the pivot table range of the worksheet that is not declared
|
||||
assert.EqualError(t, f.AddPivotTable(&PivotTableOptions{
|
||||
assert.Equal(t, newPivotTableRangeError("parameter is invalid"), f.AddPivotTable(&PivotTableOptions{
|
||||
DataRange: "Sheet1!A1:E31",
|
||||
PivotTableRange: "U34:O2",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
|
||||
Data: []PivotTableField{{Data: "Sales"}},
|
||||
}), `parameter 'PivotTableRange' parsing error: parameter is invalid`)
|
||||
}))
|
||||
// Test the worksheet declared in the pivot table range does not exist
|
||||
assert.EqualError(t, f.AddPivotTable(&PivotTableOptions{
|
||||
assert.Equal(t, ErrSheetNotExist{"SheetN"}, f.AddPivotTable(&PivotTableOptions{
|
||||
DataRange: "Sheet1!A1:E31",
|
||||
PivotTableRange: "SheetN!U34:O2",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
|
||||
Data: []PivotTableField{{Data: "Sales"}},
|
||||
}), "sheet SheetN does not exist")
|
||||
}))
|
||||
// Test not exists worksheet in data range
|
||||
assert.EqualError(t, f.AddPivotTable(&PivotTableOptions{
|
||||
assert.Equal(t, ErrSheetNotExist{"SheetN"}, f.AddPivotTable(&PivotTableOptions{
|
||||
DataRange: "SheetN!A1:E31",
|
||||
PivotTableRange: "Sheet1!U34:O2",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
|
||||
Data: []PivotTableField{{Data: "Sales"}},
|
||||
}), "sheet SheetN does not exist")
|
||||
}))
|
||||
// Test invalid row number in data range
|
||||
assert.EqualError(t, f.AddPivotTable(&PivotTableOptions{
|
||||
assert.Equal(t, newPivotTableDataRangeError(newCellNameToCoordinatesError("A0", newInvalidCellNameError("A0")).Error()), f.AddPivotTable(&PivotTableOptions{
|
||||
DataRange: "Sheet1!A0:E31",
|
||||
PivotTableRange: "Sheet1!U34:O2",
|
||||
Rows: []PivotTableField{{Data: "Month", DefaultSubtotal: true}, {Data: "Year"}},
|
||||
Columns: []PivotTableField{{Data: "Type", DefaultSubtotal: true}},
|
||||
Data: []PivotTableField{{Data: "Sales"}},
|
||||
}), `parameter 'DataRange' parsing error: cannot convert cell "A0" to coordinates: invalid cell name "A0"`)
|
||||
}))
|
||||
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddPivotTable1.xlsx")))
|
||||
// Test with field names that exceed the length limit and invalid subtotal
|
||||
assert.NoError(t, f.AddPivotTable(&PivotTableOptions{
|
||||
|
|
10
rows.go
10
rows.go
|
@ -14,7 +14,6 @@ package excelize
|
|||
import (
|
||||
"bytes"
|
||||
"encoding/xml"
|
||||
"fmt"
|
||||
"io"
|
||||
"math"
|
||||
"os"
|
||||
|
@ -202,15 +201,6 @@ func appendSpace(l int, s []string) []string {
|
|||
return s
|
||||
}
|
||||
|
||||
// ErrSheetNotExist defines an error of sheet that does not exist
|
||||
type ErrSheetNotExist struct {
|
||||
SheetName string
|
||||
}
|
||||
|
||||
func (err ErrSheetNotExist) Error() string {
|
||||
return fmt.Sprintf("sheet %s does not exist", err.SheetName)
|
||||
}
|
||||
|
||||
// rowXMLIterator defined runtime use field for the worksheet row SAX parser.
|
||||
type rowXMLIterator struct {
|
||||
err error
|
||||
|
|
|
@ -932,8 +932,7 @@ func TestGetValueFromNumber(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestErrSheetNotExistError(t *testing.T) {
|
||||
err := ErrSheetNotExist{SheetName: "Sheet1"}
|
||||
assert.EqualValues(t, err.Error(), "sheet Sheet1 does not exist")
|
||||
assert.Equal(t, "sheet Sheet1 does not exist", ErrSheetNotExist{"Sheet1"}.Error())
|
||||
}
|
||||
|
||||
func TestCheckRow(t *testing.T) {
|
||||
|
|
|
@ -185,7 +185,7 @@ func TestSearchSheet(t *testing.T) {
|
|||
|
||||
f.Pkg.Store("xl/worksheets/sheet1.xml", []byte(`<worksheet><sheetData><row r="0"><c r="A1" t="inlineStr"><is><t>A</t></is></c></row></sheetData></worksheet>`))
|
||||
result, err = f.SearchSheet("Sheet1", "A")
|
||||
assert.EqualError(t, err, "invalid cell reference [1, 0]")
|
||||
assert.Equal(t, newCoordinatesToCellNameError(1, 0), err)
|
||||
assert.Equal(t, []string(nil), result)
|
||||
|
||||
// Test search sheet with unsupported charset shared strings table
|
||||
|
|
|
@ -118,7 +118,7 @@ func (f *File) NewStreamWriter(sheet string) (*StreamWriter, error) {
|
|||
}
|
||||
sheetID := f.getSheetID(sheet)
|
||||
if sheetID == -1 {
|
||||
return nil, newNoExistSheetError(sheet)
|
||||
return nil, ErrSheetNotExist{sheet}
|
||||
}
|
||||
sw := &StreamWriter{
|
||||
file: f,
|
||||
|
|
|
@ -265,11 +265,11 @@ func TestNewStyle(t *testing.T) {
|
|||
|
||||
var exp string
|
||||
_, err = f.NewStyle(&Style{CustomNumFmt: &exp})
|
||||
assert.EqualError(t, err, ErrCustomNumFmt.Error())
|
||||
assert.Equal(t, ErrCustomNumFmt, err)
|
||||
_, err = f.NewStyle(&Style{Font: &Font{Family: strings.Repeat("s", MaxFontFamilyLength+1)}})
|
||||
assert.EqualError(t, err, ErrFontLength.Error())
|
||||
assert.Equal(t, ErrFontLength, err)
|
||||
_, err = f.NewStyle(&Style{Font: &Font{Size: MaxFontSize + 1}})
|
||||
assert.EqualError(t, err, ErrFontSize.Error())
|
||||
assert.Equal(t, ErrFontSize, err)
|
||||
|
||||
// Test create numeric custom style
|
||||
numFmt := "####;####"
|
||||
|
|
8
table.go
8
table.go
|
@ -217,7 +217,7 @@ func (f *File) countTables() int {
|
|||
count := 0
|
||||
f.Pkg.Range(func(k, v interface{}) bool {
|
||||
if strings.Contains(k.(string), "xl/tables/tableSingleCells") {
|
||||
var cells xlsxSingleXmlCells
|
||||
var cells xlsxSingleXMLCells
|
||||
if err := f.xmlNewDecoder(bytes.NewReader(namespaceStrictToTransitional(v.([]byte)))).
|
||||
Decode(&cells); err != nil && err != io.EOF {
|
||||
count++
|
||||
|
@ -513,12 +513,12 @@ func (f *File) autoFilter(sheet, ref string, columns, col int, opts []AutoFilter
|
|||
}
|
||||
offset := fsCol - col
|
||||
if offset < 0 || offset > columns {
|
||||
return fmt.Errorf("incorrect index of column '%s'", opt.Column)
|
||||
return newInvalidAutoFilterColumnError(opt.Column)
|
||||
}
|
||||
fc := &xlsxFilterColumn{ColID: offset}
|
||||
token := expressionFormat.FindAllString(opt.Expression, -1)
|
||||
if len(token) != 3 && len(token) != 7 {
|
||||
return fmt.Errorf("incorrect number of tokens in criteria '%s'", opt.Expression)
|
||||
return newInvalidAutoFilterExpError(opt.Expression)
|
||||
}
|
||||
expressions, tokens, err := f.parseFilterExpression(opt.Expression, token)
|
||||
if err != nil {
|
||||
|
@ -647,7 +647,7 @@ func (f *File) parseFilterTokens(expression string, tokens []string) ([]int, str
|
|||
if re {
|
||||
// Only allow Equals or NotEqual in this context.
|
||||
if operator != 2 && operator != 5 {
|
||||
return []int{operator}, token, fmt.Errorf("the operator '%s' in expression '%s' is not valid in relation to Blanks/NonBlanks'", tokens[1], expression)
|
||||
return []int{operator}, token, newInvalidAutoFilterOperatorError(tokens[1], expression)
|
||||
}
|
||||
token = strings.ToLower(token)
|
||||
// The operator should always be 2 (=) to flag a "simple" equality in
|
||||
|
|
|
@ -48,8 +48,8 @@ func TestAddTable(t *testing.T) {
|
|||
assert.EqualError(t, f.AddTable("Sheet:1", &Table{Range: "B26:A21"}), ErrSheetNameInvalid.Error())
|
||||
// Test addTable with illegal cell reference
|
||||
f = NewFile()
|
||||
assert.EqualError(t, f.addTable("sheet1", "", 0, 0, 0, 0, 0, nil), "invalid cell reference [0, 0]")
|
||||
assert.EqualError(t, f.addTable("sheet1", "", 1, 1, 0, 0, 0, nil), "invalid cell reference [0, 0]")
|
||||
assert.Equal(t, newCoordinatesToCellNameError(0, 0), f.addTable("sheet1", "", 0, 0, 0, 0, 0, nil))
|
||||
assert.Equal(t, newCoordinatesToCellNameError(0, 0), f.addTable("sheet1", "", 1, 1, 0, 0, 0, nil))
|
||||
// Test set defined name and add table with invalid name
|
||||
for _, cases := range []struct {
|
||||
name string
|
||||
|
@ -132,7 +132,7 @@ func TestDeleteTable(t *testing.T) {
|
|||
func TestSetTableHeader(t *testing.T) {
|
||||
f := NewFile()
|
||||
_, err := f.setTableHeader("Sheet1", true, 1, 0, 1)
|
||||
assert.EqualError(t, err, "invalid cell reference [1, 0]")
|
||||
assert.Equal(t, newCoordinatesToCellNameError(1, 0), err)
|
||||
}
|
||||
|
||||
func TestAutoFilter(t *testing.T) {
|
||||
|
@ -190,22 +190,22 @@ func TestAutoFilterError(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
assert.EqualError(t, f.autoFilter("SheetN", "A1", 1, 1, []AutoFilterOptions{{
|
||||
assert.Equal(t, ErrSheetNotExist{"SheetN"}, f.autoFilter("SheetN", "A1", 1, 1, []AutoFilterOptions{{
|
||||
Column: "A",
|
||||
Expression: "",
|
||||
}}), "sheet SheetN does not exist")
|
||||
assert.EqualError(t, f.autoFilter("Sheet1", "A1", 1, 1, []AutoFilterOptions{{
|
||||
}}))
|
||||
assert.Equal(t, newInvalidColumnNameError("-"), f.autoFilter("Sheet1", "A1", 1, 1, []AutoFilterOptions{{
|
||||
Column: "-",
|
||||
Expression: "-",
|
||||
}}), newInvalidColumnNameError("-").Error())
|
||||
assert.EqualError(t, f.autoFilter("Sheet1", "A1", 1, 100, []AutoFilterOptions{{
|
||||
}}))
|
||||
assert.Equal(t, newInvalidAutoFilterColumnError("A"), f.autoFilter("Sheet1", "A1", 1, 100, []AutoFilterOptions{{
|
||||
Column: "A",
|
||||
Expression: "-",
|
||||
}}), `incorrect index of column 'A'`)
|
||||
assert.EqualError(t, f.autoFilter("Sheet1", "A1", 1, 1, []AutoFilterOptions{{
|
||||
}}))
|
||||
assert.Equal(t, newInvalidAutoFilterExpError("-"), f.autoFilter("Sheet1", "A1", 1, 1, []AutoFilterOptions{{
|
||||
Column: "A",
|
||||
Expression: "-",
|
||||
}}), `incorrect number of tokens in criteria '-'`)
|
||||
}}))
|
||||
}
|
||||
|
||||
func TestParseFilterTokens(t *testing.T) {
|
||||
|
@ -215,5 +215,5 @@ func TestParseFilterTokens(t *testing.T) {
|
|||
assert.EqualError(t, err, "unknown operator: !")
|
||||
// Test invalid operator in context
|
||||
_, _, err = f.parseFilterTokens("", []string{"", "<", "x != blanks"})
|
||||
assert.EqualError(t, err, "the operator '<' in expression '' is not valid in relation to Blanks/NonBlanks'")
|
||||
assert.Equal(t, newInvalidAutoFilterOperatorError("<", ""), err)
|
||||
}
|
||||
|
|
6
vml.go
6
vml.go
|
@ -41,7 +41,7 @@ func (f *File) GetComments(sheet string) ([]Comment, error) {
|
|||
var comments []Comment
|
||||
sheetXMLPath, ok := f.getSheetXMLPath(sheet)
|
||||
if !ok {
|
||||
return comments, newNoExistSheetError(sheet)
|
||||
return comments, ErrSheetNotExist{sheet}
|
||||
}
|
||||
commentsXML := f.getSheetComments(filepath.Base(sheetXMLPath))
|
||||
if !strings.HasPrefix(commentsXML, "/") {
|
||||
|
@ -125,7 +125,7 @@ func (f *File) DeleteComment(sheet, cell string) error {
|
|||
}
|
||||
sheetXMLPath, ok := f.getSheetXMLPath(sheet)
|
||||
if !ok {
|
||||
return newNoExistSheetError(sheet)
|
||||
return ErrSheetNotExist{sheet}
|
||||
}
|
||||
commentsXML := f.getSheetComments(filepath.Base(sheetXMLPath))
|
||||
if !strings.HasPrefix(commentsXML, "/") {
|
||||
|
@ -738,7 +738,7 @@ func (sp *encodeShape) addFormCtrl(opts *vmlOptions) error {
|
|||
opts.MaxVal > MaxFormControlValue ||
|
||||
opts.IncChange > MaxFormControlValue ||
|
||||
opts.PageChange > MaxFormControlValue {
|
||||
return ErrorFormControlValue
|
||||
return ErrFormControlValue
|
||||
}
|
||||
if opts.CellLink != "" {
|
||||
if _, _, err := CellNameToCoordinates(opts.CellLink); err != nil {
|
||||
|
|
10
vml_test.go
10
vml_test.go
|
@ -263,9 +263,9 @@ func TestFormControl(t *testing.T) {
|
|||
Cell: "A1", Type: 0x37, Macro: "Button1_Click",
|
||||
}), ErrParameterInvalid)
|
||||
// Test add form control on not exists worksheet
|
||||
assert.Equal(t, f.AddFormControl("SheetN", FormControl{
|
||||
assert.Equal(t, ErrSheetNotExist{"SheetN"}, f.AddFormControl("SheetN", FormControl{
|
||||
Cell: "A1", Type: FormControlButton, Macro: "Button1_Click",
|
||||
}), newNoExistSheetError("SheetN"))
|
||||
}))
|
||||
// Test add form control with invalid positioning types
|
||||
assert.Equal(t, f.AddFormControl("Sheet1", FormControl{
|
||||
Cell: "A1", Type: FormControlButton,
|
||||
|
@ -278,7 +278,7 @@ func TestFormControl(t *testing.T) {
|
|||
// Test add spin form control with invalid scroll value
|
||||
assert.Equal(t, f.AddFormControl("Sheet1", FormControl{
|
||||
Cell: "C5", Type: FormControlSpinButton, CurrentVal: MaxFormControlValue + 1,
|
||||
}), ErrorFormControlValue)
|
||||
}), ErrFormControlValue)
|
||||
assert.NoError(t, f.Close())
|
||||
// Test delete form control
|
||||
f, err = OpenFile(filepath.Join("test", "TestAddFormControl.xlsm"))
|
||||
|
@ -290,7 +290,7 @@ func TestFormControl(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
assert.Len(t, result, 9)
|
||||
// Test delete form control on not exists worksheet
|
||||
assert.Equal(t, f.DeleteFormControl("SheetN", "A1"), newNoExistSheetError("SheetN"))
|
||||
assert.Equal(t, ErrSheetNotExist{"SheetN"}, f.DeleteFormControl("SheetN", "A1"))
|
||||
// Test delete form control with illegal cell link reference
|
||||
assert.Equal(t, f.DeleteFormControl("Sheet1", "A"), newCellNameToCoordinatesError("A", newInvalidCellNameError("A")))
|
||||
assert.NoError(t, f.SaveAs(filepath.Join("test", "TestDeleteFormControl.xlsm")))
|
||||
|
@ -314,7 +314,7 @@ func TestFormControl(t *testing.T) {
|
|||
assert.NoError(t, err)
|
||||
// Test get form controls on not exists worksheet
|
||||
_, err = f.GetFormControls("SheetN")
|
||||
assert.Equal(t, err, newNoExistSheetError("SheetN"))
|
||||
assert.Equal(t, ErrSheetNotExist{"SheetN"}, err)
|
||||
// Test get form controls with unsupported charset VML drawing
|
||||
f, err = OpenFile(filepath.Join("test", "TestAddFormControl.xlsm"))
|
||||
assert.NoError(t, err)
|
||||
|
|
16
xmlTable.go
16
xmlTable.go
|
@ -196,28 +196,28 @@ type xlsxTableStyleInfo struct {
|
|||
ShowColumnStripes bool `xml:"showColumnStripes,attr"`
|
||||
}
|
||||
|
||||
// xlsxSingleXmlCells is a single cell table is generated from an XML mapping.
|
||||
// xlsxSingleXMLCells is a single cell table is generated from an XML mapping.
|
||||
// These really just look like regular cells to the spreadsheet user, but shall
|
||||
// be implemented as Tables "under the covers."
|
||||
type xlsxSingleXmlCells struct {
|
||||
type xlsxSingleXMLCells struct {
|
||||
XMLName xml.Name `xml:"singleXmlCells"`
|
||||
SingleXmlCell []xlsxSingleXmlCell `xml:"singleXmlCell"`
|
||||
SingleXmlCell []xlsxSingleXMLCell `xml:"singleXmlCell"`
|
||||
}
|
||||
|
||||
// xlsxSingleXmlCell is a element represents the table properties for a single
|
||||
// xlsxSingleXMLCell is a element represents the table properties for a single
|
||||
// cell XML table.
|
||||
type xlsxSingleXmlCell struct {
|
||||
type xlsxSingleXMLCell struct {
|
||||
XMLName xml.Name `xml:"singleXmlCell"`
|
||||
ID int `xml:"id,attr"`
|
||||
R string `xml:"r,attr"`
|
||||
ConnectionID int `xml:"connectionId,attr"`
|
||||
XMLCellPr xlsxXmlCellPr `xml:"xmlCellPr"`
|
||||
XMLCellPr xlsxXMLCellPr `xml:"xmlCellPr"`
|
||||
ExtLst *xlsxInnerXML `xml:"extLst"`
|
||||
}
|
||||
|
||||
// xlsxXmlCellPr is a element stores the XML properties for the cell of a single
|
||||
// xlsxXMLCellPr is a element stores the XML properties for the cell of a single
|
||||
// cell xml table.
|
||||
type xlsxXmlCellPr struct {
|
||||
type xlsxXMLCellPr struct {
|
||||
XMLName xml.Name `xml:"xmlCellPr"`
|
||||
ID int `xml:"id,attr"`
|
||||
UniqueName string `xml:"uniqueName,attr,omitempty"`
|
||||
|
|
Loading…
Reference in New Issue