本文整理自网络,侵删。
unit Unit3;
interface
uses Math, Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.Samples.Spin, Vcl.ExtCtrls;
type TForm3 = class(TForm) Memo1: TMemo; Panel1: TPanel; Button1: TButton; SpinEdit1: TSpinEdit; Button2: TButton; procedure Button1Click(Sender: TObject); procedure FormCreate(Sender: TObject); procedure Button2Click(Sender: TObject); private { Private declarations } public { Public declarations } end;
var Form3: TForm3;
implementation
{$R *.dfm}
function ExcelNumToLetter(AExcelNum: Integer): string;var vLen: integer; vNum: Integer;begin vLen := Ord('Z') - Ord('A') + 1; Result := ''; vNum := AExcelNum; while (vNum >= 0) do begin Result := Char(vNum mod vLen + Ord('A')) + Result; vNum := Math.floor(vNum / vLen) - 1; end;end;
procedure TForm3.Button1Click(Sender: TObject);begin Memo1.Lines.Add(Format('数字【%d】对应的Excel字母列号为【%s】', [SpinEdit1.Value, ExcelNumToLetter(SpinEdit1.Value)]));end;
procedure TForm3.Button2Click(Sender: TObject);var i: Integer;begin Memo1.Clear; Memo1.Lines.BeginUpdate; for i := 0 to 300 do begin Memo1.Lines.Add(Format('数字【%d】对应的Excel字母列号为【%s】', [i, ExcelNumToLetter(i)])); end; Memo1.Lines.EndUpdate;end;
procedure TForm3.FormCreate(Sender: TObject);begin Memo1.Clear;end;
end.
//数字转Excel字母列序号 byQQ16643506
相关阅读 >>
Delphi xe(indy10)tidbytes转ansistring的实现
Delphi combobox 只读 text属性可用的方法
更多相关阅读请进入《Delphi》频道 >>