• Lunes 20 de Mayo de 2024, 06:34

Autor Tema:  Problema Con Excel  (Leído 993 veces)

jodijo5

  • Miembro HIPER activo
  • ****
  • Mensajes: 518
  • Nacionalidad: pe
    • Ver Perfil
    • http://www.bluetecnologia.com
Problema Con Excel
« en: Jueves 15 de Septiembre de 2005, 17:28 »
0
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
  1.  
  2. Option Explicit
  3. Const n As Integer = 8
  4. Private i As Integer
  5. Private infoboleta As xrpt
  6. Private Sub Prtrpt()
  7. 'On Error Resume Next
  8. Set dbf = db.Execute("select enccomprobante.IdEncComprobante," & _
  9.                      "clientes.Nombres," & _
  10.                      "clientes.Paterno," & _
  11.                      "clientes.Materno," & _
  12.                      "enccomprobante.Fecha," & _
  13.                      "enccomprobante.Subtotal," & _
  14.                      "enccomprobante.IGV," & _
  15.                      "enccomprobante.Total," & _
  16.                      "enccomprobante.IdEmpleado " & _
  17.                      "from EncComprobante inner join clientes " & _
  18.                      "on enccomprobante.idcliente=clientes.idcliente ") ' & _
  19.                      '"where enccomprobante.fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "#")
  20. With infoboleta
  21.     Call .agregar("A" & (n + i) & ":G" & (n + i), "Listado de comprobantes")
  22.     i = i + 1
  23.     Call .agregar("A" & n + i, "Codigo", True)
  24.     Call .agregar("b" & n + 1, "Cliente", True)
  25.     Call .agregar("c" & n + i, "Fecha", True)
  26.     Call .agregar("d" & n + i, "Empleado", True)
  27.     Call .agregar("e" & n + 1, "Subtotal", True)
  28.     Call .agregar("f" & n + i, "Total", True)
  29.     i = i + 1
  30.     Do Until (dbf.EOF)
  31.     If (CDate(dbf(4)) < CDate(Text1(1)) And CDate(dbf(4)) > CDate(Text1(0))) Then
  32.         Call .agregar("a" & n + i, dbf(0), True) 'codigo
  33.         Call .agregar("b" & n + i, dbf(1) & " " & dbf(2) & " " & dbf(3), True) 'cliente
  34.         Call .agregar("c" & n + i, dbf(4), True) 'fecha
  35.         'Call .agregar("d" & n + i, empleado(dbf(8)), True) 'empleado
  36.         Call .agregar("e" & n + i, dbf(5), True) 'subtotal
  37.         Call .agregar("f" & n + i, dbf(6), True) 'igv
  38.         Call .agregar("g" & n + i, dbf(7), True) 'total
  39.         i = i + 1
  40.     End If
  41.         dbf.MoveNext
  42.     Loop
  43. End With
  44. End Sub
  45. Private Sub prtcf(ByVal x As String) 'imprimir frecuencia cliente
  46. On Error GoTo bug
  47. Set dbf = db.Execute("SELECT (IdCliente) AS clientes, COUNT(IdCliente) AS veces " & _
  48. "From EncComprobante  " & _
  49. "where fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "#" & _
  50. " GROUP BY IdCliente  " & _
  51. "ORDER BY min(IdCliente) " & x)
  52. i = i + 1
  53. If (x = "desc") Then
  54.     Call infoboleta.agregar("a" & n + i, "El cliente más frecuente es: " & cliente(dbf("clientes")) & " con " & dbf("veces") & " compras")
  55. Else
  56.     Call infoboleta.agregar("a" & n + i, "El cliente menos frecuente es: " & cliente(dbf("clientes")) & " con " & dbf("veces") & " compras")
  57. End If
  58. bug:
  59. End Sub
  60. Private Sub prtvd() 'impriomir ventas diarias
  61. Set dbf = db.Execute("SELECT Fecha, SUM(Total) AS Expr1 " & _
  62.                 "From EncComprobante " & _
  63.                 "where fecha between #" & CDate(Text1(0)) & "# and #" & CDate(Text1(1)) & "# " & _
  64.                 "GROUP BY Fecha  " & _
  65.                 "ORDER BY Fecha")
  66. i = i + 1
  67. With infoboleta
  68. Call .agregar("a" & n + i & ":g" & n + i, "Ventas Diarias")
  69. i = i + 1
  70. Call .agregar("a" & n + i, "fecha", True)
  71. Call .agregar("b" & n + i, "Total", True)
  72. i = i + 1
  73. Do Until dbf.EOF
  74.     Call .agregar("a" & n + i, dbf(0), True)
  75.     Call .agregar("b" & n + i, dbf(1), True)
  76.     i = i + 1
  77.     dbf.MoveNext
  78. Loop
  79. End With
  80. End Sub
  81. Private Sub prtpv(x As String)
  82. Set dbf = db.Execute("SELECT Idproducto, SUM(Cantidad) AS total " & _
  83.                     "From Kardex " & _
  84.                     "WHERE     (Motivo LIKE 'venta') " & _
  85.                     "GROUP BY Idproducto " & _
  86.                     "ORDER BY SUM(Cantidad)")
  87. If (x = "desc") Then
  88.     x = " más "
  89. Else
  90.     x = " menos "
  91. End If
  92. i = i + 1
  93.     Call infoboleta.agregar("a" & n + i, "El producto" & x & "vendido es: " & dbf(0) & " con una cantidad de: " & dbf(1) & " unidades")
  94. End Sub
  95. Private Sub prtkx()
  96. Set dbf = db.Execute("select * from kardex")
  97. Dim a As Integer
  98. With infoboleta
  99. i = i + 1
  100. .neg = True
  101. .agregar "a" & n + i & ":g" & n + i, "Kardex"
  102. .agregar "a" & n + i, "Producto", True
  103. .agregar "b" & n + i, "Cantidad", True
  104. .agregar "c" & n + i, "Motivo", True
  105. .agregar "d" & n + i, "Tipo de doc.", True
  106. .agregar "e" & n + i, "N° Documento", True
  107. .agregar "f" & n + i, "Fecha", True
  108. i = i + 1
  109. .neg = False
  110. Do Until dbf.EOF
  111.     .agregar "a" & n + i, dbf(1), True
  112.     .agregar "b" & n + i, dbf(2), True
  113.     .agregar "c" & n + i, dbf(3), True
  114.     .agregar "d" & n + i, dbf(4), True
  115.     .agregar "e" & n + i, dbf(5), True
  116.     .agregar "f" & n + i, dbf(6), True
  117.     dbf.MoveNext
  118. Loop
  119. End With
  120. End Sub
  121. Private Sub prtp(x As String)
  122. Set dbf = db.Execute("SELECT Productos.IdProveedor, COUNT(Productos.Idproducto) AS Expr1 " & _
  123.                     "FROM Productos INNER JOIN " & _
  124.                     "Proveedores ON Productos.IdProveedor = Proveedores.IdProveedor " & _
  125.                     "GROUP BY Productos.IdProveedor " & _
  126.                     "ORDER BY COUNT(Productos.Idproducto)" & n)
  127. If (x = "desc") Then
  128.     x = " mejor "
  129. Else:
  130.     x = " peor "
  131. End If
  132. i = i + 1
  133. infoboleta.agregar "a" & n + i, "el" & x & "proveedor es:"
  134. 'aqui falta completar la oraci{on
  135. End Sub
  136. Private Sub Command1_Click()
  137. 'Listado de comprobantes.YA
  138. 'Cliente más frecuente.YA
  139. 'Cliente menos frecuente.YA
  140. 'Ventas diarias.YA
  141. 'Producto mas vendido.YA
  142. 'Producto menos vendido.YA
  143. 'Kardex.YA
  144. 'Mejor proveedor.YA
  145. 'Peor proveedor.YA
  146. i = 0
  147. Set infoboleta = New xrpt
  148. infoboleta.nuevo_doc (App.Path + "\Reportes\general.xlt")
  149. infoboleta.mostrar_doc = True
  150. If (List1.Selected(0) = True) Then Call Prtrpt
  151. If (List1.Selected(1) = True) Then Call prtcf("desc")
  152. If (List1.Selected(2) = True) Then Call prtcf("asc")
  153. If (List1.Selected(3) = True) Then Call prtvd
  154. If (List1.Selected(4) = True) Then Call prtpv("desc")
  155. If (List1.Selected(5) = True) Then Call prtpv("asc")
  156. If (List1.Selected(6) = True) Then Call prtkx
  157. If (List1.Selected(7) = True) Then Call prtp("desc")
  158. If (List1.Selected(8) = True) Then Call prtp("asc")
  159. Unload Me
  160. End Sub
  161. Private Sub Command2_Click()
  162. Unload Me
  163. End Sub
  164. Private Function cliente(id As String) As String
  165. On Error Resume Next
  166. Dim cli As New ADODB.Recordset
  167. Set cli = db.Execute("select nombres,paterno,materno from clientes where idcliente='" & id & "'")
  168. cliente = cli(0) & " " & cli(1) & " " & cli(2)
  169. End Function
  170. Private Function empleado(id As String) As String
  171. On Error Resume Next
  172. Dim emp As New ADODB.Recordset
  173. Set emp = db.Execute("select nombres,paterno,materno from personal where idempleado='" & id & "'")
  174. empleado = emp
  175. End Function
  176. Private Sub Form_Load()
  177. Text1(0) = Date
  178. Text1(1) = Date
  179. i = 0
  180. End Sub
  181.  
  182.  
  183.  

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
El mensaje contiene 1 archivo adjunto. Debes ingresar o registrarte para poder verlo y descargarlo.
=============================
Daniel Pomalaza Mendoza
visita el Dinosaurio Azul :-D
http://bluetecnologia.com

jodijo5

  • Miembro HIPER activo
  • ****
  • Mensajes: 518
  • Nacionalidad: pe
    • Ver Perfil
    • http://www.bluetecnologia.com
Re: Problema Con Excel
« Respuesta #1 en: Viernes 16 de Septiembre de 2005, 00:07 »
0
amigos, lo acabo de solucionar, ahora si funciona, para los que lo desean, aqui esta la clase:
=============================
Daniel Pomalaza Mendoza
visita el Dinosaurio Azul :-D
http://bluetecnologia.com

jodijo5

  • Miembro HIPER activo
  • ****
  • Mensajes: 518
  • Nacionalidad: pe
    • Ver Perfil
    • http://www.bluetecnologia.com
Re: Problema Con Excel
« Respuesta #2 en: Viernes 16 de Septiembre de 2005, 00:08 »
0
amigos, lo acabo de solucionar, ahora si funciona, para los que lo desean, aqui esta la clase:
El mensaje contiene 1 archivo adjunto. Debes ingresar o registrarte para poder verlo y descargarlo.
=============================
Daniel Pomalaza Mendoza
visita el Dinosaurio Azul :-D
http://bluetecnologia.com