Está en la página 1de 6

'/////////////////////////////////////////////////////////

'// Definimos dos variables para controlar fila y columna


'/////////////////////////////////////////////////////////
Dim fila As Integer = 1
Dim columna As Integer = 1
'/////////////////////////////////////////////////
'// Armamos la linea con los ttulos de columnas
'/////////////////////////////////////////////////
objHojaExcel.Range("A1").Select()
For Each dc In ds.Tables(0).Columns
objHojaExcel.Range(nombreColumna(columna) & 1).Value = dc.ColumnName
columna += 1
Next
fila += 1
Private Sub btnExportar_Click(ByVal sender As System.Object, ByVal e As System.
EventArgs) Handles btnExportar.Click
'/////////////////////////////
'// Creamos el Objeto Excel
'/////////////////////////////
Dim m_Excel
Dim objLibroExcel
Dim objHojaExcel
m_Excel = CreateObject("Excel.Application")
objLibroExcel = m_Excel.Workbooks.Add()
objHojaExcel = objLibroExcel.Worksheets(1)
objHojaExcel.Name = "Customers"
objHojaExcel.Visible = Excel.XlSheetVisibility.xlSheetVisible
objHojaExcel.Activate()
-----------------------Imports System.Data
Imports System.Data.SqlClient
Imports Microsoft.Office.Interop
Public Class Form1
Private ds As New DataSet
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.Even
tArgs) Handles MyBase.Load
'//////////////////////////////////////////////////
'// Creamos la conexin y llenamos el DataGridView
'//////////////////////////////////////////////////
Dim cnn As New SqlConnection("Data Source=localhost\sqlexpress;Initial C
atalog=Northwind; Integrated Security=True")
Dim da As New SqlDataAdapter("Select * from customers", cnn)
da.Fill(ds)
DataGridView1.DataSource = ds.Tables(0)
End Sub

Destination:=libro.ActiveSheet.Cells(2, 2), Sql:=" " & Consulta1 & " ")


Consulta1 = " select Moneda,Fecha,valorret as Valor,Agencia,n_ofici as Oficina,U
suario,Tipocarta,Numdoc"
Consulta1 = Consulta1 & " From xtrdetcarta"
Private Sub imprimeTicket()

Const TW As Integer = 567


Dim Y As Integer
Dim BeginPage, EndPage, NumCopies, i
CommonDialog1.CancelError = True
On Error GoTo ErrHandler
' CommonDialog1.ShowPrinter
BeginPage = CommonDialog1.FromPage
EndPage = CommonDialog1.ToPage
NumCopies = CommonDialog1.Copies
'-----------------------------------------------------------------------------'Prepara la frase del saludo final
HazFrase
'-----------------------------------------------------------------------------'-----------------------------------------------------------------------------' Cdigo para enviar los datos a la impresora
'-----------------------------------------------------------------------------Dim Suma As Double
For i = 1 To NumCopies 'Determina el nmero de copias a imprimir
Printer.Print ""
Y = Printer.CurrentY
Suma = 0
'---------------------------------------------------------------------------'Define el tipo de letra
'---------------------------------------------------------------------------Printer.Print ""
Y = Printer.CurrentY
Printer.FontName = "FontA2x1" 'Esta fuente es propia de la impresora Samnsung
'-------------------------------------------------------------------' Imprime el logo
'-------------------------------------------------------------------Picture1.Picture = LoadPicture(camino & "\logo.jpg")
Picture1.Top = 0
Picture1.Left = 0
Printer.CurrentX = 0.5 * TW
Printer.CurrentY = 0.3 * TW
Printer.PaintPicture Picture1.Picture, Printer.CurrentX, Printer.CurrentY
'---------------------------------------------------------------------' Imprime la cabecera del ticket
'---------------------------------------------------------------------Printer.CurrentY = 5.3 * TW
Printer.FontSize = 8
Printer.Print
Y = Printer.CurrentY
Printer.Print " Fecha"
Printer.CurrentY = Y
Printer.CurrentX = 7 * TW - Printer.TextWidth("Ticket N")
Printer.Print "Ticket N"
Y = Printer.CurrentY
Printer.CurrentX = 0.3 * TW
Printer.Print RS1!Fecha & Space(6) & Format(Now, "hh:mm")
Printer.CurrentY = Y
Printer.CurrentX = 7 * TW - Printer.TextWidth(RS1!idTicket)
Printer.Print RS1!idTicket
Printer.Print
Y = Printer.CurrentY

