Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Servers
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 22-09-2007
Avatar de GustavoCruz
GustavoCruz GustavoCruz is offline
Miembro
 
Registrado: jul 2006
Ubicación: Sampués Sucre (Colombia)
Posts: 293
Poder: 18
GustavoCruz Va por buen camino
Question Encuentro código en internet sobre excel... Alguien puede mejorarlo...

Prueba con esta funcion que escribio uno de los muchos gurus de delphi


Código Delphi [-]
 
procedure SendToExcel(aDataSet: TDataSet); 
var 
  PreviewToExcel: TExcelApplication; 
  RangeE: Excel2000.ExcelRange; //or RangeE: Excel97.Range 
  I, Row: Integer; 
  Bookmark: TBookmarkStr; 
begin 
  PreviewToExcel := TExcelApplication.Create(Self); 
  PreviewToExcel.Connect; 
  PreviewToExcel.Workbooks.Add(NULL, 0); 
  RangeE := PreviewToExcel.ActiveCell; 
  for I := 0 to aDataSet.Fields.Count - 1 do 
  begin 
    RangeE.Value := aDataSet.Fields[i].DisplayLabel; 
    RangeE := RangeE.Next; 
  end; 
  aDataSet.DisableControls; 
  try 
    Bookmark := aDataSet.Bookmark; 
    try 
      aDataSet.First; 
      Row := 2; 
      while not aDataSet.EOF do 
      begin 
        //Write down Record As Row in msExcel 
        RangeE := PreviewToExcel.Range['A' + IntToStr(Row), 'A' + IntToStr(Row)]; 
        for I := 0 to aDataSet.Fields.Count - 1 do 
        begin 
          RangeE.Value := aDataSet.Fields[i].AsString; 
          RangeE := RangeE.Next; 
        end; 
        aDataSet.Next; 
        Inc(Row); 
      end; 
    finally 
      aDataSet.Bookmark := Bookmark; 
    end; 
  finally 
    aDataSet.EnableControls; 
  end; 
  RangeE := PreviewToExcel.Range['A1', chr(64 + aDataSet.Fields.Count) + 
IntToStr(Row - 1)]; 
  RangeE.AutoFormat(8, NULL, NULL, NULL, NULL, NULL, NULL); 
  PreviewToExcel.Visible[0] := True; 
  PreviewToExcel.Disconnect; 
end;

La cuestión es que al implementarlo demora mucho para mostrar el resultado, esto cuando el dataset es grande
Responder Con Cita
  #2  
Antiguo 22-09-2007
pcicom pcicom is offline
Miembro
 
Registrado: may 2003
Ubicación: MONTERREY MEXICO
Posts: 253
Poder: 22
pcicom Va por buen camino
Cita:
Empezado por GustavoCruz Ver Mensaje
Prueba con esta funcion que escribio uno de los muchos gurus de delphi


Código Delphi [-]
 
procedure SendToExcel(aDataSet: TDataSet); 
var 
  PreviewToExcel: TExcelApplication; 
  RangeE: Excel2000.ExcelRange; //or RangeE: Excel97.Range 
  I, Row: Integer; 
  Bookmark: TBookmarkStr; 
begin 
  PreviewToExcel := TExcelApplication.Create(Self); 
  PreviewToExcel.Connect; 
  PreviewToExcel.Workbooks.Add(NULL, 0); 
  RangeE := PreviewToExcel.ActiveCell; 
  for I := 0 to aDataSet.Fields.Count - 1 do 
  begin 
    RangeE.Value := aDataSet.Fields[i].DisplayLabel; 
    RangeE := RangeE.Next; 
    Application.processmessages;

  end; 
  aDataSet.DisableControls; 
  try 
    Bookmark := aDataSet.Bookmark; 
    try 
      aDataSet.First; 
      Row := 2; 
      while not aDataSet.EOF do 
      begin 
    Application.processmessages;

        //Write down Record As Row in msExcel 
        RangeE := PreviewToExcel.Range['A' + IntToStr(Row), 'A' + IntToStr(Row)]; 
        for I := 0 to aDataSet.Fields.Count - 1 do 
        begin 
          RangeE.Value := aDataSet.Fields[i].AsString; 
          RangeE := RangeE.Next; 
    Application.processmessages;

        end; 
        aDataSet.Next; 

        Inc(Row); 
      end; 
    finally 
    Application.processmessages;

      aDataSet.Bookmark := Bookmark; 

    end; 
  finally 
    aDataSet.EnableControls; 
  end; 
    Application.processmessages;

  RangeE := PreviewToExcel.Range['A1', chr(64 + aDataSet.Fields.Count) + 
IntToStr(Row - 1)]; 
    Application.processmessages;

  RangeE.AutoFormat(8, NULL, NULL, NULL, NULL, NULL, NULL); 
    Application.processmessages;

  PreviewToExcel.Visible[0] := True; 
  PreviewToExcel.Disconnect; 
