菜单

金沙国际Delphi调控Excel输出上标示例,delphi上标

2019年8月22日 - 金沙编程资讯

Delphi调控Excel输出上标示例,delphi上标

平素上代码吧,这些示例在Excel中输出叁个M2

unit FfrmMain;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants,
  System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, RzButton;

type
  TfrmMain = class(TForm)
    RzBitBtn1: TRzBitBtn;
    procedure RzBitBtn1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  frmMain: TfrmMain;

const
  FileName: string = 'd:\t.xls';

implementation

{$R *.dfm}

Uses ComObj;

procedure TfrmMain.RzBitBtn1Click(Sender: TObject);
var
  XlApp, XlWorkbook, XlSheet: Olevariant;
  i, j: integer;
  Range: Olevariant;
begin
  Try
    XlApp := createOleObject('Excel.Application');
    XlApp.visible := false;
    XlWorkbook := XlApp.workbooks.add;
    XlSheet := XlWorkbook.sheets.add;
  except
    showmessage('你还没有安装Microsoft Excel,请先安装!');
    XlApp.Quit;
    XlSheet := Unassigned;
    XlWorkbook := Unassigned;

    XlApp := Unassigned;
    exit;
  end;

  XlSheet.Cells[1, 1] := 'M2';
  XlSheet.Cells[1, 1].Characters[2, 1].Font.Superscript := True;
  XlSheet.rows[1].insert;
  XlSheet.Columns.EntireColumn.AutoFit;
  if FileExists(FileName) then
  begin
    if MessageDlg('文件已经存在,要替换吗?', mtConfirmation, [mbyes, mbno], 0) = mrno then
    begin
      XlApp.Quit;
      XlSheet := Unassigned;
      XlWorkbook := Unassigned;
      XlApp := Unassigned;
      exit;
    end;
  end;

  try
    XlWorkbook.SaveAs(FileName);
  except
    showmessage('导出失败,请检查你对该文件是否有写权限!');
    XlApp.Quit;
    XlSheet := Unassigned;
    XlWorkbook := Unassigned;
    XlApp := Unassigned;
    exit;
  end;
  showmessage('导出成功!');
  XlWorkbook.Saved := True;
  XlApp.Quit;
  XlSheet := Unassigned;
  XlWorkbook := Unassigned;
  XlApp := Unassigned;
end;

end.

 

关键是:

XlSheet.Cells[1, 1] := 'M2';
  XlSheet.Cells[1, 1].Characters[2, 1].Font.Superscript := True;

至于属性,查资料或通过宏来看吗。

直接上代码吧,这几个示例在Excel中输出一个M 2 : unit FfrmMain; interface
uses Winapi.Windows, Winapi.Messages, Syst…

相关文章

发表评论

电子邮件地址不会被公开。 必填项已用*标注

网站地图xml地图