zoukankan      html  css  js  c++  java
  • C# 获得Excel的列标

    public static string GetColumnName(int theColumnIndex)
    {
    string tmpColName = string.Empty;
    string tmpColName1=string.Empty;

    if (theColumnIndex > 256) { return ""; }
    else {
    if (theColumnIndex <= 26) { tmpColName = Chr(Asc("A") + theColumnIndex - 1); }
    else
    {
    tmpColName1 = Chr(Asc("A") + (theColumnIndex / 26) - 1);
    tmpColName = tmpColName1 + Chr(Asc("A") + theColumnIndex % 26 - 1);
    }
    }
    return tmpColName;
    }

    public static int Asc(string character)
    {
    if (character.Length == 1)
    {
    System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
    int intAsciiCode = (int)asciiEncoding.GetBytes(character)[0];
    return (intAsciiCode);
    }
    else
    {
    throw new Exception("Character is not valid.");
    }

    }

    public static string Chr(int asciiCode)
    {
    if (asciiCode >= 0 && asciiCode <= 255)
    {
    System.Text.ASCIIEncoding asciiEncoding = new System.Text.ASCIIEncoding();
    byte[] byteArray = new byte[] { (byte)asciiCode };
    string strCharacter = asciiEncoding.GetString(byteArray);
    return (strCharacter);
    }
    else
    {
    throw new Exception("ASCII Code is not valid.");
    }
    }

     
  • 相关阅读:
    图片展示和上传需要注意的问题
    大数据技能学习
    C#100万条数据导入SQL SERVER数据库仅用4秒 (附源码)
    领导力
    .NetCore 三种生命周期注入方式
    Redis常见面试题
    .NET Core开发日志——Middleware
    编程的灵魂
    递推算法
    分治算法
  • 原文地址:https://www.cnblogs.com/Areas/p/2608737.html
Copyright © 2011-2022 走看看