Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   impresion directa? (https://www.clubdelphi.com/foros/showthread.php?t=47000)

voldemmor 15-08-2007 22:09:52

impresion directa?
 
hola gracias a todos por la ayuda que siempre me prestan.

Si pueden necesito ejemplo o algun linck para poder relizar impresiones directas desde un conjunto de datos consultados en una base de datos o desde un memo.

Mucha gracias a todos

jhonny 15-08-2007 22:47:57

En la ayuda de Delphi, hay un topico llamado TPrinter y en él hay un label que dice Using TPrinter, el cual te explica como usar sus metodos BeginDoc, EndDoc y como escribir por medio de su Canvas la impresión que necesitas, todo eso lo puedes adaptar a tu necesidad, ya sea para la del conjunto de datos o la del Memo.

Neftali [Germán.Estévez] 16-08-2007 10:08:34

Otra opción tal vez más directa sea que en lugar de usar un TMemo (como comentas) uses un TRichEdit (propiedad PlainText = True), en ese caso el comportamiento será muy similar al TMemo, con la diferencia de que un TRichEdit tiene el método Print, que te imprimirá el contenido del control.
En este caso no deberás hacer nada más que llamar al método Print.

voldemmor 21-08-2007 21:33:58

gracias
 
con sus respuestas me han aclarado el panorama.

muchas gracias por todo

luchifer 23-08-2007 01:05:32

Impresion Directa
 
Mejor que este procedimiento no pude encontrar
Pruebalo !!!

Colocas un objeto excel y listo

procedure TFlis_comprob.manda_xls;
var Rango:Excel2000.Range;
I, row:integer;
bookmark:tbookmarkstr;
begin
Excelapplication1.Visible[0]:=true;
Excelapplication1.Workbooks.Add(null,0);
Rango:=Excelapplication1.ActiveCell;
for i:=0 to Qcon_det.FieldCount-1 do
begin
rango.Value:=Qcon_det.Fields[i].DisplayLabel;
rango:=rango.Next;
end;
Qcon_det.DisableControls;
bookmark:=Qcon_det.Bookmark;
Qcon_det.First;
row:=2;
while not Qcon_det.Eof do
begin
rango:=Excelapplication1.Range['A'+Inttostr(row),'A'+inttostr(row)];
for i:=0 to Qcon_det.FieldCount-1 do
begin
rango.Value:=Qcon_det.Fields[i].AsString;
rango:=rango.Next;
end;
Qcon_det.Next;
inc(row);
end;
Qcon_det.EnableControls;
rango:=Excelapplication1.Range['a1','e'+inttostr(row-1)];
rango.AutoFormat(1,null,null,null,null,null,null);
end;


Y para que funciones yo hago!!
QCon_det.Close;
QCon_det.SQL.Clear;
QCon_det.SQL.Add(Consul2);
QCon_det.Open;
if wdatxls.Checked then manda_xls else QRmayor.Preview;

y funciona excelentemente

luchifer 23-08-2007 01:11:06

Impresion directa
 
Perdon me equivoquede rutina pra enviar a excel los datos del query. Aqui t va la rutina para impresion directa

procedure TFpto_pollo.imprime_fac(stdoc, stipo:shortstring;sndoc:integer);
Var MyPrinter: TextFile;
xcan, xdes, xval, xtot, xpag, xcam:shortstring;
xsum:real;
begin
AssignFILE(MyPrinter,'LPT1');
ReWrite(MyPrinter);
Write(MyPrinter, CHR(27) + CHR(64)); // Inicializar Impresora
//Write(MyPrinter, CHR(27)+CHR(67)+CHR(44)); // Fijar Tamaño en Lineas
Write(MyPrinter,CHR(27)+ CHR(103)); // Tipo de Letra Chicas
//Write(MyPrinter,CHR(27)+CHR(197)); // Negrita
//Write(MyPrinter,CHR(27)+CHR(179)+CHR(28)); // Espacio entre Lines
if stipo='FAC' then Writeln(MyPrinter,'MICROMARKET VIA RAPIDA') else Writeln(MyPrinter,'POLLOS ROSS');
if stipo='FAC' then Writeln(MyPrinter,'AV.ROQUE AGUILERA ESQ.RADIAL CASTILLA') else Writeln(MyPrinter,'AV.SANTOS DUMONT CASI 4TO ANILLO');
if stipo='FAC' then Writeln(MyPrinter,'NIT 2642735017 TELF.3513621') else Writeln(MyPrinter,'NO ES FACTURA TELF.3533417');
if stipo='FAC' then Writeln(MyPrinter,'FACTURA : '+wnrofac.text+' ALFAB.'+walfab.text);
if stipo='FAC' then Writeln(MyPrinter,'NR.ORDEN:'+wnorden.text+' FECHA:'+datetostr(now));
if wnomfac.Text<>'' then
Writeln(MyPrinter,'Senores : '+wnomfac.text)
else
Writeln(MyPrinter,'Senores : Clientes Varios');
//----------------------------
if wnit.Text<>'' then
Writeln(MyPrinter,'NIT : '+wnit.text)
else
Writeln(MyPrinter,'PARA SERVIRSE EN :'+tbl_gloprod.fieldbyname('refer').asstring);
//------------------------------
tbl_gloprod.Locate('tdoc;ndoc',VarArrayOf([stdoc,sndoc]),[loCaseinsensitive]); //loCaseInsensitive
Writeln(MyPrinter,'-------------------------------------');
Writeln(MyPrinter,' Cant. Producto Valor ');
Writeln(MyPrinter,'-------------------------------------');
xsum:=0;
tbl_movpro.Locate('tdoc;ndoc',VarArrayOf([stdoc,sndoc]),[loCaseinsensitive]); //loCaseInsensitive
while not tbl_movpro.Eof and (tbl_movpro.FieldByName('tdoc').AsString=stdoc) and (tbl_movpro.FieldByName('ndoc').AsInteger=sndoc) do
begin
xcan:=format('%6.2f',[tbl_movpro.fieldbyname('cant').asfloat]);
xdes:=copy(tbl_movpro.fieldbyname('descri').AsString,1,20);
xval:=format('%8.2f',[tbl_movpro.fieldbyname('valor_bs').asfloat]);
xsum:=xsum+tbl_movpro.fieldbyname('valor_bs').asfloat;
Writeln(MyPrinter,xcan+' '+xdes+' '+xval);
tbl_movpro.Next;
end;
Writeln(MyPrinter,'-------------------------------------');
xtot:=format('%8.2f',[xsum]);
xpag:=format('%8.2f',[strtofloat(wpagbs.text)]);
xcam:=format('%8.2f',[strtofloat(wcamb.text)]);
Writeln(MyPrinter,' Total Facturado : '+xtot);
Writeln(MyPrinter,' Total Pagado : '+xpag);
Writeln(MyPrinter,' Cambio : '+xcam);
Writeln(MyPrinter,'-------------------------------------');
if stipo='FAC' then Writeln(MyPrinter,'MICROMARKET VIA RAPIDA LE AGRADECE') else Writeln(MyPrinter,'POLLOS ROSS LE AGRADECE');
Writeln(MyPrinter,'POR SU PREFERENCIA '+stdoc+'-'+inttostr(sndoc));
Writeln(MyPrinter,'');
Writeln(MyPrinter,'');
Writeln(MyPrinter,'');
Writeln(MyPrinter,'');
Writeln(MyPrinter,'');
Writeln(MyPrinter,'');
Writeln(MyPrinter,'');
Writeln(MyPrinter,'');
Writeln(MyPrinter,'');
//Write(MyPrinter,#12); // Expulsar la Hoja
System.CloseFile(MyPrinter);
end;

Y funciona re bien

voldemmor 24-08-2007 01:47:33

ya gracias
 
No te preocupes por la equivocacion, voya ver tambien el procedimiento de envio a excel a ver como me va, aunque aun no lo he necesitado pero no se sabe cuando se requiera....


:D:D:D:D:D:D:D

:cool: gracia a todos

emimarz 05-09-2007 01:20:21

Cita:

Empezado por luchifer (Mensaje 225369)
Perdon me equivoquede rutina pra enviar a excel los datos del query. Aqui t va la rutina para impresion directa

procedure TFpto_pollo.imprime_fac(stdoc, stipo:shortstring;sndoc:integer);
Var MyPrinter: TextFile;
xcan, xdes, xval, xtot, xpag, xcam:shortstring;
xsum:real;
begin
AssignFILE(MyPrinter,'LPT1');
ReWrite(MyPrinter);
Write(MyPrinter, CHR(27) + CHR(64)); // Inicializar Impresora
//Write(MyPrinter, CHR(27)+CHR(67)+CHR(44)); // Fijar Tamaño en Lineas
Write(MyPrinter,CHR(27)+ CHR(103)); // Tipo de Letra Chicas
//Write(MyPrinter,CHR(27)+CHR(197)); // Negrita
//Write(MyPrinter,CHR(27)+CHR(179)+CHR(28)); // Espacio entre Lines
if stipo='FAC' then Writeln(MyPrinter,'MICROMARKET VIA RAPIDA') else Writeln(MyPrinter,'POLLOS ROSS');
if stipo='FAC' then Writeln(MyPrinter,'AV.ROQUE AGUILERA ESQ.RADIAL CASTILLA') else Writeln(MyPrinter,'AV.SANTOS DUMONT CASI 4TO ANILLO');
if stipo='FAC' then Writeln(MyPrinter,'NIT 2642735017 TELF.3513621') else Writeln(MyPrinter,'NO ES FACTURA TELF.3533417');
if stipo='FAC' then Writeln(MyPrinter,'FACTURA : '+wnrofac.text+' ALFAB.'+walfab.text);
if stipo='FAC' then Writeln(MyPrinter,'NR.ORDEN:'+wnorden.text+' FECHA:'+datetostr(now));
if wnomfac.Text<>'' then
Writeln(MyPrinter,'Senores : '+wnomfac.text)
else
Writeln(MyPrinter,'Senores : Clientes Varios');
//----------------------------
.............

Writeln(MyPrinter,'-------------------------------------');
xtot:=format('%8.2f',[xsum]);
xpag:=format('%8.2f',[strtofloat(wpagbs.text)]);
xcam:=format('%8.2f',[strtofloat(wcamb.text)]);
Writeln(MyPrinter,' Total Facturado : '+xtot);
Writeln(MyPrinter,' Total Pagado : '+xpag);
Writeln(MyPrinter,' Cambio : '+xcam);
Writeln(MyPrinter,'-------------------------------------');
if stipo='FAC' then Writeln(MyPrinter,'MICROMARKET VIA RAPIDA LE AGRADECE') else Writeln(MyPrinter,'POLLOS ROSS LE AGRADECE');
Writeln(MyPrinter,'POR SU PREFERENCIA '+stdoc+'-'+inttostr(sndoc));
.................
Writeln(MyPrinter,'');
//Write(MyPrinter,#12); // Expulsar la Hoja
System.CloseFile(MyPrinter);
end;

Y funciona re bien

esta fantastico este codigo

pero por esas casualidades para colocarlo en las cordenadas X e Y como se hace???

me dijeron que es con el modo grafico de la impresora pero no logro dar con la tecla

nelostanley 19-09-2008 16:09:35

hmmmmm
 
y si quisiera que el detalle te salga ordenado ...es decir
cant. Descripcion Precio
1 Producto1 12.00
2 Producto2 15.00

se puede ??, el codigo anterior funciona perfecto peor el ordden del detalle no es estetico.

Me quiero volver changos hasta en el mensaje me salio desordenado el reporte :)

