Programación General > Visual Basic 6.0 e inferiores
Problema Con Excel
(1/1)
jodijo5:
hola amigos, hice una clase para poder tabajar con excel desde mi aplicacion, pero me da problemas, esta clase lo uso para generar reportes en excel, ya que no me gusta trabajar con datareports ni crystal reports, la nota es que tengo una funcion "agregar", que sirve para llenar una celda determinada;
aparte de la clase tengo una serie de fnciones que ahora se las paso:
--- Código: Text --- Option ExplicitConst n As Integer = 8Private i As IntegerPrivate infoboleta As xrptPrivate Sub Prtrpt()'On Error Resume NextSet dbf = db.Execute("select enccomprobante.IdEncComprobante," & _ "clientes.Nombres," & _ "clientes.Paterno," & _ "clientes.Materno," & _ "enccomprobante.Fecha," & _ "enccomprobante.Subtotal," & _ "enccomprobante.IGV," & _ "enccomprobante.Total," & _ "enccomprobante.IdEmpleado " & _ "from EncComprobante inner join clientes " & _ "on enccomprobante.idcliente=clientes.idcliente ") ' & _ '"where enccomprobante.fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "#")With infoboleta Call .agregar("A" & (n + i) & ":G" & (n + i), "Listado de comprobantes") i = i + 1 Call .agregar("A" & n + i, "Codigo", True) Call .agregar("b" & n + 1, "Cliente", True) Call .agregar("c" & n + i, "Fecha", True) Call .agregar("d" & n + i, "Empleado", True) Call .agregar("e" & n + 1, "Subtotal", True) Call .agregar("f" & n + i, "Total", True) i = i + 1 Do Until (dbf.EOF) If (CDate(dbf(4)) < CDate(Text1(1)) And CDate(dbf(4)) > CDate(Text1(0))) Then Call .agregar("a" & n + i, dbf(0), True) 'codigo Call .agregar("b" & n + i, dbf(1) & " " & dbf(2) & " " & dbf(3), True) 'cliente Call .agregar("c" & n + i, dbf(4), True) 'fecha 'Call .agregar("d" & n + i, empleado(dbf(8)), True) 'empleado Call .agregar("e" & n + i, dbf(5), True) 'subtotal Call .agregar("f" & n + i, dbf(6), True) 'igv Call .agregar("g" & n + i, dbf(7), True) 'total i = i + 1 End If dbf.MoveNext LoopEnd WithEnd SubPrivate Sub prtcf(ByVal x As String) 'imprimir frecuencia clienteOn Error GoTo bugSet dbf = db.Execute("SELECT (IdCliente) AS clientes, COUNT(IdCliente) AS veces " & _"From EncComprobante " & _"where fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "#" & _" GROUP BY IdCliente " & _"ORDER BY min(IdCliente) " & x)i = i + 1If (x = "desc") Then Call infoboleta.agregar("a" & n + i, "El cliente más frecuente es: " & cliente(dbf("clientes")) & " con " & dbf("veces") & " compras")Else Call infoboleta.agregar("a" & n + i, "El cliente menos frecuente es: " & cliente(dbf("clientes")) & " con " & dbf("veces") & " compras")End Ifbug:End SubPrivate Sub prtvd() 'impriomir ventas diariasSet dbf = db.Execute("SELECT Fecha, SUM(Total) AS Expr1 " & _ "From EncComprobante " & _ "where fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "# " & _ "GROUP BY Fecha " & _ "ORDER BY Fecha")i = i + 1With infoboletaCall .agregar("a" & n + i & ":g" & n + i, "Ventas Diarias")i = i + 1Call .agregar("a" & n + i, "fecha", True)Call .agregar("b" & n + i, "Total", True)i = i + 1Do Until dbf.EOF Call .agregar("a" & n + i, dbf(0), True) Call .agregar("b" & n + i, dbf(1), True) i = i + 1 dbf.MoveNextLoopEnd WithEnd SubPrivate Sub prtpv(x As String)Set dbf = db.Execute("SELECT Idproducto, SUM(Cantidad) AS total " & _ "From Kardex " & _ "WHERE (Motivo LIKE 'venta') " & _ "GROUP BY Idproducto " & _ "ORDER BY SUM(Cantidad)")If (x = "desc") Then x = " más "Else x = " menos "End Ifi = i + 1 Call infoboleta.agregar("a" & n + i, "El producto" & x & "vendido es: " & dbf(0) & " con una cantidad de: " & dbf(1) & " unidades")End SubPrivate Sub prtkx()Set dbf = db.Execute("select * from kardex")Dim a As IntegerWith infoboletai = i + 1.neg = True.agregar "a" & n + i & ":g" & n + i, "Kardex".agregar "a" & n + i, "Producto", True.agregar "b" & n + i, "Cantidad", True.agregar "c" & n + i, "Motivo", True.agregar "d" & n + i, "Tipo de doc.", True.agregar "e" & n + i, "N° Documento", True.agregar "f" & n + i, "Fecha", Truei = i + 1.neg = FalseDo Until dbf.EOF .agregar "a" & n + i, dbf(1), True .agregar "b" & n + i, dbf(2), True .agregar "c" & n + i, dbf(3), True .agregar "d" & n + i, dbf(4), True .agregar "e" & n + i, dbf(5), True .agregar "f" & n + i, dbf(6), True dbf.MoveNextLoopEnd WithEnd SubPrivate Sub prtp(x As String)Set dbf = db.Execute("SELECT Productos.IdProveedor, COUNT(Productos.Idproducto) AS Expr1 " & _ "FROM Productos INNER JOIN " & _ "Proveedores ON Productos.IdProveedor = Proveedores.IdProveedor " & _ "GROUP BY Productos.IdProveedor " & _ "ORDER BY COUNT(Productos.Idproducto)" & n)If (x = "desc") Then x = " mejor "Else: x = " peor "End Ifi = i + 1infoboleta.agregar "a" & n + i, "el" & x & "proveedor es:"'aqui falta completar la oraci{onEnd SubPrivate Sub Command1_Click()'Listado de comprobantes.YA'Cliente más frecuente.YA'Cliente menos frecuente.YA'Ventas diarias.YA'Producto mas vendido.YA'Producto menos vendido.YA'Kardex.YA'Mejor proveedor.YA'Peor proveedor.YAi = 0Set infoboleta = New xrptinfoboleta.nuevo_doc (App.Path + "\Reportes\general.xlt")infoboleta.mostrar_doc = TrueIf (List1.Selected(0) = True) Then Call PrtrptIf (List1.Selected(1) = True) Then Call prtcf("desc")If (List1.Selected(2) = True) Then Call prtcf("asc")If (List1.Selected(3) = True) Then Call prtvdIf (List1.Selected(4) = True) Then Call prtpv("desc")If (List1.Selected(5) = True) Then Call prtpv("asc")If (List1.Selected(6) = True) Then Call prtkxIf (List1.Selected(7) = True) Then Call prtp("desc")If (List1.Selected(8) = True) Then Call prtp("asc")Unload MeEnd SubPrivate Sub Command2_Click()Unload MeEnd SubPrivate Function cliente(id As String) As StringOn Error Resume NextDim cli As New ADODB.RecordsetSet cli = db.Execute("select nombres,paterno,materno from clientes where idcliente='" & id & "'")cliente = cli(0) & " " & cli(1) & " " & cli(2)End FunctionPrivate Function empleado(id As String) As StringOn Error Resume NextDim emp As New ADODB.RecordsetSet emp = db.Execute("select nombres,paterno,materno from personal where idempleado='" & id & "'")empleado = empEnd FunctionPrivate Sub Form_Load()Text1(0) = DateText1(1) = Datei = 0End Sub
que es para rellenar todos los requeimientos del reporte; cuando llamo solo a una funcion de estas no me da error, pero si llamo a mas de una dentro de la clase me da un error que dice "error con la variable global Range", pero mi sintaxis esta bien, ayudenme con esto lo mas antes posible por favor, es urgente
gracias de antemano
jodijo5:
amigos, lo acabo de solucionar, ahora si funciona, para los que lo desean, aqui esta la clase:
jodijo5:
amigos, lo acabo de solucionar, ahora si funciona, para los que lo desean, aqui esta la clase:
Navegación
Ir a la versión completa