Quantcast
Channel: Ayuda con Excel y Mysql vb.net
Viewing all articles
Browse latest Browse all 2

Ayuda con Excel y Mysql vb.net

$
0
0

ALGO ASI TE PUEDE SERVIR ... esta hecho para SQL server ....para MySql ........solo cambias sql por MySql ejemplo SqlCommand     entonces MySqlCommand 

  Dim lector As SqlDataReader=Nothing
            Dim oExcel As Object
            Dim oBook As Object
            Dim oSheet As Object
            oExcel = CreateObject("Excel.Application")
            oBook = oExcel.Workbooks.Add
            oSheet = oBook.Worksheets(1)
            sql1 = "SELECT numero ,codigoarticulo,descripcionarticulo ,cantidadarticulo ,codigoequipo, unidadbase   FROM invrequisiciondetalle WHERE numero =@Numero and fecha>=@fechaIni and fecha<=@fechaFin ORDER BY id2 ASC"
            oSheet.Range("A" & f, "N" & f).Interior.Color = System.Drawing.ColorTranslator.ToOle(System.Drawing.Color.Gainsboro)
                            oSheet.Rows.Item(f).Font.Bold = 1
                            oSheet.Range("A" & f, "N" & f).HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlCenter
                              oSheet.Range("A" & f).Value = "Nº"
                            oSheet.Range("B" & f).Value = "CodigoArticulo"
                            oSheet.Range("C" & f).Value = "DescripcionArticulo"
                            oSheet.Range("D" & f).Value = "CantidadArticulo"
                            oSheet.Range("E" & f).Value = "CodigoEquipo"
                            oSheet.Range("F" & f).Value = "UnidadMedida"

                            f = f + 1

                            comando = New SqlCommand(sql1, conexion)
                            comando.Connection.Open()
                            comando.Parameters.Clear()
                            comando.Parameters.AddWithValue("@numero", Numero)
                            comando.Parameters.AddWithValue("@fechaIni", DateTimePicker1.Value.ToShorDateString())
                            comando.Parameters.AddWithValue("@fechaFin", DateTimePicker2.Value.ToShorDateString())
                            lector = comando.ExecuteReader()
                            t = 0
                            While (lector.Read())
                                t = t + 1
                                oSheet.Range("A" & f, "G" & f).HorizontalAlignment = Microsoft.Office.Interop.Excel.Constants.xlLeft
                                oSheet.Range("A" & f).Value = t.ToString()
                                oSheet.Range("B" & f).Value = lector("codigoarticulo").ToString().Trim()
                                oSheet.Range("C" & f).Value = lector("descripcionarticulo").ToString().Trim()
                                oSheet.Range("D" & f).NumberFormat = "#.##0,00"
                                oSheet.Range("D" & f).Value = lector("cantidadarticulo").ToString().Trim()
                                oSheet.Range("E" & f).Value = lector("codigoequipo").ToString().Trim()
                                oSheet.Range("F" & f).Value = lector("unidadbase").ToString().Trim()
                                f = f + 1
                            End While
                            lector.Close()
                            comando.Connection.Close()

                oExcel.ActiveWindow.Zoom = 75
                oExcel.Columns.AutoFit()
                oExcel.Rows.AutoFit()
                oExcel.Visible = True
                oExcel.UserControl = True






Viewing all articles
Browse latest Browse all 2

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>