else result:=0;
end;
else result:=0;
end;
end;
begin
{If the list has <= 1 element, it's sorted}
if (min >= max) then Exit;
{Pick a dividing item randomly}
i := min + Trunc(Random(max - min + 1));
med_value := List[i];
List[i] := List[min]; { Swap it to the front so we can find it easily}
{Move the items smaller than this into the left
half of the list. Move the others into the right}
lo := min;
hi := max;
while (True) do
begin
// Look down from hi for a value < med_value.
while compare(Grid.cells[sortcol,List[hi]]
,grid.cells[sortcol,med_value])>=0 do
(*ANSIComparetext(Grid.cells[sortcol,List[hi]]
,grid.cells[sortcol,med_value])>=0 do*)
begin
hi := hi - 1;
if (hi <= lo) then Break;
end;
if (hi <= lo) then
begin {We're done separating the items}
List[lo] := med_value;
Break;
end;
// Swap the lo and hi values.
List[lo] := List[hi];
inc(lo); {Look up from lo for a value >= med_value}
while Compare(grid.cells[sortcol,List[lo]],
grid.cells[sortcol,med_value])<0 do
begin
inc(lo);
if (lo >= hi) then break;
end;
if (lo >= hi) then
begin {We're done separating the items}
lo := hi;
List[hi] := med_value;
break;
end;
List[hi] := List[lo];
end;
{Sort the two sublists}
Quicksort(Grid,List, min, lo - 1,sortcol,datatype);
Quicksort(Grid,List, lo + 1, max,sortcol,datatype);
end;
//datatype 0:按字符排序 1:按整型排序 2:按浮点型排序
procedure Sortgrid(Grid : TStringGrid; sortcol,datatype:integer);
var
i : integer;
tempgrid:tstringGrid;
list:array of integer;
begin
screen.cursor:=crhourglass;
tempgrid:=TStringgrid.create(nil);
with tempgrid do
begin
rowcount:=grid.rowcount;
colcount:=grid.colcount;
fixedrows:=grid.fixedrows;
end;
with Grid do
begin
setlength(list,rowcount-fixedrows);
for i:= fixedrows to rowcount-1 do
begin
list[i-fixedrows]:=i;
tempgrid.rows[i].assign(grid.rows[i]);
end;
quicksort(Grid, list,0,rowcount-fixedrows-1,sortcol,datatype);
for i:=0 to rowcount-fixedrows-1 do
begin
rows[i+fixedrows].assign(tempgrid.rows[list[i]])
end;
row:=fixedrows;
end;
tempgrid.free;
setlength(list,0);
screen.cursor:=crdefault;
end;
//排序结束*********************************************************************
procedure TForm1.btn1Click(Sender: TObject);
var
excelx:string;
ExcelApp:Variant;
workBook:OleVariant;
excelRowCount,excelColCount:longint;
i,j:integer;
begin
pb1.Min:=0;
dlgOpen1.Filter:='Excel文件|*.xls|*.xlsx';
if dlgOpen1.Execute then
begin
try
ExcelApp:=CreateOleObject('Excel.Application');
workBook:=ExcelApp.WorkBooks.open(dlgOpen1.FileName);
ExcelApp.visible:=False;
excelRowCount:=ExcelApp.ActiveSheet.UsedRange.Rows.count;// 行数
excelColCount:=ExcelApp.ActiveSheet.UsedRange.Columns.Count; // 列数
strngrd1.RowCount := excelRowCount;
strngrd1.ColCount := excelColCount;
pb1.Max:=excelRowCount;
for i:=0 to strngrd1.RowCount-1 do
begin
pb1.StepBy(1);
for j:=0 to strngrd1.ColCount-1 do
begin
excelx:=excelapp.cells[i+1,j+1].value;
if (excelx<>'') then
strngrd1.Cells[j,i]:=excelx else
strngrd1.Cells[j,i]:='0'
end;
end;
pb1.Position:=0;
strngrd1.Cols[6]:=strngrd1.Cols[7];
delcol(7,strngrd1);
SetAllColWidth(strngrd1);
// ComboBox1.Items.Text:=strngrd1.Rows[0].Text;
// ComboBox1.Items.Delete(0);
lbl7.Caption:='共有:'+inttostr(excelRowCount-1)+' 条记录';
finally
workBook.Close;
ExcelApp.quit;
ExcelApp := Unassigned;
WorkBook := Unassigned;
end;
end;
end;
end.