예제 #1
0
        /// <summary>
        /// Creates an Excel Workbook from a DataSet
        /// </summary>
        /// <param name="sqlResults">The DataSet to populate a workbook with. The TableName of each DataTable will be the header and Tab name of each sheet.</param>
        /// <param name="title">The Title of the workbook</param>
        /// <returns></returns>
        public static ExcelPackage CreateNewFile( DataSet sqlResults = null, string title = null )
        {
            var excel = new ExcelPackage();
            excel.Workbook.Properties.Title = title;
            excel.Workbook.Properties.Author = UserLoginService.GetCurrentUser()?.Person?.FullName ?? "Rock";

            // Create the worksheet(s)
            foreach ( DataTable data in sqlResults.Tables )
            {
                excel.AddWorksheet( data );
            }

            return excel;
        }