2021-03-30 23:02:22 +08:00
|
|
|
// Copyright 2016 - 2021 The excelize Authors. All rights reserved. Use of
|
2019-03-20 15:13:41 +08:00
|
|
|
// this source code is governed by a BSD-style license that can be found in
|
|
|
|
// the LICENSE file.
|
|
|
|
//
|
|
|
|
// Package excelize providing a set of functions that allow you to write to
|
2020-06-22 00:14:56 +08:00
|
|
|
// and read from XLSX / XLSM / XLTM files. Supports reading and writing
|
2021-03-30 23:02:22 +08:00
|
|
|
// spreadsheet documents generated by Microsoft Excel™ 2007 and later. Supports
|
2020-06-22 00:14:56 +08:00
|
|
|
// complex components by high compatibility, and provided streaming API for
|
|
|
|
// generating or reading data from a worksheet with huge amounts of data. This
|
2021-04-04 15:29:43 +08:00
|
|
|
// library needs Go version 1.15 or later.
|
2019-03-20 15:13:41 +08:00
|
|
|
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
package excelize
|
|
|
|
|
2021-05-10 00:09:24 +08:00
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"fmt"
|
|
|
|
)
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
|
2021-08-15 00:06:40 +08:00
|
|
|
// newInvalidColumnNameError defined the error message on receiving the invalid column name.
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
func newInvalidColumnNameError(col string) error {
|
|
|
|
return fmt.Errorf("invalid column name %q", col)
|
|
|
|
}
|
|
|
|
|
2021-08-15 00:06:40 +08:00
|
|
|
// newInvalidRowNumberError defined the error message on receiving the invalid row number.
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
func newInvalidRowNumberError(row int) error {
|
|
|
|
return fmt.Errorf("invalid row number %d", row)
|
|
|
|
}
|
|
|
|
|
2021-08-15 00:06:40 +08:00
|
|
|
// newInvalidCellNameError defined the error message on receiving the invalid cell name.
|
Huge refactorig for consistent col/row numbering (#356)
* Huge refactorig for consistent col/row numbering
Started from simply changing ToALphaString()/TitleToNumber() logic and related fixes.
But have to go deeper, do fixes, after do related fixes and again and again.
Major improvements:
1. Tests made stronger again (But still be weak).
2. "Empty" returns for incorrect input replaces with panic.
3. Check for correct col/row/cell naming & addressing by default.
4. Removed huge amount of duplicated code.
5. Removed ToALphaString(), TitleToNumber() and it helpers functions at all,
and replaced with SplitCellName(), JoinCellName(), ColumnNameToNumber(), ColumnNumberToName(), CellNameToCoordinates(), CoordinatesToCellName().
6. Minor fixes for internal variable naming for code readability (ex. col, row for input params, colIdx, rowIdx for slice indexes etc).
* Formatting fixes
2019-03-20 00:14:41 +08:00
|
|
|
func newInvalidCellNameError(cell string) error {
|
|
|
|
return fmt.Errorf("invalid cell name %q", cell)
|
|
|
|
}
|
2020-03-03 19:31:02 +08:00
|
|
|
|
2021-08-15 00:06:40 +08:00
|
|
|
// newInvalidExcelDateError defined the error message on receiving the data with negative values.
|
2020-03-03 19:31:02 +08:00
|
|
|
func newInvalidExcelDateError(dateValue float64) error {
|
2021-08-15 00:06:40 +08:00
|
|
|
return fmt.Errorf("invalid date value %f, negative values are not supported", dateValue)
|
2020-03-03 19:31:02 +08:00
|
|
|
}
|
2021-05-10 00:09:24 +08:00
|
|
|
|
2021-08-15 00:06:40 +08:00
|
|
|
// newUnsupportChartType defined the error message on receiving the chart type are unsupported.
|
2021-07-05 00:03:56 +08:00
|
|
|
func newUnsupportChartType(chartType string) error {
|
|
|
|
return fmt.Errorf("unsupported chart type %s", chartType)
|
|
|
|
}
|
|
|
|
|
2021-08-15 00:06:40 +08:00
|
|
|
// 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)
|
|
|
|
}
|
|
|
|
|
2021-08-17 00:01:44 +08:00
|
|
|
// newInvalidStyleID defined the error message on receiving the invalid style ID.
|
|
|
|
func newInvalidStyleID(styleID int) error {
|
|
|
|
return fmt.Errorf("invalid style ID %d, negative values are not supported", styleID)
|
|
|
|
}
|
|
|
|
|
2021-05-10 00:09:24 +08:00
|
|
|
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")
|
|
|
|
// ErrColumnNumber defined the error message on receive an invalid column
|
|
|
|
// number.
|
|
|
|
ErrColumnNumber = errors.New("column number exceeds maximum limit")
|
|
|
|
// ErrColumnWidth defined the error message on receive an invalid column
|
|
|
|
// width.
|
2021-07-31 14:20:29 +08:00
|
|
|
ErrColumnWidth = fmt.Errorf("the width of the column must be smaller than or equal to %d characters", MaxColumnWidth)
|
2021-05-10 00:09:24 +08:00
|
|
|
// 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")
|
|
|
|
// ErrExistsWorksheet defined the error message on given worksheet already
|
|
|
|
// exists.
|
|
|
|
ErrExistsWorksheet = errors.New("the same name worksheet 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 extension")
|
|
|
|
// ErrToExcelTime defined the error message on receive a not UTC time.
|
|
|
|
ErrToExcelTime = errors.New("only UTC time expected")
|
2021-08-17 00:01:44 +08:00
|
|
|
// ErrMaxRows defined the error message on receive a row number exceeds maximum limit.
|
|
|
|
ErrMaxRows = errors.New("row number exceeds maximum limit")
|
2021-05-10 00:09:24 +08:00
|
|
|
// ErrMaxRowHeight defined the error message on receive an invalid row
|
|
|
|
// height.
|
|
|
|
ErrMaxRowHeight = errors.New("the height of the row must be smaller than or equal to 409 points")
|
|
|
|
// ErrImgExt defined the error message on receive an unsupported image
|
|
|
|
// extension.
|
|
|
|
ErrImgExt = errors.New("unsupported image extension")
|
|
|
|
// ErrMaxFileNameLength defined the error message on receive the file name
|
|
|
|
// length overflow.
|
|
|
|
ErrMaxFileNameLength = errors.New("file name length exceeds maximum limit")
|
2021-07-05 00:03:56 +08:00
|
|
|
// ErrEncrypt defined the error message on encryption spreadsheet.
|
|
|
|
ErrEncrypt = errors.New("not support encryption currently")
|
|
|
|
// ErrUnknownEncryptMechanism defined the error message on unsupport
|
|
|
|
// encryption mechanism.
|
|
|
|
ErrUnknownEncryptMechanism = errors.New("unknown encryption mechanism")
|
|
|
|
// ErrUnsupportEncryptMechanism defined the error message on unsupport
|
|
|
|
// encryption mechanism.
|
|
|
|
ErrUnsupportEncryptMechanism = errors.New("unsupport encryption mechanism")
|
|
|
|
// 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")
|
|
|
|
// ErrFontLength defined the error message on the length of the font
|
|
|
|
// family name overflow.
|
|
|
|
ErrFontLength = errors.New("the length of the font family name must be smaller than or equal to 31")
|
|
|
|
// ErrFontSize defined the error message on the size of the font is invalid.
|
|
|
|
ErrFontSize = errors.New("font size must be between 1 and 409 points")
|
|
|
|
// ErrSheetIdx defined the error message on receive the invalid worksheet
|
|
|
|
// index.
|
|
|
|
ErrSheetIdx = errors.New("invalid worksheet index")
|
|
|
|
// ErrGroupSheets defined the error message on group sheets.
|
|
|
|
ErrGroupSheets = errors.New("group worksheet must contain an active worksheet")
|
2021-07-31 00:31:51 +08:00
|
|
|
// ErrDataValidationFormulaLenth defined the error message for receiving a
|
|
|
|
// data validation formula length that exceeds the limit.
|
|
|
|
ErrDataValidationFormulaLenth = errors.New("data validation must be 0-255 characters")
|
|
|
|
// ErrDataValidationRange defined the error message on set decimal range
|
|
|
|
// exceeds limit.
|
|
|
|
ErrDataValidationRange = errors.New("data validation range exceeds limit")
|
2021-07-31 14:20:29 +08:00
|
|
|
// 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)
|
2021-09-18 23:20:24 +08:00
|
|
|
// ErrOptionsUnzipSizeLimit defined the error message for receiving
|
|
|
|
// invalid UnzipSizeLimit and WorksheetUnzipMemLimit.
|
|
|
|
ErrOptionsUnzipSizeLimit = errors.New("the value of UnzipSizeLimit should be greater than or equal to WorksheetUnzipMemLimit")
|
2021-05-10 00:09:24 +08:00
|
|
|
)
|