Imports System.IOImports System.Net.MailImports System.Runtime.InteropServices.MarshalImports System.DataPublic Class EntReportMailSender Dim WithEvents mvTimer As System.Timers.Timer
'********************************************************************* Protected Overrides Sub OnStart(ByVal args() As String) mvTimer = New System.Timers.Timer(10 * 1000) mvTimer.Enabled = True FfTestDatatableTableAdapter.Fill(EntDataSetxsd.ffTestDatatable) End Sub
'********************************************************************* Protected Overrides Sub OnStop() ' Add code here to perform any tear-down necessary to stop your service. End Sub
'*********************************************************************
Private Sub tmrRefresh_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) 'Handles tmrRefresh.Tick End Sub
Private Sub mvTimer_Elapsed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mvTimer.Elapsed
Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet1 As Excel.Worksheet Dim misValue As Object = System.Reflection.Missing.Value Dim i As Integer Dim j As Integer
xlApp = New Excel.ApplicationClass xlWorkBook = xlApp.Workbooks.Add(misValue) xlWorkSheet1 = xlWorkBook.Sheets("sheet1")
'xlWorkSheet1.Cells(1, 1) = DefectDataGridView.Item(0, 0).Value.ToString 'xlWorkSheet1.Cells(1, 1) = TestGrid.Columns(0).HeaderText 'xlWorkSheet1.Cells(1, 2) = TestGrid.Columns(1).HeaderText
For i = 0 To AdrLogDgw.RowCount - 2 For j = 0 To AdrLogDgw.ColumnCount - 1 xlWorkSheet1.Cells(i + 2, j + 1) = AdrLogDgw(j, i).Value.ToString() Next Next
xlWorkSheet1.Name = "Daily" xlWorkSheet1.SaveAs("C:\Report.xls") xlWorkBook.Close() xlApp.Quit() releaseObject(xlApp) releaseObject(xlWorkBook) releaseObject(xlWorkSheet1)
End Sub Private Sub releaseObject(ByVal obj As Object) Try System.Runtime.InteropServices.Marshal.ReleaseComObject(obj) obj = Nothing Catch ex As Exception obj = Nothing Finally GC.Collect() End Try End SubEnd Class
**** END OFF CODE *****************************
Thanks !