// Package utils -----------------------------
// @file      : excelHelper.go
// @author    : JJXu
// @contact   : wavingbear@163.com
// @time      : 2022/6/9 13:41
// -------------------------------------------
package excel

import (
	"fmt"
	"strconv"
)

// 行列坐标值转换为excel的坐标。注意row和columnCount的初始值都是1
func GetCellIndex(row int, columnCount int) string {
	var column = GetColumnIndex(columnCount)
	return fmt.Sprintf("%s%d", column, row)
}

// 获取excel的列索引
var columnIndices = []string{"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"}

func GetColumnIndex(num int) string {
	num--
	var column = columnIndices[num%26]
	for num = num / 26; num > 0; num = num / 26 {
		column = columnIndices[(num-1)%26] + column
		num--
	}
	return column
}

func Int[T int | uint | uint8 | uint32 | uint64 | int32 | int64](value string) T {
	v, _ := strconv.Atoi(value)
	return T(v)
}

func Float[T float64 | float32](value string) T {
	v, _ := strconv.ParseFloat(value, 64)
	return T(v)
}
