Ver Mensaje Individual
  #4  
Antiguo 27-02-2008
lgarcia lgarcia is offline
Miembro
 
Registrado: jul 2004
Posts: 479
Reputación: 20
lgarcia Va por buen camino
Insercion de datos en varias hojas de Excel

Hola:

En este caso te recomiendo trabajar sobre una plantilla de Excel, por que tiene las facilidades de que puedes formatear las columnas con el tipo de datos que vas a pasarle. Aqui te pongo un pequeño ejemplo que copia datos desde 3 StoreProcedure y llena tres hojas de excel en la casillas que uno desee.

Código:
Procedure InsertarExcel;
var
  Excel, Libro: Variant;
  Nombre: string;
  dia, mes: string;
  Year, Month, Day: Word;
begin
        DecodeDate(dtp1.Date, Year, Month, Day);
        dia:= IntToStr(Day);
        mes:= IntToStr(Month);
        RellenarCeros(dia);
        RellenarCeros(mes);
        nombre:= '13' + dia + mes + IntToStr(Year);
        Excel:=CreateOleObject('Excel.Application');
        Excel.Visible := False;
        Excel.DisplayAlerts:= False;
        Excel.WorkBooks.Add('C:\Archivos de programa\PMO\XDDMMAAAA.xlt');
        Excel.WorkBooks[1].WorkSheets[1].Name := 'MONTO DE EFECTIVO CONTADO';
        Libro := Excel.WorkBooks[1].WorkSheets['MONTO DE EFECTIVO CONTADO'];
        Libro.Cells [5,2] := DateToStr(dtp1.Date);
        with Conteo do
        begin
          Close;
          Parameters.ParamByName('@fecha').Value:= Int(dtp1.Date);
          Open;
        end;
        Conteo.First;
        while not (Conteo.Eof) do
        begin
          case Conteoid.Value of
            1:Libro.Cells [5,2] := Conteoimporte.Value;
            2:Libro.Cells [6,2] := Conteoimporte.Value;
            3:Libro.Cells [8,2] := Conteoimporte.Value;
            4:Libro.Cells [16,2] := Conteoimporte.Value;
            5:Libro.Cells [9,2] := Conteoimporte.Value;
            6:Libro.Cells [14,2] := Conteoimporte.Value;
            7:Libro.Cells [11,2] := Conteoimporte.Value;
            8:Libro.Cells [7,2] := Conteoimporte.Value;
            9:Libro.Cells [10,2] := Conteoimporte.Value;
          end;
          Conteo.Next;
        end;
        Excel.WorkBooks[1].WorkSheets[2].Name := 'PUNTOS NEGATIVOS EN EL DÍA';
        Libro := Excel.WorkBooks[1].WorkSheets['PUNTOS NEGATIVOS EN EL DÍA'];
        Libro.Cells [5,2] := DateToStr(dtp1.Date);
        with Puntos do
        begin
          Close;
          Parameters.ParamByName('@fecha').Value:= Int(dtp1.Date);
          Open;
        end;
        Libro.Cells [5,1] := Puntosvia.Value;
        Libro.Cells [5,2] := Puntossp.Value;
        Libro.Cells [5,3] := Puntostpte.Value;
        Libro.Cells [5,4] := Puntosso.Value;
        Libro.Cells [5,5] := 0;
        Libro.Cells [5,6] := Puntoscerrado.Value;
        Libro.Cells [5,7] := Puntosnotiene.Value;
        Libro.Cells [5,8] := Puntosnomat.Value;
        Libro.Cells [5,9] := Puntosnoestaba.Value;
        Excel.WorkBooks[1].WorkSheets[3].Name := 'ENTRADA CARROS';
        Libro := Excel.WorkBooks[1].WorkSheets['ENTRADA CARROS'];
        Libro.Cells [5,2] := DateToStr(dtp1.Date);
      with Rutas do
        begin
          Close;
          Parameters.ParamByName('@fecha').Value:= Int(dtp1.Date);
          Open;
        end;
        Rutas.First;
        while not (Rutas.Eof) do
        begin
          case Rutasorden.Value of
            1:Libro.Cells [5,3] := Rutascantidad.Value;
            2:Libro.Cells [6,3] := Rutascantidad.Value;
            3:Libro.Cells [7,3] := Rutascantidad.Value;
            4:Libro.Cells [8,3] := Rutascantidad.Value;
            5:Libro.Cells [9,3] := Rutascantidad.Value;
          end;
          Rutas.Next;
        end;
        Libro.SaveAs('D:\Partes Habana\' + nombre);
        ShowMessage(' El fichero ' + Nombre +  ' ha sido creado exitosamente');
        Excel.Quit;
      end;
end;
Esperando haberte ayudado en algo.

Saludos

Luis Garcia
Responder Con Cita