Ver Mensaje Individual
  #2  
Antiguo 02-04-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola LuisAlf.

Mirando el enlace pareciera que se trata de determinar el tipo de dato almacenado en cada celda (comprendida en un rango) del TStringGrid para pasarlo al tipo correspondiente a la planilla de Excel.

No utilizo Excel por lo que no tengo forma de probarlo, pero yo haría las comprobaciones de este modo:
Código Delphi [-]
var
  DTimeAux: TDateTime;
  IntAux: Integer;
  FloatAux: Extended;
  ...
begin
  ... 
  if TryStrToDateTime(StringGrid1.Cells[i, linea-1], DTimeAux) then 
    ws.Cells.Item[ExLin, ExCol]:= DTimeAux
  else if TryStrToInt(StringGrid1.Cells[i, linea-1], IntAux) then
    ws.Cells.Item[ExLin, ExCol] := IntAux
  else if TryStrToFloat(StringGrid1.Cells[i, linea-1],FloatAux) then
    ws.Cells.Item[ExLin, ExCol]:= FloatAux
  else
    ws.Cells.Item[ExLin, ExCol]:= Cells[i,ARow];
  ...
Me parece un modo más natural que el tratamiento mediante try/except.



Una forma mas reducida (no sé si funcione, tendrías que probar) , sería:
Código Delphi [-]
  ...
  if not TryStrToDateTime(StringGrid1.Cells[i, linea-1], ws.Cells.Item[ExLin, ExCol]) then
  else if not TryStrToInt(StringGrid1.Cells[i, linea-1], ws.Cells.Item[ExLin, ExCol]) then
  else if not TryStrToFloat(StringGrid1.Cells[i, linea-1], ws.Cells.Item[ExLin, ExCol]) then
  else
    ws.Cells.Item[ExLin, ExCol]:= Cells[i,ARow];
  ...

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita