Private Sub btnPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrint.Click Dim strCashDepExcelfile As String = Nothing Dim xlApp As Excel.Application Dim xlWorkBook As Excel.Workbook Dim xlWorkSheet As Excel.Worksheet xlApp = New Excel.ApplicationClass Dim path As String = Application.StartupPath + "\xxx.xlsx" xlWorkBook = xlApp.Workbooks.Open(path) xlWorkSheet = CType(xlWorkBook.Worksheets(1), Excel.Worksheet) Try Dim cashData As DataClassesCashDepositDenominationsDO = CType(arrDenominationDetail(0), DataClasses.CashDepositDenominationsDO) xlWorkSheet.Cells(8, 2) = cashData.Note1000 xlWorkSheet.Cells(9, 2) = cashData.Note500 xlWorkSheet.Cells(10, 2) = cashData.Note100 xlWorkSheet.Cells(11, 2) = cashData.Note50 xlWorkSheet.Cells(12, 2) = cashData.Note20 xlWorkSheet.Cells(13, 2) = cashData.Note10 xlWorkSheet.Cells(14, 2) = cashData.Note5 xlWorkSheet.Cells(15, 2) = cashData.Note2 xlWorkSheet.Cells(16, 2) = cashData.Note1 xlWorkSheet.Cells(16, 2) = cashData.TotalCoinsAmt xlWorkSheet.Cells(18, 2) = cashData.TotalNotesAmt xlApp.ScreenUpdating = False xlApp.DisplayAlerts = False xlWorkSheet.PageSetup.Orientation = Excel.XlPageOrientation.xlLandscape xlWorkBook.SaveAs(Application.StartupPath + "\aaa.xlsx") Dim printSettings As System.Drawing.Printing.PrinterSettings = New System.Drawing.Printing.PrinterSettings() Dim oProcess As New System.Diagnostics.Process With oProcess.StartInfo .CreateNoWindow = True .WindowStyle = ProcessWindowStyle.Hidden .Verb = "print" .UseShellExecute = True .FileName = Application.StartupPath + "\aaa.xlsx" End With xlWorkBook.Close(SaveChanges:=True) oProcess.Start() oProcess.Dispose() xlApp.Quit() xlApp = Nothing MessageBox.Show("aaa printed successfully", "success") Catch ex As Exception ShowErrorMessage(ex) ExceptionManager.Publish(ex) Finally releaseObject(xlWorkSheet) releaseObject(xlWorkBook) releaseObject(xlApp) If System.IO.File.Exists(Application.StartupPath + "\aaa.xlsx") = True Then System.IO.File.Delete(Application.StartupPath + "\aaa.xlsx") End If End Try End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)