示例#1
0
        //[Produces("application/json")]
        //[ValidateAntiForgeryToken]
        public async Task <IActionResult> CreateFito(IFormFile qqfile)
        {
            if (qqfile == null)
            {
                return(Json(new { success = false, error = "error file null" }));
            }
            string error = null;

            if (qqfile.Length > 0)
            {
                var toskip = new List <string> {
                    "Centre", "Fitoplanctons", "PSMB"
                };
                try
                {
                    using (var stream = new StreamReader(qqfile.OpenReadStream(), Encoding.GetEncoding("Windows-1252"), true))
                    {
                        var html = stream.ReadToEnd();
                        using (var temp = new TableToExcel())
                        {
                            temp.Process(html, out ExcelPackage xlsx);
                            //var package = new ExcelPackage(xlsx);
                            error = await _import.Fito(xlsx, toskip).ConfigureAwait(false);
                        }
                    }
                }
                catch (FileNotFoundException ex)
                {
                    return(Json(new { success = false, error = ex.Message }));
                }
            }
            return(Json(new { success = string.IsNullOrWhiteSpace(error), error }));
        }