示例#1
0
        /// <summary>
        /// Generate Excel report from DataTable by using a provided
        /// Excel template file.
        /// </summary>
        /// <param name="dataTable">DataTable containing data for report</param>
        /// <param name="templateFile">Filename of Excel file to use as template</param>
        /// <param name="templateCellsRow">Excel row where template cells are defined for each column</param>
        /// <returns>MemoryStream containing Excel report</returns>
        public static MemoryStream GenerateReport(DataTable dataTable, string templateFile, int templateCellsRow, string sheetName)
        {
            MemoryStream ms = new MemoryStream();
            ms = Utility.LoadFile(templateFile);

            using (SpreadsheetDocument ssDoc = SpreadsheetDocument.Open(ms, true))
            {
                ExcelReportGenerator.OutputTemplatedData(dataTable, ssDoc, templateCellsRow, sheetName);
            }

            return ms;
        }
示例#2
0
        /// <summary>
        /// Generate Excel report from array of object arrays by using a provided
        /// Excel template file. Generated cells will use actual cells from the template
        /// file to provide styling to output report.
        /// </summary>
        /// <param name="inputData">Array of object arrays</param>
        /// <param name="templateFile">Filename of Excel file to use as template</param>
        /// <param name="templateCellsRow">Excel row where template cells are defined for each column</param>
        /// <returns>MemoryStream containing Excel report</returns>
        public static MemoryStream GenerateReport(object[][] inputData, string templateFile, int templateCellsRow)
        {
            MemoryStream ms = new MemoryStream();
            ms = Utility.LoadFile(templateFile);

            using (SpreadsheetDocument ssDoc = SpreadsheetDocument.Open(ms, true))
            {
                ExcelReportGenerator.OutputTemplatedData(inputData, ssDoc, templateCellsRow, "Sheet1");
            }

            return ms;
        }