end;

La cuestión es que al implementarlo demora mucho para mostrar el resultado, esto cuando el dataset es grande

Puedes Agregar entre el CODIGO instrucciones:

Application.processmessages;

Y Veras que se acelerara la presntacion..
__________________
Poco ha de saber el que no pregunta.. Yo por eso soy un pregunton
Responder Con Cita
  #3  
Antiguo 22-09-2007
Avatar de GustavoCruz
GustavoCruz GustavoCruz is offline
Miembro
 
Registrado: jul 2006
Ubicación: Sampués Sucre (Colombia)
Posts: 293
Poder: 18
GustavoCruz Va por buen camino
Muchas gracias pcicom, pero el problema continua, los dataset que se generan superan los 2800 registros..., pero en todo caso gracias; ya por lo menos la aplicación no se queda paralizada.
Responder Con Cita
  #4  
Antiguo 23-09-2007
Avatar de Lepe
[Lepe] Lepe is offline
Miembro Premium
 
Registrado: may 2003
Posts: 7.424
Poder: 29
Lepe Va por buen camino
Cuantos más Application.ProcessMessages pongas... más se ralentizará los bucles.

Es cierto que tu interfaz, responderá de forma más ágil, podrás mover el ratón, pulsar botones, etc..., pero el tiempo total de espera se incrementa notablemente.

No he trabajado con automatización OLE, pero si el código original no tiene ningun processMessages, es que no son necesarios.

El primero que aparece sobra. ¿Cuantos campos tendrá un registro? 10 como mucho?, no hace falta una pausa por cada uno de ellos.

Yo solo dejaría 2 Processmessages, el segundo y el último.

Lo que sí podrías añadir es un label diciendo "Exportando registro 3 de 3000" ... por ejemplo.

Saludos
__________________
Si usted entendió mi comentario, contácteme y gustosamente,
se lo volveré a explicar hasta que no lo entienda, Gracias.
Responder Con Cita
  #5  
Antiguo 23-09-2007
pcicom pcicom is offline
Miembro
 
Registrado: may 2003
Ubicación: MONTERREY MEXICO
Posts: 253
Poder: 22
pcicom Va por buen camino
Cita:
Empezado por GustavoCruz Ver Mensaje
Prueba con esta funcion que escribio uno de los muchos gurus de delphi


Código Delphi [-]
 
procedure SendToExcel(aDataSet: TDataSet); 
var
  xFile:TextFile;
  cFile:String; 
  I, Row: Integer; 
begin 
  cFile := 'reporte.xls';
  AssignFile(xFile,cFile);
  writeln(xFile,'');
  writeln(xFile,'');

  for I := 0 to aDataSet.Fields.Count - 1 dobegin 
         
    RangeE.Value := aDataSet.Fields[i].DisplayLabel; 
    RangeE := RangeE.Next; 
  end;
  writeln(xFile,'');
 
  aDataSet.DisableControls; 
  try 
    Bookmark := aDataSet.Bookmark; 
    try 
      aDataSet.First; 
      Row := 2; 
      whilenot aDataSet.EOF dobegin//Write down Record As Row in msExcel 
        RangeE := PreviewToExcel.Range['A' + IntToStr(Row), 'A' + IntToStr(Row)]; 
        for I := 0 to aDataSet.Fields.Count - 1 dobegin 
          RangeE.Value := aDataSet.Fields[i].AsString; 
          RangeE := RangeE.Next; 
        end; 
        aDataSet.Next; 
        Inc(Row); 
      end; 
    finally 
      aDataSet.Bookmark := Bookmark; 
    end; 
  finally 
    aDataSet.EnableControls; 
  end; 
  RangeE := PreviewToExcel.Range['A1', chr(64 + aDataSet.Fields.Count) + 
IntToStr(Row - 1)]; 
  RangeE.AutoFormat(8, NULL, NULL, NULL, NULL, NULL, NULL); 
  PreviewToExcel.Visible[0] := True; 
  PreviewToExcel.Disconnect; 

  writeln(xFile,'
'
); close(xFile); end;

