How to convert a column number (e.g. 127) into an Excel column (e.g. AA)

前端 未结 30 2092
鱼传尺愫
鱼传尺愫 2020-11-22 00:35

How do you convert a numerical number to an Excel column name in C# without using automation getting the value directly from Excel.

Excel 2007 has a possible range o

30条回答
  •  鱼传尺愫
    2020-11-22 00:52

    In Delphi (Pascal):

    function GetExcelColumnName(columnNumber: integer): string;
    var
      dividend, modulo: integer;
    begin
      Result := '';
      dividend := columnNumber;
      while dividend > 0 do begin
        modulo := (dividend - 1) mod 26;
        Result := Chr(65 + modulo) + Result;
        dividend := (dividend - modulo) div 26;
      end;
    end;
    

提交回复
热议问题