Club Delphi  
    FTP   CCD     Buscar   Trucos   Trabajo   Foros

Retroceder   Foros Club Delphi > Principal > Varios
Registrarse FAQ Miembros Calendario Guía de estilo Temas de Hoy

Grupo de Teaming del ClubDelphi

Respuesta
 
Herramientas Buscar en Tema Desplegado
  #1  
Antiguo 06-11-2012
BioStudio BioStudio is offline
Miembro
NULL
 
Registrado: nov 2012
Posts: 15
Poder: 0
BioStudio Va por buen camino
Gracias por toda la ayuda!

Use similar pero para agregar datos:

Código Delphi [-]
var
  Form3: TForm3;

implementation

uses umain;
{$R *.dfm}

procedure TForm3.Button1Click(Sender: TObject);
begin
// Agregar información a la Tabla.

with umain.Form1.ListView1.Items.Add do
    begin
      Caption := '2';            // Columna 0
      SubItems.Add( '1' );           // Columna 2
      SubItems.Add( 'MONITOR LG' );  // Columna 3
      SubItems.Add( '3' );           // Columna 4
      SubItems.Add( '230,45' );      // Columna 5
    end;
end;

end.
Responder Con Cita
  #2  
Antiguo 08-11-2012
BioStudio BioStudio is offline
Miembro
NULL
 
Registrado: nov 2012
Posts: 15
Poder: 0
BioStudio Va por buen camino
Si bien el codigo de ecfisa esta perfecto, el CSV se hace con ";" por ende simplemente modificamos:

Código Delphi [-]
Add(Form1.ListView1.Items[i].Caption +';'+ 
Form1.ListView1.Items[i].SubItems[0] +';'+ 
Form1.ListView1.Items[i].SubItems[1] +';'+ 
Form1.ListView1.Items[i].SubItems[2] +';'+ 
Form1.ListView1.Items[i].SubItems[3]);

Para 4 columnas.
Responder Con Cita
  #3  
Antiguo 08-11-2012
BioStudio BioStudio is offline
Miembro
NULL
 
Registrado: nov 2012
Posts: 15
Poder: 0
BioStudio Va por buen camino
Ahora por ejemplo le quise agregar el saveDialog pero no crea el archivo:

Código Delphi [-]
var
  i : Integer;
  saveDialog : TSaveDialog;    // Save dialog variable
begin
  saveDialog := TSaveDialog.Create(self);
  saveDialog.Title := 'Guarde su información';
  saveDialog.InitialDir := GetCurrentDir;
  saveDialog.Filter := 'CSV (Formato de texto separado por comas)|*.csv|';
  saveDialog.DefaultExt := 'csv';
  saveDialog.FilterIndex := 1;

  if saveDialog.Execute then //ShowMessage('Archivo : '+saveDialog1.FileName)
     saveDialog := TSaveDialog.Create(self);
      with TStringList.Create do
        try
          for i := 0 to umain.Form1.ListView1.Items.Count-1 do
            Add(Form1.ListView1.Items[i].Caption +';'+ 
            Form1.ListView1.Items[i].SubItems[0] +';'+ 
            Form1.ListView1.Items[i].SubItems[1] +';'+ 
            Form1.ListView1.Items[i].SubItems[2] +';'+ 
            Form1.ListView1.Items[i].SubItems[3]);
            ExtractFilePath(Application.ExeName);
          finally
          Free
      end
  else ShowMessage('Se ha cancelado el guardado del archivo.');
  saveDialog.Free;

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

end;
Responder Con Cita
  #4  
Antiguo 08-11-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 BioStudio.

Creo que te va a resultar mas simple de este modo:
Código Delphi [-]
....
var
  i : Integer;
begin
  ...
  with TStringList.Create do
  try
    for i := 0 to Form1.ListView1.Items.Count-1 do
      Add(Form1.ListView1.Items[i].Caption +','+
          Form1.ListView1.Items[i].SubItems.CommaText);
      Text := StringReplace(Text,',',';',[rfReplaceAll]);
    SaveToFile('archivo.txt')
  finally
    Free
  end
end;

Saludos.
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita
  #5  
Antiguo 08-11-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
BioStudio,

Cita:
Empezado por BioStudio Ver Mensaje
Ahora por ejemplo le quise agregar el saveDialog pero no crea el archivo
Esta sentencia esta respetida 2 veces en tu código:
Código Delphi [-]
   saveDialog := TSaveDialog.Create(self);
Esta es una combinación de tu código con el de ecfisa:
Código Delphi [-]
procedure TForm1.Button1Click(Sender: TObject);
var
  i : Integer;
  saveDialog : TSaveDialog;

begin

  saveDialog := TSaveDialog.Create(self);
  saveDialog.Title := 'Respaldo de Archivo en Formato CSV';
  saveDialog.InitialDir := GetCurrentDir;
  saveDialog.Filter := 'CSV (Formato de texto separado por comas)|*.csv';
  saveDialog.DefaultExt := 'csv';
  saveDialog.FilterIndex := 1;

  if saveDialog.Execute then
  begin
     with TStringList.Create do
     try
        for i := 0 to Form1.ListView1.Items.Count-1 do
           Add(Form1.ListView1.Items[i].Caption +',' +
               Form1.ListView1.Items[i].SubItems.CommaText);
           Text := StringReplace(Text,',',';',[rfReplaceAll]);
           try
              SaveToFile(SaveDialog.FileName);
           except
              ShowMessage('Error en la Generación del Archivo CSV');
           end;
     finally
        free;
     end;
  end;

  saveDialog.Free;

end;
Espero sea útil

Nelson.

Última edición por nlsgarcia fecha: 08-11-2012 a las 05:45:40.
Responder Con Cita
  #6  
Antiguo 09-11-2012
BioStudio BioStudio is offline
Miembro
NULL
 
Registrado: nov 2012
Posts: 15
Poder: 0
BioStudio Va por buen camino
Gracias nuevamente por tu ayuda nlsgarcia!

Para completar un poquito más dejo uno para TXT:

Código Delphi [-]
procedure TForm2.BitBtn1Click(Sender: TObject);

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

var
  i : Integer;
  saveDialog : TSaveDialog;

begin

  saveDialog := TSaveDialog.Create(self);
  saveDialog.Title := 'Respaldo de Archivo en Formato TXT';
  saveDialog.InitialDir := GetCurrentDir;
  saveDialog.Filter := 'Texto (delimitado por tabulaciones) (*.txt)|*.txt';
  saveDialog.DefaultExt := 'txt';
  saveDialog.FilterIndex := 1;

  if saveDialog.Execute then
  begin
     with TStringList.Create do
     try
        for i := 0 to umain.Form1.ListView1.Items.Count-1 do
           Add(umain.Form1.ListView1.Items[i].Caption +',' +
               umain.Form1.ListView1.Items[i].SubItems.CommaText);
           Text := StringReplace(Text,',',#9,[rfReplaceAll]);
           try
              SaveToFile(SaveDialog.FileName);
           except
              ShowMessage('Error en la Generación del Archivo TXT');
           end;
     finally
        free;
     end;
  end;

  saveDialog.Free;

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
end;

y uno para PRN:

Código Delphi [-]
procedure TForm2.Button1Click(Sender: TObject);
////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

var
  i : Integer;
  saveDialog : TSaveDialog;

begin

  saveDialog := TSaveDialog.Create(self);
  saveDialog.Title := 'Respaldo de Archivo en Formato PRN';
  saveDialog.InitialDir := GetCurrentDir;
  saveDialog.Filter := 'Texto con formato (delimitado por espacios) (*.prn)|*.prn';
  saveDialog.DefaultExt := 'prn';
  saveDialog.FilterIndex := 1;

  if saveDialog.Execute then
  begin
     with TStringList.Create do
     try
        for i := 0 to umain.Form1.ListView1.Items.Count-1 do
           Add(umain.Form1.ListView1.Items[i].Caption +',' +
               umain.Form1.ListView1.Items[i].SubItems.CommaText);
           Text := StringReplace(Text,',',#32,[rfReplaceAll]);
           try
              SaveToFile(SaveDialog.FileName);
           except
              ShowMessage('Error en la Generación del Archivo PRN');
           end;
     finally
        free;
     end;
  end;

  saveDialog.Free;

////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////

end;
Responder Con Cita
  #7  
Antiguo 11-11-2012
BioStudio BioStudio is offline
Miembro
NULL
 
Registrado: nov 2012
Posts: 15
Poder: 0
BioStudio Va por buen camino
Nueva cuestión, Exportar ListView a imagen BMP!

Sigo el post para no crear múltiples y que se pueda encontrar todo en uno. Resulta que nuevamente usando un ListView, encontré un CODE en la red para imprimirlo, en teoría no es imprimirlo con impresora sino que es tomarlo y guardarlo en un archivo de imagen *.BMP:

Código Delphi [-]
procedure TForm2.Button2Click(Sender: TObject);
var
  bmp: TBitmap;
begin
  bmp := TBitmap.Create;
  try
    bmp.Width := ListView1.Width;
    bmp.Height := ListView1.Height;
    bmp.Canvas.Lock;
    try
      ListView1.Perform(WM_PRINT, bmp.Canvas.Handle, PRF_CHILDREN or PRF_CLIENT or PRF_NONCLIENT);
    finally
      bmp.Canvas.UnLock;
      bmp.SaveToFile('C:\tree.bmp')
    end;
  finally
    bmp.Free
  end;
end;

Pero el problema esta en que al quererlo guardar por ejemplo si tenemos 1000 datos en un listview, seguramente se nos creara un Scroll (abajo/arriba), pero lo unico que hace es capturar tal cual es el tamaño del ListView y no imprime los 1000 datos que debe. Hay alguna manera de realizar esto???

Luego, también encontré un CODE muy bueno pero que le falta algo, es para exportar directamente un ListView a Microsoft Excel XXXX (en mi caso 2010), pero me lanza el siguiente errror:

i.minus.com/ibrVRjaEZAgSsn.png

El code es:

Código Delphi [-]
!**************************************
! Name: Listview contents to Excel
! Description:Exports data in a TListview to an Excel spreadsheet
! By: Brett Perry
!
! Returns:A formatted Excel spreadsheet
!
! Assumes:Converts data from TListview to Excel Spreadsheet
!
! Side Effects:Must have Excel installed on client machine but errors are trapped
!
!This code is copyrighted and has! limited warranties.Please see Planet-Source-Code .com/vb/scripts/ShowCode.asp?txtCodeId=768&lngWId=7!fordetails.!**************************************

procedure ListDataToExcel;
var
 {excel}
 Sheet,objExcel : Variant;
 Title : String;
 x,y: Integer;
 tmpDate : TDateTime; 
begin
 Screen.Cursor := crHourGlass;
 try
Title := 'Listview Data To Excel';
{create an instance of excel}
objExcel := CreateOleObject ('Excel.Application');
objExcel.Visible := True;
objExcel.Caption := 'Your CAPTION in Excel here';
{add the sheet}
objExcel.Workbooks.Add;
objExcel.Workbooks[1].Sheets.Add;
objExcel.Workbooks[1].WorkSheets[1].Name := Title;
Sheet := objExcel.Workbooks[1].WorkSheets[Title];
{create the columns}
for x := 0 to (lvList.Columns.Count -1) do
 Sheet.Cells[1, (x + 1)] := lvList.Columns.Items[x].Caption;
for y := 0 to (lvList.Items.Count -1) do
begin
      Sheet.Cells[(y + 3),1] := lvList.Items.Item[y].Caption;
  for x := 0 to (lvList.Columns.Count - 2) do
 begin
   try
  {check if output is date and add to excel in correct format}
  tmpDate := StrToDate(lvList.Items.Item[y].SubItems.Strings[x]);
 Sheet.Cells[(y + 3), (x + 2)] := tmpDate;
 objExcel.Selection.NumberFormat := 'dd/mm/yyyy';
 except on EConvertError do
 begin
   {if there was a conversion error then just add as normal i.e. string}
   Sheet.Cells[(y + 3), (x + 2)] := lvList.Items.Item[y].SubItems.Strings[x];
    end;
   end;
 end;
end;
{Select cells and format}
objExcel.Cells.select;
objExcel.Selection.Font.Name:='Arial';
objExcel.Selection.Font.Size:=9;
objExcel.selection.Columns.AutoFit;
except
begin
 Screen.Cursor := crDefault;
 MessageDlg('Excel transaction cancelled.',mtInformation, [mbOK],0);
 exit;
end;
 end;
 Screen.Cursor := crDefault; 
end;
Responder Con Cita
Respuesta



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
Problemas con DB + ListView mightydragonlor Varios 11 10-10-2008 16:23:30
Problemas con ListView ZayDun Varios 2 24-10-2007 22:14:56
Problemas al guardar HORA Sara Paz Varios 2 11-02-2007 12:36:09
problemas para guardar Guadalupe .NET 2 27-05-2006 01:58:45
Problemas con el TreeView y el ListView quake2420 Varios 5 11-08-2005 20:57:48


La franja horaria es GMT +2. Ahora son las 03:07:56.


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