Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Otros temas > Trucos
Registrarse FAQ Miembros Calendario Guía de estilo Buscar Temas de Hoy Marcar Foros Como Leídos

Los mejores trucos

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 08-06-2006
Avatar de Neftali [Germán.Estévez]
Neftali [Germán.Estévez] Neftali [Germán.Estévez] is offline
[becario]
 
Registrado: jul 2004
Ubicación: Barcelona - España
Posts: 18.220
Poder: 10
Neftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en brutoNeftali [Germán.Estévez] Es un diamante en bruto
Exportar un StringGrid a un fichero

Éste truco ha llegado por la necesidad de exportar el contenido de un StringGrid hacia un fichero con las columnas separadas por TABs.
Definimos una constante CHAR_SEP como separador; Modificando ésta constante podemos usar TAB, ; , Saltos de linea,...

El código:

Código Delphi [-]
const
   CHAR_SEP = ';';
   // CHAR_SEP = #9;
   // CHAR_SEP = '--';
   //... diferentes posibilidades
   //... different possibilities
 var
   i, j:Integer;
   Str:String;
   TS:TStrings;
 begin

   // Inicializamos
   // initialize
   Str := '';
   // Para cada línea de las selecciondas
   // for selected lines
   for i := (StringGrid1.Selection.Top) to (StringGrid1.Selection.Bottom) do
 begin
     // Si no es la 1ª linea, añadimos un salto de línea
     // if not is the first line tou must add a carry return
     if (i <> StringGrid1.Selection.Top) then begin
       Str := Str + #13#10;
     end;
     // Para cada elemento dentro de la línea (celdas)...
     // for the elements of the line...
     for j := 0 to (StringGrid1.Rows[i].Count - 1) do begin
       // Si no es la primera celda, añadimos un separador
       // if not is the first cell we add the separator
       if (j <> 0) then begin
         Str := Str + CHAR_SEP;
       end;
       // Construimos la cadena
       // construct the string
       Str := Str + StringGrid1.Rows[i].Strings[j];
     end;
     // La guardamos en el fichero (utilizando un TStrings, por ejemplo)
     // Save to the file (using TStrings by example)
     TS := TStringList.Create();
     TS.Add(Str);
     TS.SaveToFile('C:\aaa.txt');
     TS.Free;
Responder Con Cita
Respuesta


Herramientas Buscar en Tema
Buscar en Tema:

Búsqueda Avanzada
Desplegado

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 04:12:44.


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