Printer.CurrentX = 0.3 * TW
Printer.Print "Le atendi " & nombreCamarero
Printer.FontBold = False
Printer.Print
'----------------------------------------------------------'Imprimir el cuerpo del ticket
'----------------------------------------------------------RS1.MoveFirst
While Not RS1.EOF
Y = Printer.CurrentY
Printer.CurrentX = 3.9 * TW - Printer.TextWidth(Left(RS1!Descripcion, 25))
Printer.Print Left(RS1!Descripcion, 25)
Printer.CurrentY = Y
If RS1!cantidad - Int(RS1!cantidad) <> 0 Then
Printer.CurrentX = 4.9 * TW - Printer.TextWidth(Format(RS1!cantidad, "##,##0.00"
))
Printer.Print Format(RS1!cantidad, "##,##0.0")
Else
Printer.CurrentX = 4.9 * TW - Printer.TextWidth(Format(RS1!cantidad, "##,##0.00"
))
Printer.Print Format(RS1!cantidad, "##,##0")
End If
Printer.CurrentY = Y
Printer.CurrentX = 5.5 * TW - Printer.TextWidth(Format(RS1!Precio, "##,##0.00"))
Printer.Print Format(RS1!Precio, "##,##0.00")
Printer.CurrentY = Y
Printer.CurrentX = 7 * TW - Printer.TextWidth(Format(RS1!total, "##,##0.00"))
Printer.Print Format(RS1!total, "##,##0.00")
Suma = Suma + RS1!total
RS1.MoveNext
Wend
'------------------------------------------------------------------'Imprime el pie del ticket
'------------------------------------------------------------------Printer.Print ""
Y = Printer.CurrentY
Printer.CurrentY = Y
Y = Printer.CurrentY
Printer.FontBold = True
Printer.FontSize = 10
Printer.CurrentX = 7 * TW - Printer.TextWidth("Total iva includo " & Format(Suma,
"##,##0.00"))
Printer.Print "Total iva includo " & Format(Suma, "##,##0.00")
Printer.FontBold = False
Printer.FontSize = 7
Printer.Print
Printer.CurrentX = (7 * TW - Printer.TextWidth(Saludo)) / 2
Printer.Print Saludo
Printer.Print ""
Printer.CurrentX = (7 * TW - Printer.TextWidth("Telfono +34 942.213.066")) / 2
Printer.Print "Telfono +34 942.213.066"
Printer.CurrentX = (7 * TW - Printer.TextWidth(" Fax +34 942.032.617")) / 2
Printer.Print " Fax +34 942.032.617"
Printer.CurrentX = (7 * TW - Printer.TextWidth("restaurante@mesongoya.com")) / 2
Printer.Print "restaurante@mesongoya.com"
Printer.CurrentX = (7 * TW - Printer.TextWidth("www.mesongoya.com")) / 2

Printer.Print "www.mesongoya.com"
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.Print ""
Printer.CurrentX = (7 * TW - Printer.TextWidth(".")) / 2
Printer.Print "."
Printer.EndDoc
Next i
Printer.EndDoc
CamareroNum = 0
lblSumaTicket.Caption = ""
ApagaTodo
Exit Sub
ErrHandler:
' El usuario ha hecho clic en el botn Cancelar
Exit Sub
End Sub
i = 1: j = 0
Do While Not rs.EOF
'Format(flex.TextMatrix(flex.Row, 2), "#,###,###,#0.00")
flex.TextMatrix(i, j) = rs!branc
flex.TextMatrix(i, j + 1) = rs!n_ofici
flex.TextMatrix(i, j + 2) = Format(rs!PAG_U + rs!PAG_C + rs!PAG_N +
rs!PAG_CH + rs!PAG_R + rs!PAG_M + rs!PAG_E, "#,###,###,#0.00")
'flex.TextMatrix(i, j + 3) = rs!INVPU + rs!INVPC + rs!INVPN + rs!INV
PCH + rs!INVPR + rs!INVPM + rs!INVPE
'flex.TextMatrix(i, j + 4) = Format$(rs!PAG_Up + rs!PAG_Cp + rs!PAG_
Np + rs!PAG_CHp + rs!PAG_Rp + rs!PAG_Mp + rs!PAG_Ep, "0.00")
'flex.TextMatrix(i, j + 5) = rs!INVPU + rs!INVPCp + rs!INVPNp + rs!I
NVPCHp + rs!INVPRp + rs!INVPMp + rs!INVPEp
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,

j
j
j
j
j
j
j
j
j
j
j
j
j
j

+
+
+
+
+
+
+
+
+
+
+
+
+
+

6) = Format$(rs!PAG_U, "0.00")
7) = rs!INVPU
8) = Format$(rs!PAG_C, "0.00")
9) = rs!INVPC
10) = Format$(rs!PAG_E, "0.00")
11) = rs!INVPE
12) = Format$(rs!PAG_N, "0.00")
13) = rs!INVPN
14) = Format$(rs!PAG_CH, "0.00")
15) = rs!INVPCH
16) = Format$(rs!PAG_R, "0.00")
17) = rs!INVPR
18) = Format$(rs!PAG_M, "0.00")
19) = rs!INVPM

