Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Impresión (https://www.clubdelphi.com/foros/forumdisplay.php?f=4)
-   -   impresiones de tickets con excel y delphi (https://www.clubdelphi.com/foros/showthread.php?t=75632)

jofebas 08-09-2011 21:28:27

impresiones de tickets con excel y delphi
 
Buenas tardes.


[left]Miren lo que quiero hacer es un poco fuera de lo común, he intentado hacer un pequeño programa tipo puto de venta para un proyecto escolar, después de realizar todos los movimientos de venta, cambio y eso, quiero mandar imprimir un ticket, como no tengo impresora de ticket para probar lo mando a una imp. Normal laser.
El ticket sale tal y como lo configuro en Delphi 2010 con el componente de TExcelAplication sin problemas, el problema está que cuando lo probé en una impresora de tickets la hoja no deja de salir, y he buscado por todos lados, no encuentro como hacer para que pare al final de la impresión corte automáticamente la hoja o se detenga, probé con 2 miniprint una que corta y otra que no, pero con las dos hace lo mismo


podrian ayudarme. :)

Gracias de antemano.

el codigo es este:

Código Delphi [-]
procedure TFreportes.imprime();
var
  Format: OleVariant;
  Hoja : _WorkSheet;
  i, j : integer;
  con: string;
begin
    with ZQexcel do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from tiket ');
      Open;
    end;
// Abrimos excel
  Excel.Connect;
// Creamos un nuevo libro con tres hojas (predeterminado)
  //Excel.DisplayAlerts := False;
   Excel.WorkBooks.Add(NULL,0);
  //Excel.Workbooks.Add(1);
// Apuntamos a la primera hoja y le cambiamos el nombre
  Hoja := Excel.Worksheets.Item[1] as _WorkSheet;
  Hoja.Name := 'REPORTE';
  // Títulos de los datos
  //Hoja.Cells.AutoFormat(10, 'arial', 'center', 1, NULL, NULL, NULL);
  with Hoja.range['A1','D8'] do
  begin
    Font.Size:=7;
    Font.FontStyle := 'Bold';
    HorizontalAlignment := xlCenter;
    VerticalAlignment := xlCenter;
    WrapText:= true;
  end;
  Hoja.Range['A1','D1'].MergeCells := true;
  Hoja.Range['A1','D1'].Value2 := Label15.Caption;
  Hoja.Range['A2','D2'].MergeCells := true;
  Hoja.Range['A2','D2'].Value2 := Label13.Caption;
  Hoja.Range['A3','D3'].MergeCells := true;
  Hoja.Range['A3','D3'].Value2 := Label14.Caption;
  Hoja.Range['A4','D4'].MergeCells := true;
  Hoja.Range['A4','D4'].Value2 := Label4.Caption;
  Hoja.Range['A5','D5'].MergeCells := true;
  Hoja.Range['A5','D5'].Value2 := Label16.Caption+': '+Label7.Caption;
  Hoja.Range['A6','D6'].MergeCells := true;
  Hoja.Range['A6','D6'].Value2 := 'ticket No.'+ Label12.Caption;
  Hoja.Range['A7','D7'].MergeCells := true;
  Hoja.Range['A7','D7'].Value2 := IntToStr(ZQexcel.RecordCount) +' Articulos';
  Hoja.Range['A8','A8'].Value2 := 'CANT';
  Hoja.Range['A8','A8'].ColumnWidth  := 4;
  Hoja.Range['B8','B8'].Value2 := 'DESCRIPCION';
  Hoja.Range['C8','C8'].Value2 := 'PRECIO';
  Hoja.Range['C8','C8'].ColumnWidth := 6;
  Hoja.Range['D8','D8'].Value2 := 'TOTAL';
  Hoja.Range['D8','D8'].ColumnWidth  := 6;
  with ZQExcel do
  begin
    i:=9;
    if not IsEmpty then
      begin
        while not Eof do
        begin
        Hoja.Range['A'+IntToStr(i),'A'+IntToStr(i)].Value2 := ZQExcel.FieldByName('cantidad').AsString;
        Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := ZQExcel.FieldByName('descripcion').AsString;
        Hoja.Range['C'+IntToStr(i),'C'+IntToStr(i)].Value2 := ZQExcel.FieldByName('precio').AsString;
        Hoja.Range['D'+IntToStr(i),'D'+IntToStr(i)].Value2 := ZQExcel.FieldByName('total').AsString;
        Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].HorizontalAlignment := xlLeft;
        Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].VerticalAlignment := xlCenter;
        Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].Font.Size:=7;
        Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].WrapText:= true;
        next;
        i:=i+1;
      end;
      Format := '$#,##0.00_)';
      i:=i+1;
      j:=i;

      Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := 'EFECTIVO';
      Hoja.Range['D'+IntToStr(i),'D'+IntToStr(i)].Value2 := Edit3.Text;
      i:=i+1;
      Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := 'CAMBIO';
      Hoja.Range['D'+IntToStr(i),'D'+IntToStr(i)].Value2 := Edit5.Text;
      i:=i+1;
      Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := 'TOTAL';
      Hoja.Range['D'+IntToStr(i),'D'+IntToStr(i)].Value2 := Edit4.Text;

      with Hoja.Range['B'+inttostr(j),'B'+inttostr(i)] do
      begin
        Font.Size:=7;
        HorizontalAlignment := xlLeft;
        VerticalAlignment := xlCenter;
        Font.FontStyle := 'Bold';
        WrapText:= true;
      end;

      with Hoja.Range['C'+inttostr(j),'D'+inttostr(i)] do
      begin
        Font.Size:=7;
        HorizontalAlignment := xlLeft;
        VerticalAlignment := xlCenter;
        EntireColumn.NumberFormat := Format;
        WrapText:= true;
      end;
      i:=i+2;
      Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := 'GRACIAS POR SU PREFERENCIA';
      Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].MergeCells := true;
    end;
  end;
  if not DirectoryExists('C:\SSM\Ticket\') then CreateDir('C:\SSM\Ticket\');
  Excel.ActiveWorkbook.SaveAs( ExtractFilePath( 'C:\SSM\Ticket\' ) + 'ticket No.'+ Label12.Caption +'.xlsx ',EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, xlNoChange, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0);
  //ShowMessage( 'ticket No.'+ Label12.Caption+' Guardado en C:\SSM\Ticket\');
  Excel.Visible[1]:=False;
//aqui imprimo
  Excel.Worksheets.PrintOut(null, null, 1, null, null, null, null, null, 0);
  Excel.Quit;
end;

oscarac 08-09-2011 21:33:48

no se ve el codigo...
aqui te muestro como hago yo la impresion de los tickets

Código Delphi [-]
 
procedure TfrmValesdeConsumo.ImprimirTicket;
var
  impresora:TextFile;
  vCadena : string;
begin
  AssignFile(Impresora, 'LPT1');
  rewrite(Impresora);
  Writeln(Impresora,'Nombre de Empresa');
  Writeln(Impresora,'R.U.C. : ');
  Writeln(Impresora,'');
  Writeln(Impresora,'Cajero : ' + dmComedor.g_NombreUsuario);
  Writeln(Impresora,'');
  Writeln(Impresora,'Codigo : ' + edtTrabajador.Text);
  Writeln(Impresora,'');
  Writeln(Impresora,lbltrabajador.caption);
  Writeln(Impresora,'');
  Writeln(Impresora,'Fecha :' + FormatDatetime('dd/mm/yyyy', dmComedor.g_fecha));
  Writeln(Impresora,'Doc.  :' + _DOC + '   ' + Izquierda(TimeToStr(GetTime),5)) ;
  Writeln(Impresora,'');
  CDSConsumo.First;
  while not CDSConsumo.Eof do
  Begin
    vCadena := IntToStr(CDSConsumoCantidad.Value) + ' ' +
               CDSConsumoCodigo.AsString + ' ' +
               CDSConsumoDescripcion.AsString + ' ' +
               FloatToStr(CDSConsumoTotal.Value);
    Writeln(Impresora, vCadena);
    CDSConsumo.Next;
  End;
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,#27+'m');
  CloseFile(impresora);
end;

jofebas 09-09-2011 15:39:39

este es el codigo
 
espero que ahora se vea.

gracias por tu respuesta, pero no encuentro como ligarlo a lo que estoy haciendo, como veras yo mando primero a excel y despues imprimo la hoja de excel, lo que imprimo lo saco de un query utilizo los Zeos delphi 2010 y TexcelAplication.


Código Delphi [-]
 
procedure TFpuntoventa.imprime();
var
  Format: OleVariant;
  Hoja : _WorkSheet;
  i, j : integer;
  con: string;
begin
    with ZQexcel do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from tiket ');
      Open;
    end;
// Abrimos excel
  Excel.Connect;
// Creamos un nuevo libro con tres hojas (predeterminado)
  //Excel.DisplayAlerts := False;
   Excel.WorkBooks.Add(NULL,0);
  //Excel.Workbooks.Add(1);
// Apuntamos a la primera hoja y le cambiamos el nombre
  Hoja := Excel.Worksheets.Item[1] as _WorkSheet;
  Hoja.Name := 'REPORTE';
  // Títulos de los datos
  //Hoja.Cells.AutoFormat(10, 'arial', 'center', 1, NULL, NULL, NULL);
  with Hoja.range['A1','D8'] do
  begin
    Font.Size:=7;
    Font.FontStyle := 'Bold';
    HorizontalAlignment := xlCenter;
    VerticalAlignment := xlCenter;
    WrapText:= true;
  end;
  Hoja.Range['A1','D1'].MergeCells := true;
  Hoja.Range['A1','D1'].Value2 := Label15.Caption;
  Hoja.Range['A2','D2'].MergeCells := true;
  Hoja.Range['A2','D2'].Value2 := Label13.Caption;
  Hoja.Range['A3','D3'].MergeCells := true;
  Hoja.Range['A3','D3'].Value2 := Label14.Caption;
  Hoja.Range['A4','D4'].MergeCells := true;
  Hoja.Range['A4','D4'].Value2 := Label4.Caption;
  Hoja.Range['A5','D5'].MergeCells := true;
  Hoja.Range['A5','D5'].Value2 := Label16.Caption+': '+Label7.Caption;
  Hoja.Range['A6','D6'].MergeCells := true;
  Hoja.Range['A6','D6'].Value2 := 'ticket No.'+ Label12.Caption;
  Hoja.Range['A7','D7'].MergeCells := true;
  Hoja.Range['A7','D7'].Value2 := IntToStr(ZQexcel.RecordCount) +' Articulos';
  Hoja.Range['A8','A8'].Value2 := 'CANT';
  Hoja.Range['A8','A8'].ColumnWidth  := 4;
  Hoja.Range['B8','B8'].Value2 := 'DESCRIPCION';
  Hoja.Range['C8','C8'].Value2 := 'PRECIO';
  Hoja.Range['C8','C8'].ColumnWidth := 6;
  Hoja.Range['D8','D8'].Value2 := 'TOTAL';
  Hoja.Range['D8','D8'].ColumnWidth  := 6;
  with ZQExcel do
  begin
    i:=9;
    if not IsEmpty then
      begin
        while not Eof do
        begin
        Hoja.Range['A'+IntToStr(i),'A'+IntToStr(i)].Value2 := ZQExcel.FieldByName('cantidad').AsString;
        Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := ZQExcel.FieldByName('descripcion').AsString;
        Hoja.Range['C'+IntToStr(i),'C'+IntToStr(i)].Value2 := ZQExcel.FieldByName('precio').AsString;
        Hoja.Range['D'+IntToStr(i),'D'+IntToStr(i)].Value2 := ZQExcel.FieldByName('total').AsString;
        Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].HorizontalAlignment := xlLeft;
        Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].VerticalAlignment := xlCenter;
        Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].Font.Size:=7;
        Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].WrapText:= true;
        next;
        i:=i+1;
      end;
      Format := '$#,##0.00_)';
      i:=i+1;
      j:=i;
      Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := 'EFECTIVO';
      Hoja.Range['D'+IntToStr(i),'D'+IntToStr(i)].Value2 := Edit3.Text;
      i:=i+1;
      Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := 'CAMBIO';
      Hoja.Range['D'+IntToStr(i),'D'+IntToStr(i)].Value2 := Edit5.Text;
      i:=i+1;
      Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := 'TOTAL';
      Hoja.Range['D'+IntToStr(i),'D'+IntToStr(i)].Value2 := Edit4.Text;
      with Hoja.Range['B'+inttostr(j),'B'+inttostr(i)] do
      begin
        Font.Size:=7;
        HorizontalAlignment := xlLeft;
        VerticalAlignment := xlCenter;
        Font.FontStyle := 'Bold';
        WrapText:= true;
      end;
      with Hoja.Range['C'+inttostr(j),'D'+inttostr(i)] do
      begin
        Font.Size:=7;
        HorizontalAlignment := xlLeft;
        VerticalAlignment := xlCenter;
        EntireColumn.NumberFormat := Format;
        WrapText:= true;
      end;
      i:=i+2;
      Hoja.Range['B'+IntToStr(i),'B'+IntToStr(i)].Value2 := 'GRACIAS POR SU PREFERENCIA';
      Hoja.Range['A'+inttostr(i),'D'+inttostr(i)].MergeCells := true;
    end;
  end;
  if not DirectoryExists('C:\SSM\Ticket\') then CreateDir('C:\SSM\Ticket\');
  Excel.ActiveWorkbook.SaveAs( ExtractFilePath( 'C:\SSM\Ticket\' ) + 'ticket No.'+ Label12.Caption +'.xlsx ',EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, xlNoChange, EmptyParam, EmptyParam, EmptyParam, EmptyParam, EmptyParam, 0);
  //ShowMessage( 'ticket No.'+ Label12.Caption+' Guardado en C:\SSM\Ticket\');
  Excel.Visible[1]:=False;
  Excel.Worksheets.PrintOut(null, null, 1, null, null, null, null, null, 0);
  Excel.Quit;
end;

oscarac 09-09-2011 15:43:15

pero dime
es necesario (obligatorio) que lo mandes al excel primero antes de imprimir?

pq si te das cuenta... el codigo que te pase saca de ClientDataset los datos a imprimir (tambien podria ser de una tabla o un query)

y lo manda directamente al puerto LPT1 para su impresion

jofebas 09-09-2011 15:50:27

Bueno, al principio lo hacía para darle un formato al ticket, después me sirvió para guardar un registro de los tickets que se estaban imprimiendo, pero no es obligatorio.

Solo que no sabía otra manera de como imprimir algo.

Lo voy a intentar con lo que me mandaste, pero si se pudiera hacer algo con mi código te lo agradecería.

oscarac 09-09-2011 16:00:11

pues elimina desde
Código Delphi [-]
 
// Abrimos excel
  Excel.Connect;
// Creamos un nuevo libro
hasta abajo y adecua el codigo que te di, lo pruebas y comentas

jofebas 09-09-2011 16:55:57

lo estoy acomodando luego te digo como quedo.

gracias.

oscarac 09-09-2011 17:01:08

incluso esta linea
Código Delphi [-]
 
Writeln(Impresora,#27+'m');
hace que se active las cuchillas de la ticketera y corte el papel:D

jofebas 09-09-2011 19:01:50

asi quedo al final,

muchas gracias. una ultima pregunta, si tengo un aimpresora en red y quiero mandarla ahi, pongo la ip de la imp. donde dice LPT1, o USB, ose solo cambio el nomre del puerto.

es posible.

y muchas gracias.

saludos


Código Delphi [-]
 
procedure TFpuntoventa.ImprimirTicket();
var
  impresora:TextFile;
  vCadena : string;
begin
   with ZQexcel do
    begin
      Close;
      SQL.Clear;
      SQL.Add('select * from tiket ');
      Open;
    end;
  AssignFile(Impresora, 'LPT1');
  rewrite(Impresora);
  Writeln(Impresora,''+Label15.Caption);
  Writeln(Impresora,''+Label13.Caption);
  Writeln(Impresora,''+Label14.Caption);
  Writeln(Impresora,'Cajero : ' + Label4.Caption);
  Writeln(Impresora,'');
  Writeln(Impresora,'ticket No.'+ Label12.Caption);
  Writeln(Impresora,'');
  Writeln(Impresora,'Fecha :' + Label16.Caption+': '+Label7.Caption);
  Writeln(Impresora,IntToStr(ZQexcel.RecordCount) +' Articulos') ;
  Writeln(Impresora,'');
  with ZQExcel do
  begin
    //i:=9;
    if not IsEmpty then
      begin
        while not Eof do
        begin
          vCadena := ZQExcel.FieldByName('cantidad').AsString + ' ' +
          ZQExcel.FieldByName('ns').AsString + ' ' +
          ZQExcel.FieldByName('descripcion').AsString + ' ' +
          ZQExcel.FieldByName('precio').AsString+ ' ' +
          ZQExcel.FieldByName('total').AsString;
          Writeln(Impresora, vCadena);
          next;
         // i:=i+1;
      end;
    end;
  end;
  Writeln(Impresora,'EFECTIVO: '+Edit3.Text);
  Writeln(Impresora,'');
  Writeln(Impresora,'CAMBIO: '+Edit5.Text);
  Writeln(Impresora,'');
  Writeln(Impresora,'TOTAL: '+Edit4.Text);
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,'');
  Writeln(Impresora,#27+'m');
  CloseFile(impresora);
end;


La franja horaria es GMT +2. Ahora son las 22:05:16.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi