private void builWorkBook(Xls.Workbook workBook, IEnumerable <ChartInfo> graphs) { Xls.Chart graphTemplate = workBook.Sheets[1]; Xls.Worksheet dataSheet = workBook.Sheets[2]; int chartsCounter = 1; int currentDataColumn = 1; try { foreach (var graph in graphs) { int dataColumnsWritten; graphTemplate.Copy(dataSheet); workBook.Sheets[workBook.Sheets.Count - 1].Name = string.Format(Strings.ExcelChartSheetName, chartsCounter++); buildXlsChart(workBook.Sheets[workBook.Sheets.Count - 1], dataSheet, graph, currentDataColumn, out dataColumnsWritten); currentDataColumn += dataColumnsWritten; } graphTemplate.Delete(); } finally { if (dataSheet != null) { Marshal.FinalReleaseComObject(dataSheet); } Marshal.FinalReleaseComObject(graphTemplate); } }