public void CreateDetailReport(ParentDetail summary, String FileName, out String msg) { msg = ""; Excel.Application xlApp; Excel.Workbook xlWorkBook; Excel.Worksheet xlWorkSheet; object misValue = System.Reflection.Missing.Value; xlApp = new Excel.Application(); xlWorkBook = xlApp.Workbooks.Add(misValue); xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.Add(misValue, misValue, misValue, misValue); xlWorkSheet.Name = CreateValidWorksheetName(summary.BuildName); int y = 1; xlWorkSheet.Cells[y, 1] = "TRUST CODE"; xlWorkSheet.Cells[y, 2] = "BUILDING NAME"; y++; xlWorkSheet.Cells[y, 1] = summary.TrustCode; xlWorkSheet.Cells[y, 2] = summary.BuildName; y += 2; xlWorkSheet.Cells[y, 1] = "DATE"; xlWorkSheet.Cells[y, 2] = "DESCRIPTION"; xlWorkSheet.Cells[y, 3] = "REFERENCE"; xlWorkSheet.Cells[y, 4] = "AMOUNT"; y++; foreach (Detail transaction in summary.Transactions) { xlWorkSheet.Cells[y, 1] = transaction.TrnDate.ToString("yyyy/MM/dd"); xlWorkSheet.Cells[y, 2] = transaction.Description; xlWorkSheet.Cells[y, 3] = transaction.Reference; xlWorkSheet.Cells[y, 4] = transaction.Amt.ToString(); y++; } releaseObject(xlWorkSheet, out msg); xlWorkBook.SaveAs(FileName, Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue); xlWorkBook.Close(true, misValue, misValue); xlApp.Quit(); releaseObject(xlWorkBook, out msg); releaseObject(xlApp, out msg); msg = (msg == "" ? "Excel Report Saved" : msg); }