⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bm_excelu.pas

📁 Delphi办公管理系统
💻 PAS
字号:
unit BM_EXCELU;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Buttons, StdCtrls, ExtCtrls,ComObj,ComCtrls, Grids, TabNotBk;

type
  TBM_EXCELF = class(TForm)
    Panel1: TPanel;
    Panel2: TPanel;
    SpeedButton3: TSpeedButton;
    SpeedButton4: TSpeedButton;
    SpeedButton5: TSpeedButton;
    SpeedButton6: TSpeedButton;
    Panel3: TPanel;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    SpeedButton2: TSpeedButton;
    ListBox1: TListBox;
    StringGrid1: TStringGrid;
    Panel4: TPanel;
    Splitter1: TSplitter;
    SpeedButton7: TSpeedButton;
    SpeedButton8: TSpeedButton;
    TabbedNotebook1: TTabbedNotebook;
    Edit5: TEdit;
    UpDown2: TUpDown;
    UpDown1: TUpDown;
    Edit2: TEdit;
    Label1: TLabel;
    Label4: TLabel;
    Edit6: TEdit;
    Label5: TLabel;
    Edit3: TEdit;
    Label2: TLabel;
    RB1: TRadioButton;
    RB2: TRadioButton;
    CB1: TCheckBox;
    Edit4: TEdit;
    Label3: TLabel;
    procedure SpeedButton2Click(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
    procedure SpeedButton3Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure SpeedButton4Click(Sender: TObject);
    procedure UpDown1ChangingEx(Sender: TObject; var AllowChange: Boolean;
      NewValue: Smallint; Direction: TUpDownDirection);
    procedure SpeedButton8Click(Sender: TObject);
    procedure UpDown2ChangingEx(Sender: TObject; var AllowChange: Boolean;
      NewValue: Smallint; Direction: TUpDownDirection);
    procedure SpeedButton6Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure SpeedButton5Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  BM_EXCELF: TBM_EXCELF;
    i,j,p:INTEGER;
    eclApp,WorkBook:Variant;
 xlsFileName:string;
implementation

{$R *.dfm}

procedure TBM_EXCELF.SpeedButton2Click(Sender: TObject);
begin
listbox1.Items.Delete(listbox1.ItemIndex);
end;

procedure TBM_EXCELF.SpeedButton1Click(Sender: TObject);
begin
if edit1.Text <>'' then listbox1.Items.Add(edit1.Text);
end;

procedure TBM_EXCELF.SpeedButton3Click(Sender: TObject);

begin
if strtoint(edit2.text)>0 then stringgrid1.RowCount :=strtoint(edit2.text)+1;
if strtoint(edit5.text)>0 then stringgrid1.colCount :=strtoint(edit5.text)+1;


xlsFileName:=edit4.Text+ edit3.Text+'.xls';
eclApp:=CreateOleObject('Excel.Application');
WorkBook:=CreateOleobject('Excel.Sheet');

try
workBook:=eclApp.workBooks.Add;
//   WorkBook.caption:=edit4.text;
 for i:=1 to StringGrid1.rowCount+1  do
   begin
     for j:=1 to StringGrid1.ColCount+1 do
     // begin
        eclApp.Cells(j,i):=StringGrid1.Cells[i,j];
    //  end;
   end;
WorkBook.ActiveSheet.PageSetup.CenterHeader :=edit6.Text;

if rb1.Checked then  WorkBook.ActiveSheet.PageSetup.CenterHorizontally := 2/0.035
else  WorkBook.ActiveSheet.PageSetup.CenterVertically := 2/0.035;
if cb1.Checked then WorkBook.ActiveSheet.PageSetup.PrintGridLines := True;



//WorkBook:=eclApp.workBooks.Open(xlsFileName);


if MessageDlg(xlsFileName+'已经生成,您要保存吗?',mtConfirmation, [mbYes, mbNo], 0)=mrYes then
 begin
WorkBook.save ;
WorkBook.saveas(xlsFileName);
end
else
workBook.Saved := true;

WorkBook.Close;
eclApp.Quit;
eclApp:=Unassigned;
except

WorkBook.close;
eclApp.Quit;
eclApp:=Unassigned;
end;


end;

procedure TBM_EXCELF.FormClose(Sender: TObject; var Action: TCloseAction);
begin
action:=cafree;
end;

procedure TBM_EXCELF.SpeedButton4Click(Sender: TObject);
begin
//stringgrid1.rowcount:=strtoint(listbox1.Items.Count);
//stringgrid1.Cells[0,0]:=edit3.Text;
if strtoint(edit2.text)>0 then stringgrid1.RowCount :=strtoint(edit2.text)+1;
if strtoint(edit5.text)>0 then stringgrid1.colCount :=strtoint(edit5.text)+1;
 for i:=0 to stringgrid1.rowcount-1 do
   begin
   stringgrid1.Cells[0,i]:=inttostr(i);
   end;
for i:=0 to stringgrid1.colcount-1 do
   begin
   stringgrid1.Cells[i,0]:=inttostr(i);
   end;
//  WorkBook.ActiveSheet.PrintPreview;
{stringgrid1.colcount:=listbox1.Items.Count+1;


  for i:=1 to stringgrid1.rowcount-1 do
   begin
   stringgrid1.Cells[0,i]:=inttostr(i);
   end;

   for p:=0 to listbox1.Items.Count-1 do
   begin
   stringgrid1.Cells[p+1,0]:=listbox1.Items[p];
   end;

 { for j:=1 to stringgrid1.rowcount do
   begin
     for i:=0 to stringgrid1.ColCount-1 do ListBox1.Items.Add(stringgrid1.Cells[i,j]);//stringgrid1.Cells[i,j]:='uu';
   end; }
end;

procedure TBM_EXCELF.UpDown1ChangingEx(Sender: TObject;
  var AllowChange: Boolean; NewValue: Smallint;
  Direction: TUpDownDirection);

begin

  if direction=updup then
   edit2.Text :=inttostr(strtoint(edit2.Text)+1)
  else
  if  strtoint(edit2.Text)<=1 then exit
  else
  edit2.Text :=inttostr(strtoint(edit2.Text)-1);
end;

procedure TBM_EXCELF.SpeedButton8Click(Sender: TObject);
begin
listbox1.Items.Clear ;
end;

procedure TBM_EXCELF.UpDown2ChangingEx(Sender: TObject;
  var AllowChange: Boolean; NewValue: Smallint;
  Direction: TUpDownDirection);
begin

  if direction=updup then
   edit5.Text :=inttostr(strtoint(edit5.Text)+1)
  else
  if  strtoint(edit5.Text)<=1 then exit
  else
  edit5.Text :=inttostr(strtoint(edit5.Text)-1);
end;

procedure TBM_EXCELF.SpeedButton6Click(Sender: TObject);
begin
close;
end;

procedure TBM_EXCELF.FormCreate(Sender: TObject);
begin
if strtoint(edit2.text)>0 then stringgrid1.RowCount :=strtoint(edit2.text)+1;
if strtoint(edit5.text)>0 then stringgrid1.colCount :=strtoint(edit5.text)+1;
 for i:=0 to stringgrid1.rowcount-1 do
   begin
   stringgrid1.Cells[0,i]:=inttostr(i);
   end;
for i:=0 to stringgrid1.colcount-1 do
   begin
   stringgrid1.Cells[i,0]:=inttostr(i);
   end;
end;

procedure TBM_EXCELF.SpeedButton5Click(Sender: TObject);
begin
//WorkBook.WorkBooks.Open( 'C:\BM_EXCEL.xls' );
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -