Esempio n. 1
0
        public async Task <IActionResult> GetListNameProduct(string term)
        {
            var list = await _productConnectAPI.GetAllProduct();

            var listname = list.Select(x => x.Name).ToList();

            return(Json(new
            {
                status = true,
                data = listname
            }));
        }
Esempio n. 2
0
        public async Task <IActionResult> ExportExcel()
        {
            string sWebRootFolder = _hostingEnvironment.WebRootPath;
            string directory      = Path.Combine(sWebRootFolder, "export-files");

            if (!Directory.Exists(directory))
            {
                Directory.CreateDirectory(directory);
            }
            string   sFileName = $"Product_{DateTime.Now:yyyyMMddhhmmss}.xlsx";
            string   fileUrl   = $"{Request.Scheme}://{Request.Host}/export-files/{sFileName}";
            FileInfo file      = new FileInfo(Path.Combine(directory, sFileName));

            if (file.Exists)
            {
                file.Delete();
                file = new FileInfo(Path.Combine(sWebRootFolder, sFileName));
            }
            var listproduct = await _productConnectAPI.GetAllProduct();

            using (ExcelPackage package = new ExcelPackage(file))
            {
                // add a new worksheet to the empty workbook
                ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Products");
                worksheet.Cells["A1"].LoadFromCollection(listproduct, true, TableStyles.Light1);
                worksheet.Cells.AutoFitColumns();
                package.Save(); //Save the workbook.
            }
            var test = fileUrl;

            return(Json(new
            {
                status = true,
                data = test
            }));
        }