Imports Microsoft.Office.Interop Public Class Service1 Protected Overrides Sub OnStart(ByVal args() As String) ' Ajoutez ici le code pour démarrer votre service. Cette méthode doit ' démarrer votre service. Me.Timer1.Start() End Sub Protected Overrides Sub OnStop() ' Ajoutez ici le code pour effectuer les destructions nécessaires à l'arrêt de votre service. Me.Timer1.Stop() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If Weekday(Today) 6 And Format(Now, "HH:mm") "22:00" Then CreerListe() End Sub Sub CreerListe() ' Déclaration des variables Dim ExcelApp As New Excel.Application Dim Ligne As Long Dim NomFeuille As String ExcelApp.Workbooks.Add() ExcelApp.ActiveWorkbook.Worksheets(1).Select() Me.OccasionsBindingSource.Filter = "Vendu=true" ' Créer les titres du WorkSheet ExcelApp.ActiveWorkbook.Worksheets(1).Range("A1").Value = String.Format("N°") ExcelApp.ActiveWorkbook.Worksheets(1).Range("B1").Value = String.Format("Marque") ExcelApp.ActiveWorkbook.Worksheets(1).Range("C1").Value = String.Format("Modèle") ExcelApp.ActiveWorkbook.Worksheets(1).Range("D1").Value = String.Format("Version") ExcelApp.ActiveWorkbook.Worksheets(1).Range("E1").Value = String.Format("Couleur") ExcelApp.ActiveWorkbook.Worksheets(1).Range("F1").Value = String.Format("Cylindrée") ExcelApp.ActiveWorkbook.Worksheets(1).Range("G1").Value = String.Format("Valeur") ExcelApp.ActiveWorkbook.Worksheets(1).Range("H1").Value = String.Format("Date d'Entrée") ExcelApp.ActiveWorkbook.Worksheets(1).Range("I1").Value = String.Format("Date de Vente") ' Remplir la WorkSheet For Ligne = 0 To Me.OccasionsBindingSource.Count - 1 ExcelApp.ActiveWorkbook.Worksheets(1).Range("A" & Ligne + 2).Value = Ligne + 1 ExcelApp.ActiveWorkbook.Worksheets(1).Range("B" & Ligne + 2).Value = String.Format(Me.DataGridView1.Rows(Ligne).Cells(1).Value) ExcelApp.ActiveWorkbook.Worksheets(1).Range("C" & Ligne + 2).Value = String.Format(Me.DataGridView1.Rows(Ligne).Cells(2).Value) ExcelApp.ActiveWorkbook.Worksheets(1).Range("D" & Ligne + 2).Value = String.Format(Me.DataGridView1.Rows(Ligne).Cells(3).Value) ExcelApp.ActiveWorkbook.Worksheets(1).Range("E" & Ligne + 2).Value = String.Format(Me.DataGridView1.Rows(Ligne).Cells(4).Value) ExcelApp.ActiveWorkbook.Worksheets(1).Range("F" & Ligne + 2).Value = Me.DataGridView1.Rows(Ligne).Cells(8).Value ExcelApp.ActiveWorkbook.Worksheets(1).Range("G" & Ligne + 2).Value = Me.DataGridView1.Rows(Ligne).Cells(15).Value ExcelApp.ActiveWorkbook.Worksheets(1).Range("H" & Ligne + 2).Value = Me.DataGridView1.Rows(Ligne).Cells(18).Value ExcelApp.ActiveWorkbook.Worksheets(1).Range("I" & Ligne + 2).Value = Me.DataGridView1.Rows(Ligne).Cells(19).Value Next ExcelApp.ActiveWorkbook.Worksheets(1).Range("A1:I1").select() With ExcelApp.Selection .VerticalAlignment = Excel.XlVAlign.xlVAlignCenter .Font.Bold = True .font.italic = False .Font.ColorIndex = 5 .Interior.ColorIndex = 48 .WrapText = True End With ExcelApp.Columns.AutoFit() ExcelApp.ActiveWorkbook.Worksheets(1).Range("A2").Activate() ExcelApp.ActiveWindow.FreezePanes = True NomFeuille = ("D:\Listes\Liste occasions au " & Format(Today, "d MMMM yyyy") & ".xls") ExcelApp.ActiveWorkbook.SaveAs(NomFeuille) ExcelApp.Quit() End Sub End Class