'flex.TextMatrix(i, j + 20) = Format$(rs!PAG_Up, "0.00")

'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,
'flex.TextMatrix(i,

j
j
j
j
j
j
j
j
j
j
j
j
j

+
+
+
+
+
+
+
+
+
+
+
+
+

21)
22)
23)
24)
25)
26)
27)
28)
29)
30)
31)
32)
33)

=
=
=
=
=
=
=
=
=
=
=
=
=

rs!INVPUp
Format$(rs!PAG_Cp, "0.00")
rs!INVPCp
Format$(rs!PAG_Ep, "0.00")
rs!INVPEp
Format$(rs!PAG_Np, "0.00")
rs!INVPNp
Format$(rs!PAG_CHp, "0.00")
rs!INVPCHp
Format$(rs!PAG_Rp, "0.00")
rs!INVPRp
Format$(rs!PAG_Mp, "0.00")
rs!INVPMp

'Tpagado = Tpagado + rs!PAG_U + rs!PAG_C + rs!PAG_N + rs!PAG_CH + rs


!PAG_R + rs!PAG_M + rs!PAG_E
'Tinv = Tinv + rs!INVPU + rs!INVPC + rs!INVPN + rs!INVPCH + rs!INVPR
+ rs!INVPM + rs!INVPE
'TpagadoP = TpagadoP + rs!PAG_Up + rs!PAG_Cp + rs!PAG_Np + rs!PAG_CH
p + rs!PAG_Rp + rs!PAG_Mp + rs!PAG_Ep
'Tinvp = Tinvp + rs!INVPUp + rs!INVPCp + rs!INVPNp + rs!INVPCHp + rs
!INVPRp + rs!INVPMp + rs!INVPEp
'TPAG_U = TPAG_U + rs!PAG_U
'TINV_U = TINV_U + rs!INVPU
'TPAG_C = TPAG_C + rs!PAG_C
'TINV_C = TINV_C + rs!INVPC
'TPAG_N = TPAG_N + rs!PAG_N
'TINV_N = TINV_N + rs!INVPN
'TPAG_CH = TPAG_CH + rs!PAG_CH
'TINV_CH = TINV_CH + rs!INVPCH
'TPAG_R = TPAG_R + rs!PAG_R
'TINV_R = TINV_R + rs!INVPR
'TPAG_M = TPAG_M + rs!PAG_M
'TINV_M = TINV_M + rs!INVPM
'TPAG_E = TPAG_E + rs!PAG_E
'TINV_E = TINV_E + rs!INVPE
'TPAG_UP = TPAG_UP + rs!PAG_Up
'TINV_Up = TINV_Up + rs!INVPUp
'TPAG_CP = TPAG_CP + rs!PAG_Cp
'TINV_Cp = TINV_Cp + rs!INVPCp
'TPAG_NP = TPAG_NP + rs!PAG_Np
'TINV_Np = TINV_Np + rs!INVPNp
'TPAG_CHP = TPAG_CHP + rs!PAG_CHp
'TINV_CHp = TINV_CHp + rs!INVPCHp
'TPAG_RP = TPAG_RP + rs!PAG_Rp
'TINV_Rp = TINV_Rp + rs!INVPRp
'TPAG_MP = TPAG_MP + rs!PAG_Mp
'TINV_Mp = TINV_Mp + rs!INVPMp
'TPAG_EP = TPAG_EP + rs!PAG_Ep
'TINV_Ep = TINV_Ep + rs!INVPEp
i = i + 1
rs.MoveNext
Loop
rs.Close
flex.Rows = i
'End With

---------------Option Explicit
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Recibe la conexin ado y el recordset
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub Llenar_FlexGrid(cn As Connection, Rs As Recordset)
On Error GoTo ErrSub
Screen.MousePointer = vbHourglass
' Deshabilita el repintado del Flexgrid
MSFlexGrid1.Redraw = False
' Mueve el recordset al primer registro
Rs.MoveFirst

' Agrega las filas necesarias en el FlexGRid


MSFlexGrid1.Rows = Rs.RecordCount + 1
' Agrega las columnas necesarias
MSFlexGrid1.Cols = Rs.Fields.Count
Dim c As Integer
' recorre los campos del recordset
For c = 0 To Rs.Fields.Count - 1
' Agrega los encabezados de columna
MSFlexGrid1.TextMatrix(0, c) = Rs.Fields(c).Name
Next
' Selecciona
MSFlexGrid1.Row = 1
MSFlexGrid1.Col = 0

También podría gustarte