Ver Mensaje Individual
  #17  
Antiguo 11-11-2012
BioStudio BioStudio is offline
Miembro
NULL
 
Registrado: nov 2012
Posts: 15
Reputación: 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