Ver Mensaje Individual
  #4  
Antiguo 05-07-2006
zvf zvf is offline
Miembro
 
Registrado: abr 2006
Posts: 158
Reputación: 19
zvf Va por buen camino
HOLA!!!!
Estoy checando el truco que me sugeriste, solo que no entiendo algunas partes porque no esta comentado. Lo intento correr y me marca algunos errores como:
- coinitialize y alltrim no esta inicializado
- if pos('/', alltrim(cells[i, linea - 1])) <> 0 then begin //aqui marca que los tipos son incompatibles


Código Delphi [-]
procedure ExportaExcel(pStringGrid : TstringGrid; c0,r0,c1,r1 : Integer);
var ExLin, ExCol, i, Linea, AuxInteger : Integer;
    AuxFloat : Double;
    AuxFecha : tDatetime;
    c : TCursor;
    Excel, ExcelDoc, WS : Variant;
begin
  c             := Screen.Cursor;
  Screen.Cursor := crHourGlass;
  with pStringGrid do begin
    try
      coinitialize(nil);
      Excel         := CreateOleObject('Excel.Application');
      ExcelDoc      := Excel.Workbooks.Add;
      WS            := ExcelDoc.ActiveSheet;
      Excel.Visible := true;
      ExCol         := 0;
      for i := c0 to c1 do begin
        inc(ExCol);
        ws.Cells.Item[1, ExCol]:= cells[i, 0];
      end;
      for linea := r0 to r1 do begin
        inc(ExLin);
        ExCol := 0;
        for i := c0 to c1 do begin
          inc(ExCol);
          try
            try
              if pos('/', alltrim(cells[i, linea - 1])) <> 0 then begin
                AuxFecha := strtodatetime(alltrim(cells[i, linea - 1]));
                ws.Cells.Item[ExLin, ExCol] := AuxFecha;
              end
              else AuxFecha := strtodatetime('GENERA EXCEPCION');
            except
              try
                AuxInteger := strtoint(alltrim(cells[i,linea-1]));
                ws.Cells.Item[ExLin,ExCol]:= AuxInteger;
              except
                try
                  AuxFloat := strtofloat(alltrim(cells[i,linea-1]));
                  ws.Cells.Item[ExLin,ExCol]:= AuxFloat;
                except
                  ws.Cells.Item[ExLin,ExCol]:= cells[i,linea-1];
                end;
              end;
            end;
          except end;
        end;
      end;
      ws.cells.entirecolumn.autofit;
    finally
      screen.Cursor := c;
    end;
  end;
end;


Código Delphi [-]
procedure ExportaExcel (pStringGrid : TstringGrid; c0,r0,c1,r1 : Integer);

Código Delphi [-]
ExportaExcel(StringGrid1, 0, StringGrid1.ColCount-1, 0, StringGrid1.RowCount-1);

No se si lo este mandando llamar bien o me equivoque en algo. O si me falta agregar alguna unit.

GRACIAS POR SU AYUDA!!!!!!!!
Responder Con Cita