utexceldldc.pas

来自「是一个用delphi设计的考勤系统」· PAS 代码 · 共 147 行

PAS
147
字号
unit UTExcelDlDc;

interface
uses windows, forms, SysUtils, Controls, URecord, Excel2000, UTyhxx;
type
   TExcel = class
      RetVal: integer;
      RetMsg: string;
      ExcelApp: TExcelApplication;
      Sheet: variant;
      RecCount: integer;
      FileName: string;
      PathName: string;
      RecordCount: integer;
      constructor create(bWrite: boolean; sFileName: string); virtual;
      function ReadData: boolean; virtual;
      function dlData: boolean; virtual;
      destructor Destroy; virtual;
   end;
   TYhxxExcel = class(TExcel)
      yhxx: Tyhxx;
      constructor create(bWrite: boolean; sFileName: string); overload;
      destructor Destroy; overload;
      function ReadData: boolean; overload;
      function dlData: boolean; overload;
   end;
   TBjxxExcel = class(TExcel)
      Bjbh: string;
      Bjmc: string;
      zybh: string;
      constructor create(bWrite: boolean; sFileName: string); overload;
      destructor Destroy; overload;
      function ReadData: boolean; overload;
     // function dlData: boolean; overload;
   end;

implementation

uses DM_DataModal;

{ TExcel }

constructor TExcel.create(bWrite: boolean; sFileName: string);
begin
   ExcelApp := TExcelApplication.Create(application);
   ExcelApp.Connect;
   ExcelApp.Workbooks.Add(sFileName, 0); //(OpenDialog1.FileName, 0);
   sheet := ExcelApp.Workbooks[1].Worksheets[1];
   RecCount := 2;
end;

destructor TExcel.Destroy;
begin
   ExcelApp.Disconnect;
   Excelapp.Quit;
   Excelapp.Free;
end;

function TExcel.dlData: boolean;
begin

end;

function TExcel.ReadData: boolean;
begin

end;

{ TYhxxExcel }

constructor TYhxxExcel.create(bWrite: boolean; sFileName: string);
begin
   inherited;
   yhxx := Tyhxx.create;
end;

destructor TYhxxExcel.Destroy;
begin
   inherited;
   yhxx.Free;
end;

function TYhxxExcel.dlData: boolean;
begin
   result := False;   
   RetVal := yhxx.RetVal;
   RetMsg := yhxx.RetMsg;
   if RetVal = 0 then Result := True;
end;

function TYhxxExcel.ReadData: boolean;
begin
   result := False;
   try
      if trim(sheet.cells[RecCount, 1]) <> '' then
      begin
         yhxx.Yhbh := trim(sheet.cells[RecCount, 1]);
         yhxx.Yhxm := trim(sheet.cells[RecCount, 2]);
         yhxx.Xb := trim(sheet.cells[RecCount, 3]);
         yhxx.Bjbh := trim(sheet.cells[RecCount, 4]);
         yhxx.Sfzh := trim(sheet.cells[RecCount, 5]);
         yhxx.Track1 := trim(sheet.cells[RecCount, 6]);
         yhxx.Track2 := trim(sheet.cells[RecCount, 7]);
         yhxx.Track3 := trim(sheet.cells[RecCount, 8]);
         inc(RecCount);
         result := True;
      end;
   except
      Retval := -1;
      RetMsg := '操作异常';
   end;
end;


constructor TBjxxExcel.create(bWrite: boolean; sFileName: string);
begin
   inherited;
end;

destructor TBjxxExcel.Destroy;
begin

end;



function TBjxxExcel.ReadData: boolean;
begin
   result := False;
   try
      if trim(sheet.cells[RecCount, 1]) <> '' then
      begin
         bjbh := trim(sheet.cells[RecCount, 1]);
         bjmc := trim(sheet.cells[RecCount, 2]);
         zybh := trim(sheet.cells[RecCount, 3]);
         inc(RecCount);
         result := True;
      end;
   except
      Retval := -1;
      RetMsg := '操作异常';
   end;

end;

end.

⌨️ 快捷键说明

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