Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

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

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 07-12-2012
Avatar de Cristhor1982
Cristhor1982 Cristhor1982 is offline
Miembro
NULL
 
Registrado: dic 2012
Posts: 60
Poder: 12
Cristhor1982 Va por buen camino
Pegar de Clipboard a StringGrid

var
Vtextbuf:string;
Vnren:integer;
columna:integer;
begin
if Clipboard.HasFormat(CF_TEXT) then
begin
Vtextbuf:= Clipboard.AsText;
Vnren:=1;
stringgrid1.RowCount:=2;
columna:=strtoint(edit1.text);

while (pos(#13,Vtextbuf)>0)and(length(Vtextbuf)>2) do
begin
stringgrid1.Cells[Columna,Vnren]:=copy(Vtextbuf,1,pos(#13,Vtextbuf)-1);
delete(Vtextbuf,1,pos(#13#10,Vtextbuf)+1);

if (length(Vtextbuf)>2) then
begin
stringgrid1.RowCount:=stringgrid1.RowCount+1;
Vnren:=Vnren+1;
end;
// ShowMessage(Vtextbuf);
end;
bt_validar.Click;
end
else
ShowMessage('No hay texto en el PortaPapeles');

Este Codigo me entrega lo copiado pero no el ultimo valor que puede ser?
Responder Con Cita
  #2  
Antiguo 07-12-2012
Avatar de Casimiro Notevi
Casimiro Notevi Casimiro Notevi is offline
Moderador
 
Registrado: sep 2004
Ubicación: En algún lugar.
Posts: 32.037
Poder: 10
Casimiro Notevi Tiene un aura espectacularCasimiro Notevi Tiene un aura espectacular
Cita:
Empezado por Cristhor1982 Ver Mensaje
...
Bienvenido a clubdelphi, ¿ya leiste nuestra guía de estilo?, gracias por tu colaboración

Recuerda poner los tags al código fuente, ejemplo:



Gracias
Responder Con Cita
  #3  
Antiguo 07-12-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 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 Cristhor1982.

Si no interpreté mal la finalidad del código, yo haría:
Código Delphi [-]
...
var
  TS: TStrings;
begin
  if Clipboard.HasFormat(CF_TEXT) then
  begin
    TS := TStringList.Create;
    try
      TS.Text := clipboard.AsText;
      StringGrid1.RowCount := TS.Count;
      StringGrid1.Cols[StrToInt(Edit1.Text)]:= TS;
    finally
      TS.Free;
    end;
  end
  else
    ShowMessage('No hay texto en el PortaPapeles');
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #4  
Antiguo 08-12-2012
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Cristhor1982,

Revisa este código:
Código Delphi [-]
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Grids, ClipBrd;

type
  TForm1 = class(TForm)
    StringGrid1: TStringGrid;
    ClipBoard2StringGrid: TButton;
    StringGrid2Clipboard: TButton;
    txtRows: TEdit;
    Label1: TLabel;
    txtCols: TEdit;
    Label2: TLabel;
    procedure ClipBoard2StringGridClick(Sender: TObject);
    procedure StringGrid2ClipboardClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

// Divide una cadena de Texto por palabras
procedure Split(const Delimiter: Char; Input: string; const Strings: TStrings);
begin
   Strings.Clear;
   Strings.Delimiter := Delimiter;
   Strings.DelimitedText := Input;
end;

// Copia de Clipboard a StringGrid
procedure TForm1.ClipBoard2StringGridClick(Sender: TObject);
var
   StrList : TStringList;
   Row, Col, Data : Integer;

begin
   StrList := TStringList.Create;

   if Clipboard.HasFormat(CF_TEXT) then
   begin
      Split(' ',Clipboard.AsText,StrList);
      StringGrid1.FixedRows := 1;
      StringGrid1.FixedCols := 1;
      StringGrid1.RowCount := StrToIntDef(txtRows.Text,1)+1; // Por defecto una fila
      StringGrid1.ColCount := StrToIntDef(txtCols.Text,1)+1; // Por defecto una columna

      for Row:= 1 to StringGrid1.RowCount do
         StringGrid1.Rows[Row].Clear;

      for Col:= 1 to StringGrid1.ColCount do
         StringGrid1.Cols[Col].Clear;

      Data := 0;
      for Row:= 1 to StringGrid1.RowCount do
         for Col:= 1 to StringGrid1.ColCount-1 do
         begin
            if (Data <= StrList.Count-1) then
            begin
               StringGrid1.Cells[Col,Row] := StrList.Strings[Data];
               inc(Data);
            end
         end
   end;

   StrList.Free;
end;

// Copia de StringGrid a Clipboard
procedure TForm1.StringGrid2ClipboardClick(Sender: TObject);
var
   StringData : String;
   Row,Col : Integer;

begin
   Clipboard.Clear;

   StringData := '';

   for Row := 1 to StringGrid1.RowCount do
   begin
      for Col := 1 to StringGrid1.ColCount-1 do
      begin
         if (StringGrid1.cells[Col,Row] <> ' ') then
            StringData := StringData + StringGrid1.cells[Col,Row] + #9;
      end;
      StringData := StringData + #13 + #10;
   end;

   Clipboard.AsText := StringData;
end;

end.
El código anterior permite copiar por medio del Clipboard filas y columnas de data desde y hacia un control TStringGrid, es práctico para el intercambio de data con Excel.

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 08-12-2012 a las 03:22:55.
Responder Con Cita
  #5  
Antiguo 10-12-2012
Avatar de Cristhor1982
Cristhor1982 Cristhor1982 is offline
Miembro
NULL
 
Registrado: dic 2012
Posts: 60
Poder: 12
Cristhor1982 Va por buen camino
No logro pegar desde la Row 1 de la grilla, siempre comienza de la Row 0, me puedes ayudar, gracias
Responder Con Cita
  #6  
Antiguo 10-12-2012
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Cristhor1982,

El código que te indique anteriormente define de forma dinámica las filas y columnas del control TStringGrid y permite copiar desde y hacia el control por medio del Clipboard, quizás esta solución se pueda adaptar a tu proyecto.

Espero sea útil

Nelson.
Responder Con Cita
  #7  
Antiguo 10-12-2012
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 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
Cita:
Empezado por Cristhor1982 Ver Mensaje
No logro pegar desde la Row 1 de la grilla, siempre comienza de la Row 0, me puedes ayudar, gracias
Hola.

De este modo pegará los valores en la columna y a partir de la fila que indique la celda seleccionada actualmente:
Código Delphi [-]
var
  TS: TStrings;
  i : Integer;
begin
  if Clipboard.HasFormat(CF_TEXT) then
    with StringGrid1 do
    begin
      TS := TStringList.Create;
      try
        TS.Text := clipboard.AsText;
        RowCount := TS.Count;
        for i:= 0 to TS.Count-1 do
          Cells[Col, StringGrid1.Row+i]:= TS[i]; //(*)
      finally
        TS.Free;
      end;
  end
end;
Si deseas utilizar el edit para seleccionar la columna, reemplaza la línea (*) por:
Código Delphi [-]
   Cells[StrToInt(Edit1.Text),StringGrid1.Row+i]:= TS[i];

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #8  
Antiguo 11-12-2012
Avatar de Cristhor1982
Cristhor1982 Cristhor1982 is offline
Miembro
NULL
 
Registrado: dic 2012
Posts: 60
Poder: 12
Cristhor1982 Va por buen camino
Muchas gracias, me parece que voy a probar poniendole algun ciclo...
Responder Con Cita
  #9  
Antiguo 11-12-2012
Avatar de Cristhor1982
Cristhor1982 Cristhor1982 is offline
Miembro
NULL
 
Registrado: dic 2012
Posts: 60
Poder: 12
Cristhor1982 Va por buen camino
Ecfisa
Muchas Gracias...Resulto a la perfeccion
Responder Con Cita
  #10  
Antiguo 18-12-2012
Avatar de Cristhor1982
Cristhor1982 Cristhor1982 is offline
Miembro
NULL
 
Registrado: dic 2012
Posts: 60
Poder: 12
Cristhor1982 Va por buen camino
Código Delphi [-]
procedure TFR_EliminacionFolioMasivo.SG1KeyDown(Sender: TObject;
  var Key: Word; Shift: TShiftState);
var
  TS: TStrings;
  j,i : Integer;
begin
if ((ssCtrl in Shift) and (Key = 86)) or ((ssShift in Shift) and (Key = 45)) then
  if Clipboard.HasFormat(CF_TEXT) then
    with SG1 do
    begin
      TS := TStringList.Create;
      try
        TS.Text := clipboard.AsText;
        RowCount := TS.Count+1;
        for i:= 0 to TS.Count-1 do
        begin


          Cells[SG1.Col,SG1.Row+i]:= TS[i];   //desde row 1

          screen.Cursor := crsqlwait;
          fr_clave.SQL.Close;
              fr_clave.SQL.SQL.Clear;
              fr_clave.SQL.SQL.Add('EXEC_aCTeLIMINACIONfOLIOv2 1,0,');
              if ((Cells[1,1+i]<>'')AND ((Cells[2,1+i])<>'')) then
                begin
                 fr_clave.SQL.SQL.Add(''''+ Cells[1,1+i] +''',''' + Cells[2,1+i] +''',0,0,0,');
                 end
                 else
                 if ((Cells[1,1+i]<>'') AND (Cells[2,1+i]='')) then
                 begin
                 fr_clave.SQL.SQL.Add(''''+ Cells[1,1+i] +''',-1,0,0,0,')
                 end
                else
                fr_clave.SQL.SQL.Add('-1,''' + Cells[2,1+i] +''',0,0,0,');
                fr_clave.SQL.SQL.Add(''''+ fr_clave.TX_Rut.Text +''',0,0,0');
                fr_clave.SQL.Open;
                  if fr_clave.SQL.RecordCount <> 0 then
                  BEGIN

                 // SG1.RowCount :=SG1.RowCount+1;
                  SG1.Cells[1,i+1 ] := fr_clave.SQL['Folio'];
                  SG1.Cells[2,i+1 ] := fr_clave.SQL['Vale'];
                  SG1.Cells[3,i+1 ] := fr_clave.SQL['Periodo'];
                  SG1.Cells[4,i+1] := fr_clave.SQL['RutVisador'];
                  SG1.Cells[6,i+1 ] := fr_clave.SQL['RutVisado'];
                  SG1.Cells[8,i+1 ] := fr_clave.SQL['Motivo'];
                  SG1.Cells [5,i+1 ] := NombreTrabajador(SG1.Cells[4,i+1]);
                  SG1.Cells [7,i+1 ] := NombreTrabajador(SG1.Cells[6,i+1]);

          end;
          for j := 0 to 8 do
          begin
          SG1.Cells[j, SG1.RowCount] := '';
          end;
          end;
      finally
        screen.Cursor := crdefault;
        TS.Free;
        //clipboard.Clear;

    end;
end
  else
    ShowMessage('No hay texto en el PortaPapeles');
end;



Esto esta funcionando "Bien", pero necesito que los valores Vacios de lo que copio no los inserte, trate con un IF TS[i]='' then..etc
pero no puedo, alguien que me de una pista
Responder Con Cita
  #11  
Antiguo 18-12-2012
Avatar de nlsgarcia
[nlsgarcia] nlsgarcia is offline
Miembro Premium
 
Registrado: feb 2007
Ubicación: Caracas, Venezuela
Posts: 2.206
Poder: 21
nlsgarcia Tiene un aura espectacularnlsgarcia Tiene un aura espectacular
Cristhor1982,

Cita:
Empezado por Cristhor1982
Necesito que los valores Vacios de lo que copio no los inserte, trate con un IF TS[i]='' then..etc pero no puedo
La solución que te propuse en el Mensaje #4 tiene el siguiente código:
Código Delphi [-]
procedure Split(const Delimiter: Char; Input: string; const Strings: TStrings);
begin
   Strings.Clear;
   Strings.Delimiter := Delimiter;
   Strings.DelimitedText := Input;
end;
Luego, si hay texto en el Clipboard este es procesado:
Código Delphi [-]
 if Clipboard.HasFormat(CF_TEXT) then
   begin
      Split(' ',Clipboard.AsText,StrList);
   ...
De esta forma solo se copia al TStringList los valores diferentes de blanco del Clipboard, usando el carácter blanco como separador de data.

Adicionalmente:
Código Delphi [-]
IF TS[i]='' Then
No verifica si el valor es blanco, solo verifica si el valor es empty, contrariamente:
Código Delphi [-]
IF TS[i]=' ' Then
Si verifica si el valor es blanco.

Te sugiero probar ambas opciones e implementes la que mejor se adapte a tu proyecto.

Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 18-12-2012 a las 22:53:50.
Responder Con Cita
  #12  
Antiguo 21-12-2012
Avatar de Cristhor1982
Cristhor1982 Cristhor1982 is offline
Miembro
NULL
 
Registrado: dic 2012
Posts: 60
Poder: 12
Cristhor1982 Va por buen camino
Cita:
Empezado por nlsgarcia Ver Mensaje
Cristhor1982,


La solución que te propuse en el Mensaje #4 tiene el siguiente código:
Código Delphi [-]
procedure Split(const Delimiter: Char; Input: string; const Strings: TStrings);
begin
   Strings.Clear;
   Strings.Delimiter := Delimiter;
   Strings.DelimitedText := Input;
end;
Luego, si hay texto en el Clipboard este es procesado:
Código Delphi [-]
 if Clipboard.HasFormat(CF_TEXT) then
   begin
      Split(' ',Clipboard.AsText,StrList);
   ...
De esta forma solo se copia al TStringList los valores diferentes de blanco del Clipboard, usando el carácter blanco como separador de data.

Adicionalmente:
Código Delphi [-]
IF TS[i]='' Then
No verifica si el valor es blanco, solo verifica si el valor es empty, contrariamente:
Código Delphi [-]
IF TS[i]=' ' Then
Si verifica si el valor es blanco.

Te sugiero probar ambas opciones e implementes la que mejor se adapte a tu proyecto.

Espero sea útil

Nelson.
Al final lo solucione con una variable x que almacenaba y luego en un ciclo le preguntaba si era '' ...y funciono.. Gracias
Responder Con Cita
  #13  
Antiguo 23-05-2013
Avatar de Cristhor1982
Cristhor1982 Cristhor1982 is offline
Miembro
NULL
 
Registrado: dic 2012
Posts: 60
Poder: 12
Cristhor1982 Va por buen camino
Ayuda (2) - Clipboard hacia TStringGrid

Amigos, de nuevo con el problema para pegar desde clipboard a TStringGrid...

Ahora necesito pegar esto

Equipo 12345

Fecha/Hora 23-may-2013 11:49:11 CLT

Horometro 1111

Operador 12

Cancha 20

Insumo 6789

Cantidad 121

y quede de esta forma

Equipo Fecha/Hora Horometro Operador Cancha Insumo Cantidad
15503 23-may-2013 11:49:11 CLT 1515 363 32 50085645 121


POR FAVOR AYUDA...Llevo unos dias tratando y me pega en cualquier lado....


SAludos
Responder Con Cita
  #14  
Antiguo 23-05-2013
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Poder: 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 Cristhor1982.

Recuerda que: preguntas diferentes = hilos diferentes (Punto 8 de la guía de estilo).

Saludos y gracias por tu colaboración
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
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

Temas Similares
Tema Autor Foro Respuestas Último mensaje
Copiar/pegar desde el Clipboard a otra Aplicación broly7 Varios 4 07-03-2011 17:08:53
Pegar imagen desde el Portapapeles (Clipboard) gluglu Gráficos 8 20-10-2010 15:09:55
tabla a clipboard picap Varios 4 13-05-2010 08:23:07
Copiar Y Pegar texto en las celdas de un StringGrid rgstuamigo OOP 2 01-12-2008 13:55:51
Una clase al ClipBoard bustio OOP 2 07-07-2004 00:35:16


La franja horaria es GMT +2. Ahora son las 18:08:11.


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