mirror of
https://github.com/unidoc/unioffice.git
synced 2025-04-29 13:49:10 +08:00

* evaluation errors fixed * allow underscores in sheet names * allow wildcard in *LOOKUP functions * horizontal and vertical ranges * horizontal and vertical ranges for sheet references * remove redundant recalculate * caching * fixed named ranges, made Evaluator more generic * Memory usage shown in flatten example * temporary file deleted * ParseCellReference duplicate removed * ISREF is fixed
42 lines
969 B
Go
42 lines
969 B
Go
// Copyright 2017 FoxyUtils ehf. All rights reserved.
|
|
//
|
|
// Use of this source code is governed by the terms of the Affero GNU General
|
|
// Public License version 3.0 as published by the Free Software Foundation and
|
|
// appearing in the file LICENSE included in the packaging of this file. A
|
|
// commercial license can be purchased on https://unidoc.io.
|
|
|
|
package reference
|
|
|
|
import (
|
|
"strings"
|
|
)
|
|
|
|
// ColumnToIndex maps a column to a zero based index (e.g. A = 0, B = 1, AA = 26)
|
|
func ColumnToIndex(col string) uint32 {
|
|
col = strings.ToUpper(col)
|
|
res := uint32(0)
|
|
for _, c := range col {
|
|
res *= 26
|
|
res += uint32(c - 'A' + 1)
|
|
}
|
|
return res - 1
|
|
}
|
|
|
|
// IndexToColumn maps a column number to a column name (e.g. 0 = A, 1 = B, 26 = AA)
|
|
func IndexToColumn(col uint32) string {
|
|
var a [64 + 1]byte
|
|
i := len(a)
|
|
u := col
|
|
const b = 26
|
|
for u >= b {
|
|
i--
|
|
q := u / b
|
|
a[i] = byte('A' + uint(u-q*b))
|
|
u = q - 1
|
|
}
|
|
i--
|
|
a[i] = byte('A' + uint(u))
|
|
|
|
return string(a[i:])
|
|
}
|