TExcelApplication, provoca travamento
07/07/2004
0
Estou usando a classe TExcelApplication para gerar uma planilha excel, aparentemente por a planilha gerada ser grande (na verdade nem tão grande assim) rotina trava, alguém sabe se há limite para isto.
Faltou algum tratamento ?
function DataSetToExcelFile(ds: TDataSet;ExcelFile: String):Boolean; var bResult: Boolean; SavePlace: TBookmark; i,eline: Integer; Excel: TExcelApplication; r : Excel97.Range; w : _WorkBook; celula : string; begin bResult:= False; // If dataset is assigned and active runs Excel if Assigned(ds) then begin if ds.Active then begin try Excel:= TExcelApplication.Create(Application); Excel.Connect; Excel.Visible[0] := False; w := Excel.WorkBooks.Add(null,0); r := Excel.ActiveCell; // Save grid Position SavePlace:= ds.GetBookmark; ds.First; // Dataset Header eline:= 1; // First Line of Sheet if not (ds.Eof) then begin for i:=0 to (ds.FieldCount-1) do begin r.Value := ds.Fields[i].DisplayLabel; r := r.Next; end; end; while not ds.Eof do // Detail begin Inc(eline); // Add 1 to the line of Sheet celula := ´A´ + IntToStr(eline); r := Excel.Range[celula,celula]; for i:=0 to (ds.FieldCount-1) do begin r.Value := ds.Fields[i].Value; r := r.Next; end; ds.Next; end; // Set saved grid position ds.GotoBookmark(SavePlace); // Save the file w.SaveAs(ExcelFile,null,null,null,null,null,ACCESS_OBJECT_GUID,null,null,null,null,0); w.Close(null,null,null,0); Excel.Disconnect; Excel.Quit; Excel.Free; bResult:= True; except on e:exception do begin showmessage(e.message); bResult:= False; end; end; end; end; Result := bResult; end;
Faltou algum tratamento ?
Motta
Curtir tópico
+ 0
Responder
Posts
09/07/2004
Lucas Silva
Coloque um [b:4e26f70a35]Application.ProcessMessages [/b:4e26f70a35]dentro dos loop´s
Responder
09/07/2004
Motta
não funcionou, continua travando ...
tentei um diablecontrols e enablecontrols mas tb não deu certo, só trava quando o resultset é maiorzinho,acjo que é limite de processamento.
sabe de algum método , salvar parcialmente , fecth do cursor etc ?
grato !
tentei um diablecontrols e enablecontrols mas tb não deu certo, só trava quando o resultset é maiorzinho,acjo que é limite de processamento.
sabe de algum método , salvar parcialmente , fecth do cursor etc ?
grato !
Responder
Clique aqui para fazer login e interagir na Comunidade :)