Posted on: 5/12/2014 9:54:30 AM | Views : 742

Private Sub BtnExportExcel_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles BtnExportExcel.Click 'Using save file dialog that allow you to chosse the file name. Dim objDlg As New SaveFileDialog objDlg.Filter = "Excel File|*.xls" objDlg.OverwritePrompt = False If objDlg.ShowDialog = DialogResult.OK Then Dim filepath As String = objDlg.FileName ExportToExcel(dt, filepath) End If End Sub Private Sub ExportToExcel(ByVal dtTemp As DataTable, ByVal filepath As String) Dim strFileName As String = filepath If System.IO.File.Exists(strFileName) Then If (MessageBox.Show("Do you want to replace from the existing file?", "Export to Excel", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) = System.Windows.Forms.DialogResult.Yes) Then System.IO.File.Delete(strFileName) Else Return End If
End If Di ...

Go to the complete details ...