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-04-2009
fsolispa fsolispa is offline
Miembro
 
Registrado: sep 2008
Posts: 28
Poder: 0
fsolispa Va por buen camino
Cita:
Empezado por nuk3zito Ver Mensaje
Es algo así...


Código Delphi [-]
var
Excel, Libro, xlSheet: Variant;






Código Delphi [-]
try
Excel := GetActiveOleObject('Excel.Application');
except
Excel := CreateOleObject('Excel.Application');
end;






Código Delphi [-]
if bGenerarArchivo then
begin
Libro:= Excel.WorkBooks.Add(xlWBATWorksheet);
xlSheet:= Excel.WorkBooks[1].Sheets[1];
xlSheet.Name:= sSheetName;
end
else
begin
Libro:= Excel.Workbooks.Open(sArchivo);
xlSheet:= Libro.Worksheets.Item[sSheetName];
end;





Donde bGenerarArchivo es una variable booleana que indica si el archivo se crea o se abre; sArchivo es una variable string con la ruta y nombre del archivo; y sSheetName es el nombre de la hoja a donde vas a escribir.

Toma en cuenta que este ejemplo es sin usar TExcelApplication (por eso puse el codigo con el que se crea el objeto), así que usándolo debe ser algo muy parecido.

Saludos.
Muchas gracias.
Responder Con Cita
  #2  
Antiguo 22-04-2009
fsolispa fsolispa is offline
Miembro
 
Registrado: sep 2008
Posts: 28
Poder: 0
fsolispa Va por buen camino
Cita:
Empezado por fsolispa Ver Mensaje
Muchas gracias.
Ya realice las modificaciones necesarias de acuerdo a la información que me diste y trabaja super bien, no utilice el comando

Try
Excel := GetActiveOleObject('Excel.Application')
Except
Excel := CreateOleObject('Excel.Application')
End;

ya que me daba error al leer, entonces lo solo cree, como no creare un nuevo archivo de excel solo utilice los comandos necesarios que fueron

Libro := Excel.WorkBooks.Open(sArchivo);
xlSheet := Libro.WorkSheets.Item[sShetName);

Dentro de un if para determinar la hoja de excel en la que se guardará la información y un while para llenarla el programa quedo así

procedure TGeneraListasFrm.SpeedButton2Click(Sender: TObject);
Var
Excel, Libro, Hoja : Variant;
i : integer;
begin
i := 7;
Excel := CreateOleObject('Excel.Application');
Libro := Excel.WorkBooks.Open('E:\Mis Documentos\feb08.xls');
if ModuloDatosFrm.ZListaQrycgrado.Value = 'PREP01' then
Begin
Hoja := Libro.WorkSheets.Item[6];
With ModuloDatosFrm.ZListaQry Do
Begin
First;
while not EOF do
Begin
i := i + 1;
Hoja.Cells.Item[i,1] := DbGrid1.Fields[0].AsString;
Next;
End;
End;
Excel.Visible := True;
End
Else if ModuloDatosFrm.ZListaQrycgrado.Value = 'PREP02' then
Begin
Hoja := Libro.WorkSheets.Item[7];
With ModuloDatosFrm.ZListaQry Do

bueno y continua hasta 'PREP06'
Responder Con Cita
  #3  
Antiguo 22-04-2009
Avatar de nuk3zito
nuk3zito nuk3zito is offline
Miembro
 
Registrado: ago 2003
Ubicación: "Z" Land
Posts: 244
Poder: 21
nuk3zito Va por buen camino
Very good!
__________________
Tiempo y ocasión acontecen a todos!
Responder Con Cita
  #4  
Antiguo 22-04-2009
Avatar de nuk3zito
nuk3zito nuk3zito is offline
Miembro
 
Registrado: ago 2003
Ubicación: "Z" Land
Posts: 244
Poder: 21
nuk3zito Va por buen camino
Para los que quieren un poquitito más de teoría referente a lo que se vio en este hilo... aquí tienen una page:

Deborah Pate's Page


Es un artículo viejito... pero vigente.

Saludos.
__________________
Tiempo y ocasión acontecen a todos!
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


La franja horaria es GMT +2. Ahora son las 03:10:52.


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