Ver Mensaje Individual
  #3  
Antiguo 31-05-2011
Avatar de alej.villa
alej.villa alej.villa is offline
Miembro
NULL
 
Registrado: may 2011
Ubicación: Caracas, Venezuela
Posts: 76
Reputación: 13
alej.villa Va por buen camino
buenos dias yo estoy tratando de exportar los datos de un dbgrid a excel 2007 tengo el siguiente codigo de delphi 7
procedure TformEmpleados.Button1Click(Sender: TObject);
var Excel, Libro : Variant;
var i:integer;
begin
// Crea una aplicacion Excel.
Excel := CreateOleObject ('Excel.Application');
// La muestra (vas a ver un Excel como si lu ubieras ejecutado)
Excel.Visible := True;
// Agrega un libro.
Excel.WorkBooks.Add (-4167);
// Le asigna un nombre al libro
Excel.WorkBooks[1].WorkSheets[1].Name := 'Reporte';
// Hace un puntero al libro del Excel.
Libro := Excel.WorkBooks[1].WorkSheets['Reporte'];

dm.Query.SQL.Add ('Select cedula, nombres, apellidos, sexo, turno, fecha_ingreso, cargo from Empleados');
dm.Query.Open;
i:=1;
while not dm.Query.EOF do
begin
// aqui le ponemos nombre a los campos
Libro.Cells [1,1] := 'Cedula';
Libro.Cells [1,2] := 'Nombre';
Libro.Cells [1,3] := 'Apellido';
Libro.Cells [1,4] := 'Sexo';
Libro.Cell [1,5] := 'Turno';
Libro.Cell [1,6] := 'Fecha de Ingreso';
Libro.Cell [1,7] := 'Cargo';
i:=i+1;
Libro.Cells [i,1] := dm.Query.FieldByName ('cedula').AsString;
Libro.Cells [i,2] := dm.Query.FieldByName ('nombres').AsString;
Libro.Cells [i,3] := dm.Query.FieldByName ('apellidos').AsString;
Libro.Cells [i,4] := dm.Query.FieldByName ('sexo').AsString;
Libro.cells [i,5] := dm.Query.FieldByName ('turno').AsString;
Libro.Cells [i,6] := dm.Query.FieldByName ('fecha_ingreso').AsString;
Libro.Cells [i,7] := dm.Query.FieldByName ('cargo').AsString;

dm.Query.Next;
end;

//Query.Close;
end;

en estas lineas
Libro.Cell [1,5] := 'Turno';
Libro.Cell [1,6] := 'Fecha de Ingreso';
Libro.Cell [1,7] := 'Cargo';
me dice un error de 'Method 'Cells' not supported by automation object'
quisiera que me explicaran un poco porque sucede este error y como puedo solucionarlo

Gracias!
Responder Con Cita