Пример #1
0
        public IActionResult ExportAssignedTelephoneList()
        {
            var    results    = _iTelephoneRepository.GetAssignedTelephoneExportList();
            string fileName   = "AssignedTelephoneList.xlsx";
            string folderPath = Path.Combine(_hostingEnvironment.WebRootPath, "TempUploadTelePhone");
            string filePath   = Path.Combine(folderPath, fileName);

            if (!Directory.Exists(folderPath))
            {
                Directory.CreateDirectory(folderPath);
            }
            if (System.IO.File.Exists(filePath))
            {
                System.IO.File.Delete(filePath);
            }
            FileInfo file = new FileInfo(Path.Combine(folderPath, fileName));

            using (var package = new ExcelPackage(file))
            {
                var workSheet = package.Workbook.Worksheets.Add("AssignedTelephoneList");
                workSheet.Cells.LoadFromCollection(results, true);
                package.Save();
            }
            return(Ok());
        }