コード例 #1
0
        public async Task <bool> Handle(RegisterFromExcelCommand message, CancellationToken cancellationToken)
        {
            _logger.LogInformation("----- Start require excel file");
            /*string path = _hostingEnvironment.MapPath("~/Resources/register_template.xlsx");*/

            /*string webRootPath = _hostingEnvironment.WebRootPath;
             * string path = "D:\\Tri_Viet\\src\\Services\\Identity\\Identity.API\\Resources\\register_template.xlsx";*/
            //Path.Combine(webRootPath + "/Identity.API/Resources/register_template.xlsx");

            /*FileInfo fileInfo = new FileInfo(path);
             *
             * ExcelPackage package = new ExcelPackage(fileInfo);
             * ExcelWorksheet worksheet = package.Workbook.Worksheets.FirstOrDefault();
             *
             * // get number of rows and columns in the sheet
             * if (worksheet != null)
             * {
             *  int rows = worksheet.Dimension.Rows; // 20
             *  int columns = worksheet.Dimension.Columns; // 7
             *
             * // loop through the worksheet rows and columns
             *  for (int i = 1; i <= rows; i++)
             *  {
             *      for (int j = 1; j <= columns; j++)
             *      {
             *          string content = worksheet.Cells[i, j].Value.ToString();
             *          /* Do something ...#1#
             *      }
             *  }
             * }*/

            _logger.LogInformation("--- Register UnSuccessfull");
            return(false);
        }
コード例 #2
0
        public async Task <ActionResult <bool> > RegisterFromExcelAsync([FromBody] RegisterFromExcelCommand command, IFormFile formFile)
        {
            /*if (formFile == null || formFile.Length <= 0)
             * {
             *  return false;
             * }
             *
             * if (!Path.GetExtension(formFile.FileName).Equals(".xlsx", StringComparison.OrdinalIgnoreCase))
             * {
             *  return false;
             * }
             *
             * var list = new List<RegisterFromExcel>();
             *
             * await using (var stream = new MemoryStream())
             * {
             *  await formFile.CopyToAsync(stream, cancellationToken);
             *
             *  using (var package = new ExcelPackage(stream))
             *  {
             *      ExcelWorksheet worksheet = package.Workbook.Worksheets[0];
             *      var rowCount = worksheet.Dimension.Rows;
             *
             *      for (int row = 2; row <= rowCount; row++)
             *      {
             *          list.Add(new RegisterFromExcel
             *          {
             *              STT = Convert.ToInt32(worksheet.Cells[row, 1].Value.ToString().Trim()),
             *              Age = int.Parse(worksheet.Cells[row, 2].Value.ToString().Trim()),
             *          });
             *      }
             *  }
             * }  */

            return(Ok(await _mediator.Send(command)));
        }