首页 > 其他分享 >获取Excel列标

获取Excel列标

时间:2022-12-23 14:25:27浏览次数:30  
标签:列标 26 sub temp Excel 获取 col Math

/// <summary>
/// 获取Excel列标 A B C...Z等
/// </summary>
/// <param name="col">Excel列数,从0开始</param>
/// <returns></returns>
public string getExcelColumnLabel(int col)
{
    string temp = "";
    double i = Math.Floor(Math.Log(25.0 * (col) / 26.0 + 1) / Math.Log(26)) + 1;
    if (i > 1)
    {
        double sub = col - 26 * (Math.Pow(26, i - 1) - 1) / 25;
        for (double j = i; j > 0; j--)
        {
            temp = temp + (char)(sub / Math.Pow(26, j - 1) + 65);
            sub = sub % Math.Pow(26, j - 1);
        }
    }
    else
    {
        temp = temp + (char)(col + 65);
    }
    return temp;
}

 

标签:列标,26,sub,temp,Excel,获取,col,Math
From: https://www.cnblogs.com/wsk198726/p/17000568.html

相关文章