Example #1
0
        public IActionResult ExcelBackupBase(dynamic excelData, string excelName, bool isDynamic = false, string savePath = "")
        {
            if (!Directory.Exists(savePath))
            {
                Directory.CreateDirectory(savePath);
            }

            if (Directory.Exists(savePath))
            {
                var    factory = ExcelEntityFactory.GetInstance();
                byte[] result  = null;
                if (!isDynamic)
                {
                    result = factory.CreateWriteToExcel().ExportListToExcel(excelData, null, true);
                }
                else
                {
                    var dtResult = DynamicHelper.ToDataTable(excelData);
                    result = factory.CreateWriteToExcel().ExportDataTableToExcel(dtResult, null, true);
                }
                string fileName = $"{excelName}-{DateTime.Now:yyyyMMddHHmmss}.xlsx";
                System.IO.File.WriteAllBytes($@"{savePath}\{fileName}", result);
            }
            return(new EmptyResult());
        }
Example #2
0
        public static FileContentResult ExcelExport(dynamic excelData, string excelName, List <string> heading, bool isShowSlNo, List <string> keySelectors, List <string> tails)
        {
            var factory = ExcelEntityFactory.GetInstance();

            byte[] result = null;
            // var listResult = DynamicHelper.ToDynamicList(DynamicHelper.ToDataTable(excelData));
            DataTable dtResult = DynamicHelper.ToDataTable(excelData);

            result = factory.CreateWriteToExcel().ExportListToExcel(dtResult, heading, isShowSlNo, keySelectors, tails);
            var returnResult =
                new FileContentResult(result, factory.CreateWriteToExcel().ExcelContentType)
            {
                FileDownloadName = $"{excelName}-{DateTime.Now:yyyyMMddHHmmss}.xlsx"
            };

            return(returnResult);
        }
Example #3
0
        /// <summary>
        /// Excel导出,暂时支持实体类和DataTable数据源
        /// </summary>
        /// <param name="excelData"></param>
        /// <param name="excelName"></param>
        /// <param name="isModel"></param>
        /// <returns></returns>
        public static FileContentResult ExcelExport(dynamic excelData, string excelName, bool isDynamic = false, bool isShowSlNo = true)
        {
            var factory = ExcelEntityFactory.GetInstance();

            byte[] result = null;
            if (!isDynamic)
            {
                result = factory.CreateWriteToExcel().ExportListToExcel(excelData, null, isShowSlNo);
            }
            else
            {
                var dtResult = DynamicHelper.ToDataTable(excelData);
                result = factory.CreateWriteToExcel().ExportDataTableToExcel(dtResult, null, isShowSlNo);
            }
            var returnResult =
                new FileContentResult(result, factory.CreateWriteToExcel().ExcelContentType)
            {
                FileDownloadName = $"{excelName}-{DateTime.Now:yyyyMMddHHmmss}.xlsx"
            };

            return(returnResult);
        }