egostar 19-09-2008 16:25:08

Cita:

Empezado por emimarz (Mensaje 228410)
esta fantastico este codigo

pero por esas casualidades para colocarlo en las cordenadas X e Y como se hace???

me dijeron que es con el modo grafico de la impresora pero no logro dar con la tecla

Para eso debes usar el Canvas de impresión de la unidad Printers, algo que ya no es usado tan frecuentemente, pero te saca de muchos aprietos.

Salud OS

luchifer 19-09-2008 17:36:49

Orden de los productos
 
si puedes hacerlo. basta que le des el orden en la base de datos.
por ejm. si estas usando SQL server, puedes crear un campo de correlatividad en base al cual te imprima el listado.

egostar 19-09-2008 17:50:07

Cita:

Empezado por nelostanley (Mensaje 315178)
y si quisiera que el detalle te salga ordenado ...es decir
cant. Descripcion Precio
1 Producto1 12.00
2 Producto2 15.00

se puede ??, el codigo anterior funciona perfecto peor el ordden del detalle no es estetico.

Me quiero volver changos hasta en el mensaje me salio desordenado el reporte :)

Lo que yo hago para que los datos se vean correctamente alineados es esto:

Código Delphi [-]
function TFSalida.RJ(cString:string;nRJustOffset:integer):integer;
begin
  Result := nRJustOffSet - Printer.canvas.TextWidth(cString);
end;

var
  Importe: string;

  printer.BeginDoc;
  with printer.canvas do begin
     Y := 100;
     TextOut(1600,Y,QConsumosFecha.AsString);
     TextOut(2100,Y,QConsumosDescripcion.AsString);
     Importe := Format('%10.2m',[QConsumosImporte.AsFloat]);
     X  := RJ(Importe,3100);
     TextOut(3100,Y,Importe);
  end;
  printer.EndDoc;

Salud OS


La franja horaria es GMT +2. Ahora son las 20:02:41.

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