我想计算一个EXCEL文件中第一列单元格中的数字是否有重复值,
需要一个高效的算法!请参与讨论!谢谢!
我用了最笨的办法,如下:
for i:=1 to count-1 do
begin
for j:=i+1 to count do
begin
if (strtoint(Form1.ExcelWorksheet1.Cells.Item[i,1])=strtoint
(Form1.ExcelWorksheet1.Cells.Item[j,1])) then
showmessage('第'+inttostr(i)+'行和第'+inttostr(j)+'行重复!');
end;
end;
if i>=count then
showmessage('没有重复值!');勿笑,嘻嘻,谢谢!
需要一个高效的算法!请参与讨论!谢谢!
我用了最笨的办法,如下:
for i:=1 to count-1 do
begin
for j:=i+1 to count do
begin
if (strtoint(Form1.ExcelWorksheet1.Cells.Item[i,1])=strtoint
(Form1.ExcelWorksheet1.Cells.Item[j,1])) then
showmessage('第'+inttostr(i)+'行和第'+inttostr(j)+'行重复!');
end;
end;
if i>=count then
showmessage('没有重复值!');勿笑,嘻嘻,谢谢!
vActiveWorkbook: OleVariant;
begin
ExcelApplication1.Disconnect;
ExcelApplication1.Connect;
ExcelApplication1.Workbooks.Add('C:\temp\temp.xls', 0);
vActiveWorkbook := ExcelApplication1.ActiveWorkbook;
DeleteFile('C:\temp\temp.txt');
vActiveWorkbook.SaveAs('C:\temp\temp.txt', xlText, False);
ExcelApplication1.Disconnect;
end;
ss: WideString;ss:='';
for i:=1 to count-1 do
begin
if Pos('|'+Form1.ExcelWorksheet1.Cells.Item[i,1]+'|')>0 then
begin
j:=自己解析出
showmessage('第'+inttostr(i)+'行和第'+inttostr(j)+'行重复!');
Break;
end
ss:=ss+'|'+Form1.ExcelWorksheet1.Cells.Item[i,1]+'|'+'['+IntToStr(i)+']';
end;
for i:=1 to count-1 do
begin
if Pos('|'+Form1.ExcelWorksheet1.Cells.Item[i,1]+'|',ss)>0 then
begin
j:=自己解析出
showmessage('第'+inttostr(i)+'行和第'+inttostr(j)+'行重复!');
Break;
end
ss:=ss+'|'+Form1.ExcelWorksheet1.Cells.Item[i,1]+'|'+'['+IntToStr(i)+']';
end;