La cuestión es que al implementarlo demora mucho para mostrar el resultado, esto cuando el dataset es grande


OTRA FORMA es que CREES el XLS al vuelo como un archivo tipo HTML con extencin de EXCEL .xls, y despues lo abres..
__________________
Poco ha de saber el que no pregunta.. Yo por eso soy un pregunton
Responder Con Cita
  #6  
Antiguo 23-09-2007
pcicom pcicom is offline
Miembro
 
Registrado: may 2003
Ubicación: MONTERREY MEXICO
Posts: 253
Poder: 22
pcicom Va por buen camino
OTRA FORMA es que CREES el XLS al vuelo como un archivo tipo HTML con extencin de EXCEL .xls, y despues lo abres..


Código PHP:
procedure SendToExcelFromHTML(aDataSetTDataSet); 
var
  
xFile:TextFile;
  
cFile:String
  
IRowInteger
begin 
  cFile 
:= 'reporte.xls';
  
AssignFile(xFile,cFile);
  
writeln(xFile,'<table border=1>');
  
writeln(xFile,'<th>');
  
  for 
:= 0 to aDataSet.Fields.Count do 
    
writeln(xFile,'<td>' aDataSet.Fields[i].DisplayLabel '</td>'); 

  
writeln(xFile,'</th>');
 
  try 
      
aDataSet.First
      while 
not aDataSet.EOF do 
      
begin
        Application
.processmessagess;
        
writeln(xFile,'<tr>');

        for 
:= 0 to aDataSet.Fields.Count do 
           
writeln(xFile,'<td>' aDataSet.Fields[i].AsString '</td>'); 
        
aDataSet.Next
        
writeln(xFile,'</tr>');
        
Inc(Row); 
      
end
  
finally 

  end


  
writeln(xFile,'</table>');
  
closeFile(xFile);
 
  
ShellExecute(Form1.Handle,nil,PChar(cFile),'','',SW_SHOWNORMAL);   
  
end

La cuestión es que al implementarlo demora mucho para mostrar el resultado, esto cuando el dataset es grande[/quote]

<table>
__________________
Poco ha de saber el que no pregunta.. Yo por eso soy un pregunton

Última edición por pcicom fecha: 23-09-2007 a las 15:22:22.
Responder Con Cita
Respuesta



Normas de Publicación
no Puedes crear nuevos temas
no Puedes responder a temas
no Puedes adjuntar archivos
no Puedes editar tus mensajes

El código vB está habilitado
Las caritas están habilitado
Código [IMG] está habilitado
Código HTML está deshabilitado
Saltar a Foro

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Alguien puede recomedar algun componente VCL para código de Barras ??? QuarkBcn Impresión 5 29-04-2007 14:07:55
Donde encuentro el codigo de CAERQUES dtomeysoto Conexión con bases de datos 6 19-05-2006 22:28:58
Ehm, alguien me puede facilitar éste código? gatsu PHP 3 09-07-2004 13:35:01
donde encuentro manuales de Kylix con codigo gaoss Lazarus, FreePascal, Kylix, etc. 0 25-03-2004 20:25:30
alguien sabe donde encuentro quickreport en delphi 7 pzala Impresión 2 30-11-2003 19:22:40


La franja horaria es GMT +2. Ahora son las 09:18:23.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi
Copyright 1996-2007 Club Delphi