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
|
|
|
|
|
|
|
func newInvalidColumnNameError(col string) error {
|
|
|
|
return fmt.Errorf("invalid column name %q", col)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newInvalidRowNumberError(row int) error {
|
|
|
|
return fmt.Errorf("invalid row number %d", row)
|
|
|
|
}
|
|
|
|
|
|
|
|
func newInvalidCellNameError(cell string) error {
|
|
|
|
return fmt.Errorf("invalid cell name %q", cell)
|
|
|
|
}
|
2020-03-03 19:31:02 +08:00
|
|
|
|
|
|
|
func newInvalidExcelDateError(dateValue float64) error {
|
|
|
|
return fmt.Errorf("invalid date value %f, negative values are not supported supported", dateValue)
|
|
|
|
}
|
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.
|
|
|
|
ErrColumnWidth = errors.New("the width of the column must be smaller than or equal to 255 characters")
|
|
|
|
// 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")
|
|
|
|
// 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")
|
|
|
|
)
|