本文整理自网络,侵删。
const xlCellTypeLastCell = $0000000B; var ExlApp, Sheet: OLEVariant; i, j, r, c: integer; namestr: string; checkdata: string; tempstr: string; begin ExlApp := CreateOleObject('Excel.Application'); ExlApp.Visible := false; ExlApp.Workbooks.Open(path); Sheet := ExlApp.Workbooks[ExtractFileName(path)].WorkSheets[1]; Sheet.Cells.SpecialCells(xlCellTypeLastCell, EmptyParam).Activate; r := ExlApp.ActiveCell.Row; c := ExlApp.ActiveCell.Column;
//Grid.RowCount:=r; // c :=Grid.ColumnCount; // Form2.Caption:='加载进度 0%';
Application.ProcessMessages; for j:= 1 to r do begin try if (j mod 1000 = 0) then begin Caption:='加载进度'+FormatFloat('0.00%',(j/r*100)); // ProgressBar1.Position :=(j/r*100);
Application.ProcessMessages; end;
for i:= 1 to c do begin StringGrid1.Cells[i-1,j-1]:=sheet.cells[j,i];
end; except on e:exception do //ShowMessage(inttostr(j)+' '+e.Message); end; end; Caption:='加载进度 100%'; //ProgressBar1.Position:=0;
ExlApp.Quit; ExlApp := Unassigned; Sheet := Unassigned;
补充:StringGrid 实例1:初始化StirngGrid的首行和首列实例1:初始化StirngGrid的首行和首列
// 主要代码部分:
procedure TForm23.SetSGridTitle(Sender: TObject);
var
ColIndex, RowIndex: integer;
begin
//画第一行(标题栏)
for colIndex := 1 to StringGrid1.ColumnCount do
begin
StringGrid1.Cells[colIndex, 0] := '列名' + Chr(ord('A') - 1 + colIndex);
end;
//画第一列(数字栏)
StringGrid1.Columns[0].Width := 30;
StringGrid1.Cells[0, 0] := '序列';
for RowIndex := 1 to StringGrid1.RowCount - 1 do
begin
StringGrid1.Cells[0, RowIndex] := IntToStr(RowIndex);
end;
end;来源:https://www.cnblogs.com/lingzhiwen/p/3321947.html
相关阅读 >>
Delphi下idhttp配合cookiemanager获取cookie
Delphi xe5实现通过tmemorystream将一个unicodestring写入到一个unicode文本文件
Delphi windows 编程[20] - 改变菜单项并换行
更多相关阅读请进入《Delphi》频道 >>