📄 unit1.pas
字号:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs,ComObj, StdCtrls, ComCtrls, ExtCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
OpenDialog1: TOpenDialog;
Button2: TButton;
Panel1: TPanel;
LabeledEdit1: TLabeledEdit;
UpDown1: TUpDown;
LabeledEdit2: TLabeledEdit;
LabeledEdit3: TLabeledEdit;
UpDown2: TUpDown;
UpDown3: TUpDown;
LabeledEdit4: TLabeledEdit;
StaticText1: TStaticText;
LabeledEdit5: TLabeledEdit;
UpDown4: TUpDown;
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
Excel:Variant;
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.Button1Click(Sender: TObject);
var
sheetno,colno,startrow,endrow,i,j:Integer;
flagarray:array of boolean;
line:String;
begin
sheetno:=UpDown1.Position;
colno:=UpDown4.Position;
startrow:=UpDown2.Position;
endrow:=UpDown3.Position;
line:='';
if endrow-startrow+1>0 then
begin
SetLength(flagarray,endrow-startrow+1);
for i:=0 to endrow-startrow+1 do
flagarray[i]:=true;
end;
Memo1.Lines.Append('Sheet Number:'+IntToStr(sheetno)+' Column:'+IntToStr(colno)+' Start Row:'+IntToStr(startrow)+' End Row:'+IntToStr(endrow));
if LabeledEdit1.Text<>'' then
begin
Excel.WorkSheets[sheetno].activate;
for i:=startrow to endrow-1 do
begin
for j:=i+1 to endrow do
begin
if (VarToStr(Excel.WorkSheets[sheetno].Cells[i,colno].value)<>'') and (VarToStr(Excel.WorkSheets[sheetno].Cells[j,colno].value)<>'') then
begin
if flagarray[j-startrow] and (i<>j) and (VarToStr(Excel.WorkSheets[sheetno].Cells[i,colno].value)=VarToStr(Excel.WorkSheets[sheetno].Cells[j,colno].value)) then
begin
if flagarray[i-startrow] then
line:=line+IntToStr(i);
if flagarray[j-startrow] then
line:=line+'<=>'+IntToStr(j);
flagarray[j-startrow]:=false;
flagarray[i-startrow]:=false;
end;
end
end;
if line<>'' then
Memo1.Lines.Append(line);
line:='';
end;
Memo1.Lines.Append('处理完成');
end
else
ShowMessage('请输入文件名!');
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
try
Excel:=createOleObject('Excel.Application');
except
on Exception do raise exception.Create('程序需要安装EXCEL,请确认是否已安装EXCEL');
end;
end;
procedure TForm1.FormDestroy(Sender: TObject);
begin
Excel.WorkBooks.Close;
// Excel.quit;
end;
procedure TForm1.Button2Click(Sender: TObject);
begin
if OpenDialog1.Execute then
begin
LabeledEdit1.Text:=OpenDialog1.FileName;
Excel.WorkBooks.Close;
end;
if LabeledEdit1.Text<>'' then
try
Excel.WorkBooks.Open(LabeledEdit1.Text);
except
on Exception do raise exception.Create('无法打开指定的文件!');
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -