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

📄 frmbjbb.pas

📁 delphi+excel报表管理程序
💻 PAS
字号:
unit frmbjbb;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, Excel2000, OleServer, OleCtnrs, StdCtrls,IniFiles;

type
  TForm2 = class(TForm)
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    ComboBox1: TComboBox;
    Button1: TButton;
    ComboBox2: TComboBox;
    ComboBox3: TComboBox;
    OleContainer1: TOleContainer;
    Button3: TButton;
    ExcelApplication1: TExcelApplication;
    ExcelWorkbook1: TExcelWorkbook;
    ExcelWorksheet1: TExcelWorksheet;
    MainMenu1: TMainMenu;
    N1: TMenuItem;
    N2: TMenuItem;
    N3: TMenuItem;
    procedure N2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure ComboBox2Select(Sender: TObject);
    procedure ComboBox3Select(Sender: TObject);
    procedure ComboBox1Select(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure N3Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form2: TForm2;

implementation

uses frmmain;

{$R *.dfm}

procedure TForm2.N2Click(Sender: TObject);
begin
self.Close;
end;

procedure TForm2.Button1Click(Sender: TObject);
var
bbml,sbmb,search,lujing,s1,cjml:string;
MyIni:TIniFile;
begin
//初始化路径
MyIni:=Tinifile.create('.\lj.ini');
sbmb:=myini.ReadString('系统路径设置','系统路径','')+'\报表\识别模板\'+trim(ComboBox1.Text);
lujing:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text;
search:=filesearch(ComboBox1.Text,lujing);
bbml:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text+'\'+trim(ComboBox1.Text);
s1:=combobox1.text;
//结束
//判断年列表是否为空
if ComboBox2.Text='' then
  begin
  application.MessageBox('请选择要打开的报表所属的年份!','系统提示');
  exit;
  end;
//判断年列表结束
//判断月列表是否为空
if ComboBox3.Text='' then
  begin
  application.MessageBox('请选择要打开的报表所属的月份!','系统提示');
  exit;
  end;
//判断月列表结束
//判断报表类型列表的内容是否为空
if ComboBox1.Text<>'' then
  begin
        s1:=ComboBox1.Text;
        label1.Caption:=search;
        //判断打开的报表是否存在
         if search='' then  //如果要打开的报表不存在,则自动创建模板
            begin
            cjml:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+ComboBox2.Text+ComboBox3.Text;
            MkDir(cjml);
         //复制报表
         CopyFile(pchar(sbmb),pchar(bbml),false);
        //复制报表结束
            end;
        //判断打开的报表是否存在结束
  end
else
  begin
  application.MessageBox('请选择要打开的报表名称!','系统提示');
  exit;
  end;
//判断报表类型列表结束
//打开指定的报表
//////////////////////////
 Begin

//关闭已经打开的程序
        Try
                ExcelApplication1.Quit;
                ExcelWorkbook1.Disconnect;
                ExcelWorksheet1.Disconnect;
                ExcelApplication1.Disconnect;
        Except
        End;
//结束
//OLEContaner打开报表
OleContainer1.DestroyObject;
OleContainer1.CreateObjectFromFile(label1.Caption,false);
//OleContainer1.CreateLinkToFile(label1.Caption,false);
//OLEContaner打开报表结束

        //打开Excel
           Try
                ExcelApplication1.Connect;
           Except
                application.MessageBox('打开失败,可能系统没有安装Excel,请重试!','提示信息');
                exit;
           End;
                //ExcelApplication1.Visible[0]:=True;
        //打开结束
End;
/////////////////////////
//结束
Button3.Enabled:=true;
OleContainer1.Enabled:=true;
myini.Free;
end;

procedure TForm2.FormShow(Sender: TObject);
var
year:string;
i:integer;
j:integer;
begin
//更新报表年列表
ComboBox2.Items.Clear;
year:=datetostr(date());
ComboBox2.Items.Add(inttostr(strtoint(copy(year,0,4))+1));
ComboBox2.Items.Add(copy(year,0,4));
ComboBox2.Items.Add(inttostr(strtoint(copy(year,0,4))-1));
//更新年列表结束
//更新报表类型列表
try
form1.ADOQuery1.Close;
form1.ADOQuery1.SQL.Clear;
form1.ADOQuery1.SQL.Add('select * from template');
form1.ADOQuery1.Open;
i:=form1.ADOQuery1.RecordCount;
ComboBox1.Clear;
for j := 1 to i do
begin
form1.ADOQuery1.Close;
form1.ADOQuery1.SQL.Clear;
form1.ADOQuery1.SQL.Add('select * from template');
form1.ADOQuery1.SQL.Add('where id=:a1');
form1.adoquery1.Parameters.ParamValues['a1']:=inttostr(j);
form1.ADOQuery1.Open;
if (form1.ADOQuery1.Fields.Fields[3].AsString='1') then
if (form1.ADOQuery1.Fields.Fields[4].AsString='1') then
ComboBox1.Items.Add(form1.ADOQuery1.Fields.Fields[1].AsString);
end;
except;
end;
//更新报表类型列表结束
end;

procedure TForm2.ComboBox2Select(Sender: TObject);
var
bbml,sbmb,search,lujing,s1,cjml:string;
MyIni:TIniFile;
begin
//初始化路径
MyIni:=Tinifile.create('.\lj.ini');
sbmb:=myini.ReadString('系统路径设置','系统路径','')+'\报表\识别模板\'+trim(ComboBox1.Text);
lujing:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text;
search:=filesearch(ComboBox1.Text,lujing);
bbml:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text+'\'+trim(ComboBox1.Text);
s1:=combobox1.text;
//结束
//判断年列表是否为空
if ComboBox2.Text='' then
  begin
  application.MessageBox('请选择要打开的报表所属的年份!','系统提示');
  exit;
  end;
//判断年列表结束
//判断月列表是否为空
if ComboBox3.Text='' then
  begin
  exit;
  end;
//判断月列表结束
//判断报表类型列表的内容是否为空
if ComboBox1.Text<>'' then
  begin
        s1:=ComboBox1.Text;
        label1.Caption:=search;
        //判断打开的报表是否存在
         if search='' then  //如果要打开的报表不存在,则自动创建模板
            begin
            cjml:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+ComboBox2.Text+ComboBox3.Text;
            MkDir(cjml);
         //复制报表
         CopyFile(pchar(sbmb),pchar(bbml),false);
        //复制报表结束
            end;
        //判断打开的报表是否存在结束
  end
else
  begin
  exit;
  end;
//判断报表类型列表结束
Button3.Enabled:=true;
OleContainer1.Enabled:=true;
//结束
end;

procedure TForm2.ComboBox3Select(Sender: TObject);
var
bbml,sbmb,search,lujing,s1,cjml:string;
MyIni:TIniFile;
begin
//初始化路径
MyIni:=Tinifile.create('.\lj.ini');
sbmb:=myini.ReadString('系统路径设置','系统路径','')+'\报表\识别模板\'+trim(ComboBox1.Text);
lujing:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text;
search:=filesearch(ComboBox1.Text,lujing);
bbml:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text+'\'+trim(ComboBox1.Text);
s1:=combobox1.text;
//结束
//判断年列表是否为空
if ComboBox2.Text='' then
  begin
  application.MessageBox('请选择要打开的报表所属的年份!','系统提示');
  exit;
  end;
//判断年列表结束
//判断月列表是否为空
if ComboBox3.Text='' then
  begin
  exit;
  end;
//判断月列表结束
//判断报表类型列表的内容是否为空
if ComboBox1.Text<>'' then
  begin
        s1:=ComboBox1.Text;
        label1.Caption:=search;
        //判断打开的报表是否存在
         if search='' then  //如果要打开的报表不存在,则自动创建模板
            begin
            cjml:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+ComboBox2.Text+ComboBox3.Text;
            MkDir(cjml);
         //复制报表
         CopyFile(pchar(sbmb),pchar(bbml),false);
        //复制报表结束
            end;
        //判断打开的报表是否存在结束
  end
else
  begin
  exit;
  end;
//判断报表类型列表结束
//结束
end;

procedure TForm2.ComboBox1Select(Sender: TObject);
var
bbml,sbmb,search,lujing,s1,cjml:string;
MyIni:TIniFile;
begin
//初始化路径
MyIni:=Tinifile.create('.\lj.ini');
sbmb:=myini.ReadString('系统路径设置','系统路径','')+'\报表\识别模板\'+trim(ComboBox1.Text);
lujing:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text;
search:=filesearch(ComboBox1.Text,lujing);
bbml:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text+'\'+trim(ComboBox1.Text);
s1:=combobox1.text;
//结束
//判断年列表是否为空
if ComboBox2.Text='' then
  begin
  application.MessageBox('请选择要打开的报表所属的年份!','系统提示');
  exit;
  end;
//判断年列表结束
//判断月列表是否为空
if ComboBox3.Text='' then
  begin
  exit;
  end;
//判断月列表结束
//判断报表类型列表的内容是否为空
if ComboBox1.Text<>'' then
  begin
        s1:=ComboBox1.Text;
        label1.Caption:=search;
        //判断打开的报表是否存在
         if search='' then  //如果要打开的报表不存在,则自动创建模板
            begin
            cjml:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+ComboBox2.Text+ComboBox3.Text;
            MkDir(cjml);
         //复制报表
         CopyFile(pchar(sbmb),pchar(bbml),false);
        //复制报表结束
            end;
        //判断打开的报表是否存在结束
  end
else
  begin
  application.MessageBox('请选择要打开的报表名称!','系统提示');
  exit;
  end;
//判断报表类型列表结束
//结束
end;

procedure TForm2.Button3Click(Sender: TObject);
var
search,s1,lujing:STRING;
MyIni:TIniFile;
begin
MyIni:=Tinifile.create('.\lj.ini');
lujing:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text;
s1:=ComboBox1.Text;
search:=FileSearch(s1,lujing);
label1.Caption:=search;
OleContainer1.SaveAsDocument(label1.Caption);
myini.Free;
end;

procedure TForm2.N3Click(Sender: TObject);
begin
if (application.MessageBox('是否真的要退出该系统?(Y/N)','系统提示',MB_YESNO)=IDNO) then
   exit
else
   application.Terminate;
end;

procedure TForm2.FormClose(Sender: TObject; var Action: TCloseAction);
var
search,s1,lujing:STRING;
MyIni:TIniFile;
begin
try
MyIni:=Tinifile.create('.\lj.ini');
lujing:=myini.ReadString('系统路径设置','系统路径','')+'\报表\报表目录\'+combobox2.text+combobox3.text;
s1:=ComboBox1.Text;
search:=FileSearch(s1,lujing);
label1.Caption:=search;
OleContainer1.SaveAsDocument(label1.Caption);
myini.Free;
OleContainer1.DestroyObject;
except;
end;
end;

end.

⌨️ 快捷键说明

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