1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133
|
Imports MySql.Data.MySqlClient
Imports System.Data.DataTable
Imports Microsoft.Office.Interop
Imports ExcelAutoFormat = Microsoft.Office.Interop.Excel.XlRangeAutoFormat
Public Class Form1
Dim iRowCnt As Integer = 0
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
If MsgBox("Voulez vous vraiment quitter l'application ?", vbYesNo, "Quitter") = vbYes Then
End
End If
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Exporter.Click
Dim i, j As Integer
Dim xlApp As Excel.Application
Dim xlWorkBook As Excel.Workbook
Dim xlWorkSheet As Excel.Worksheet
Dim misValue As Object = System.Reflection.Missing.Value
xlApp = New Excel.Application
xlWorkBook = xlApp.Workbooks.Add(misValue)
Dim xlAppToUpload As New Excel.Application
xlAppToUpload.Workbooks.Add()
Dim xlWorkSheetToUpload As Excel.Worksheet
xlAppToUpload.Visible = True
Dim con As New MySqlConnection("server=localhost; user id= root; password= ; database= user;")
con.Open()
Dim com As String = ""
com = "SELECT * FROM statistiques"
Dim dscmd As New MySqlDataAdapter(com, con)
Dim ds As New DataSet
dscmd.Fill(ds)
For i = 0 To ds.Tables(0).Rows.Count - 1
For j = 0 To ds.Tables(0).Columns.Count - 1
' xlWorkSheet.Cells(i + 1, j + 1) =
' ds.Tables(0).Rows(i).Item(j)
Next
Next
xlWorkBook.SaveAs("C:\Users\camo\Desktop\vbexcel.xlsx")
xlWorkBook.Close()
xlApp.Quit()
releaseObject(xlApp)
releaseObject(xlWorkBook)
releaseObject(xlWorkBook)
con.Close()
MsgBox("Fichier généré dans le répertoire C:\Users\camo\Desktop\vbexcel.xlsx")
Try
If xlWorkBook.HasRows Then
iRowCnt = 4 ' ROW AT WHICH PRINT WILL START.
With xlAppToUpload
' SHOW AN HEADER.
.Cells(1, 1).value = "Statistiques individuelles des opératrices"
.Cells(1, 1).FONT.NAME = "Calibri"
.Cells(1, 1).Font.Bold = True
.Cells(1, 1).Font.Size = 20
.Range("A1:H1").MergeCells = True ' MERGE CELLS OF THE HEADER.
' SHOW COLUMNS ON THE TOP.
.Cells(iRowCnt - 1, 1).value = "Login User"
.Cells(iRowCnt - 1, 2).value = "Operation"
.Cells(iRowCnt - 1, 3).value = "Nombre de documents"
.Cells(iRowCnt - 1, 4).value = "Temps de traitement"
.Cells(iRowCnt - 1, 5).value = "Moyene documents par heure"
.Cells(iRowCnt - 1, 6).value = "Moyenne seconde par document"
.Cells(iRowCnt - 1, 7).value = "Taux d'erreur (%)"
While xlWorkBook.Read
.Cells(iRowCnt, 1).value = xlWorkBook.Item("Login")
.Cells(iRowCnt, 2).value = xlWorkBook.Item("Operation")
.Cells(iRowCnt, 3).value = xlWorkBook.Item("Nbr_docs")
.Cells(iRowCnt, 4).value = xlWorkBook.Item("tps_traite")
.Cells(iRowCnt, 5).value = xlWorkBook.Item("moy_doc_hr")
.Cells(iRowCnt, 6).value = xlWorkBook.Item("moy_sec_doc")
.Cells(iRowCnt, 7).value = xlWorkBook.Item("taux_err")
iRowCnt = iRowCnt + 1
End While
End With
' FINALLY, FORMAT THE EXCEL SHEET USING EXCEL'S AUTOFORMAT FUNCTION.
xlAppToUpload.ActiveCell.Worksheet.Cells(4, 1).AutoFormat(ExcelAutoFormat.xlRangeAutoFormatList3)
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
xlAppToUpload = Nothing : xlWorkSheetToUpload = Nothing
End Try
Cursor.Current = Cursors.Default
End Sub
Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Visualiser.Click
Dim con As New MySqlConnection("server=localhost; user id= root; password= ; database= user;")
con.Open()
Dim com As String = ""
com = "select * from statistiques "
Dim adapter As New MySqlDataAdapter(com, con)
Dim aze As New DataTable()
adapter.Fill(aze)
DataGridView1.DataSource = aze
con.Close()
End Sub
Private Sub releaseObject(ByVal obj As Object)
Try
System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
obj = Nothing
Catch ex As Exception
obj = Nothing
End Try
End Sub
End Class |