private void AddReportLines(WorkbookPart workbookPart, WorksheetPart worksheetPart, Report report, uint startRow)
 {
     for (int iRow = 0; iRow < report.ReportLines.Count; iRow++)
     {
         for (int iCol = 0; iCol < report.ColumnNames.Count; iCol++)
         {
             WorkbookHelper.AddCellText(
                 workbookPart,
                 worksheetPart,
                 report[iRow][iCol].ToString(),
                 (uint)iCol + 1, (uint)iRow + startRow + 1);
         }
     }
 }
        public void GenerateReport(
            string workbookPath,
            string worksheetName,
            Report report,
            bool showColumns,
            bool createTable
        )
        {
            // Open the document for editing.
            using (SpreadsheetDocument spreadSheet = WorkbookHelper.OpenOrCreateWorkbook(workbookPath))
            {
                if (WorkbookHelper.IsWorksheetPresent(spreadSheet.WorkbookPart, worksheetName))
                {
                    WorkbookHelper.DeleteWorksheet(spreadSheet.WorkbookPart, worksheetName);
                }

                // Insert a new worksheet.
                WorksheetPart worksheetPart = WorkbookHelper.InsertWorksheet(spreadSheet.WorkbookPart, worksheetName);

                if (showColumns)
                {
                    AddReportColumns(spreadSheet.WorkbookPart, worksheetPart, report.ColumnNames);
                }

                AddReportLines(spreadSheet.WorkbookPart, worksheetPart, report, showColumns ? 1U : 0);

                if (createTable && report.ReportLines.Count > 0)
                {
                    WorkbookHelper.CreateTable(
                        spreadSheet.WorkbookPart,
                        worksheetPart,
                        report.ColumnNames.ToArray(),
                        1, 1,
                        report.ColumnNames.Count,
                        report.ReportLines.Count
                    );
                }

            }
        }