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

📄 cgf5.pas

📁 非常丰富的delphi小程序,相信会对你有帮助
💻 PAS
字号:
unit cgf5;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, DBGrids, DBTables, DB, ExtCtrls, Buttons;

type
  TForm1 = class(TForm)
    Bevel1: TBevel;
    Edit1: TEdit;
    SpeedButton1: TSpeedButton;
    OpenDialog1: TOpenDialog;
    Label1: TLabel;
    Panel1: TPanel;
    Panel2: TPanel;
    SpeedButton2: TSpeedButton;
    Table1: TTable;
    DBGrid1: TDBGrid;
    Button1: TButton;
    Button2: TButton;
    DataSource1: TDataSource;
    procedure SpeedButton1Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
     private
    { Private declarations }
  public
    Function Legit1(const s:string):boolean;{ Public declarations }
  end;

var
  Form1: TForm1;
  str1:string;
  str2:pchar;
  query1:TQuery;
implementation

{$R *.dfm}

procedure TForm1.SpeedButton1Click(Sender: TObject);
begin
 If opendialog1.Execute  then
   begin
    Edit1.Text:=opendialog1.FileName;
   end;
end;

function TForm1.Legit1(const s: string): boolean;
var count1:integer;str:string;
begin
  count1:=length(s);
  if count1<8 then result:=false
   else
     begin
      str:=copy(s,count1-3,4);
      if (str='.xls')or(str='.XLS')or(str='.Xls')or(str='.xLs')or(str='.xlS')
        or(str='.XLs')or(str='.XlS')or(str='.xLS') Then result:=true
        else  result:=false;
     end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var str:string;s:pchar;
begin
 if Legit1(edit1.Text) then
    begin
     str:=Edit1.Text;
     If FileExists(str)  then
        begin
         s:=pchar(str);
         copyfile(s,'F:\论文\test3.xls',false);
         Query1:=TQuery.Create(self);
         query1.DatabaseName:='Excel Driver';
         query1.Close;
         query1.sql.Clear;
         query1.sql.Add('Select * From sheet1');
         query1.Prepare ;
         query1.open;
         table1.Active:=true;
         table1.BatchMove(query1,Batcopy);
         table1.Close;

         query1.Destroy ;
        end
       else
        begin
         Showmessage('文件不存在!,请重新选择');
        end;
    end
   else
    begin
     showmessage('要进行导入的文件名有问题!,请改正后重试');
    end;
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin
 self.Close;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 if button2.Caption='显示' then
   begin
    Table1.Active:=true;
   if table1.RecordCount=0 then
    showmessage('库中没有内容!')
   else
   begin
    dbgrid1.Visible :=true;
    Button2.Caption:='关闭';
   end;
   end
  else
   begin
    Table1.Active:=false;
    dbgrid1.Visible:=false;
    button2.Caption :='显示';
   end;
end;
end.

⌨️ 快捷键说明

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