国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

.NET CORE Api 上傳excel解析并生成錯誤excel下載

這篇具有很好參考價值的文章主要介紹了.NET CORE Api 上傳excel解析并生成錯誤excel下載。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

寫在前面的話:

? ? ? ??【對外承接app API開發(fā)、網(wǎng)站建設(shè)、系統(tǒng)開發(fā),有償提供幫助,聯(lián)系方式于文章最下方?】

因業(yè)務(wù)調(diào)整,不再需要生成錯誤無excel下載,所以先保存代碼,回頭再重新編輯

#region Excel校驗部分
            if (files == null) throw Oops.Oh("文件不存在");
            string path = @"upload\{yyyy}\{MM}\{dd}";
            var reg = new Regex(@"(\{.+?})");
            var match = reg.Matches(path);
            match.ToList().ForEach(a =>
            {
                var str = DateTime.Now.ToString(a.ToString().Substring(1, a.Length - 2)); // 每天一個目錄
                path = path.Replace(a.ToString(), str);
            });


            var sizeKb = (long)(files.Length / 1024.0); // 大小KB
            if (sizeKb > 1048576)
                throw Oops.Oh("文件超過允許大小");

            // 后綴
            var suffix = Path.GetExtension(files.FileName).ToLower();
            if (string.IsNullOrWhiteSpace(suffix))
            {
                var contentTypeProvider = FS.GetFileExtensionContentTypeProvider();
                suffix = contentTypeProvider.Mappings.FirstOrDefault(u => u.Value == files.ContentType).Key;
            }

            if (string.IsNullOrWhiteSpace(suffix))
                throw Oops.Oh("文件后綴錯誤");

            var finalName = Guid.NewGuid() + suffix;

            //組合路徑并創(chuàng)建文件夾
            var filePath = Path.Combine(App.WebHostEnvironment.ContentRootPath, path);
            if (!Directory.Exists(filePath))
                Directory.CreateDirectory(filePath);

            //上傳文件
            var realFile = Path.Combine(filePath, finalName);
            using (var stream = System.IO.File.Create(realFile))
            {
                await files.CopyToAsync(stream);
            }

            //判斷文件格式(通過后綴名及文件頭編碼判斷)
            byte[] bytes = new byte[4];
            FileStream fileStream = new FileStream(realFile, FileMode.Open, FileAccess.Read);
            string temstr = "";
            if (Convert.ToInt32(fileStream.Length) > 0)
            {
                fileStream.Read(bytes, 0, 4);
                fileStream.Close();
                for (int i = 0; i < bytes.Length; i++)
                {
                    temstr += Convert.ToString(bytes[i], 16);
                }
            }
            var fileHeads = temstr.ToUpper();

            List<FileTypeModel> fileType = new List<FileTypeModel>();
            fileType.Add(new FileTypeModel { FileNameStr = "xlsx", FileHeadStr = "504B34" });
            fileType.Add(new FileTypeModel { FileNameStr = "xls", FileHeadStr = "D0CF11E0" });

            if (!fileType.Any(p => p.FileHeadStr.Contains(fileHeads)) || string.IsNullOrWhiteSpace(fileHeads))
            {
                //刪除剛剛上傳的文件
                Directory.Delete(realFile, true);
                throw Oops.Oh("文件類型錯誤");
            }
            #endregion

            #region

            //realFile
            //接下來就可以開始解析了
            IWorkbook _wb_xls = null;

            string fileEx = System.IO.Path.GetExtension(Path.GetFileName(realFile));
            FileStream _file = new FileStream(realFile, FileMode.Open, FileAccess.Read);

            if (realFile.IndexOf(".xlsx") > 0)
                _wb_xls = new XSSFWorkbook(_file);
            else if (realFile.IndexOf(".xls") > 0)
                _wb_xls = new HSSFWorkbook(_file);


            //保存成功信息
            List<DriverImportList> importList = new List<DriverImportList>();
            List<DriverImportList> errorList = new List<DriverImportList>();


            //開始讀取excel中數(shù)據(jù)并作數(shù)據(jù)校驗
            try
            {

                for (int i = 3; i < _wb_xls.GetSheet("DriverData").PhysicalNumberOfRows + 1; i++)
                {
                    var isDataCorrect = true;

                    var cellList = _wb_xls.GetSheet("DriverData").GetRow(i);

                    #region 解析司機個人信息

                    PersonalInformationModel driverModel = new PersonalInformationModel();
                    if (!string.IsNullOrEmpty(cellList.GetCell(1) + ""))
                        driverModel.FirstName = cellList.GetCell(1) + "";

                    //if (!string.IsNullOrEmpty(cellList.GetCell(2) + ""))
                    //    driverModel.MiddleName = cellList.GetCell(2) + "";

                    if (!string.IsNullOrEmpty(cellList.GetCell(3) + ""))
                        driverModel.LastName = cellList.GetCell(3) + "";

                    if (!string.IsNullOrEmpty(cellList.GetCell(4) + ""))
                    {
                        driverModel.PhonetNo = cellList.GetCell(4) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        driverModel.PhonetNo = "Error!Not Null";
                    }

                    if (!string.IsNullOrEmpty(cellList.GetCell(5) + ""))
                        driverModel.EMail = cellList.GetCell(5) + "";

                    if (!string.IsNullOrEmpty(cellList.GetCell(6) + ""))
                    {
                        driverModel.SocialInsurance = cellList.GetCell(6) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        driverModel.SocialInsurance = "Error!Not Null";
                    }

                    if (!string.IsNullOrEmpty(cellList.GetCell(7) + ""))
                    {
                        driverModel.License = cellList.GetCell(7) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        driverModel.License = "Error!Not Null";
                    }

                    if (!string.IsNullOrEmpty(cellList.GetCell(8) + ""))
                    {
                        driverModel.LicenseFirstIssueDate = cellList.GetCell(8) + "";
                    }
                    else if (!(cellList.GetCell(8) is DateTime))
                    {
                        isDataCorrect = false;
                        driverModel.LicenseFirstIssueDate = "Error!Must Time Type";
                    }
                    else
                    {
                        isDataCorrect = false;
                        driverModel.LicenseFirstIssueDate = "Error!Not Null";
                    }


                    if (!string.IsNullOrEmpty(cellList.GetCell(9) + ""))
                    {
                        driverModel.LicenseFromDate = cellList.GetCell(9) + "";
                    }
                    else if (!(cellList.GetCell(9) is DateTime))
                    {
                        isDataCorrect = false;
                        driverModel.LicenseFromDate = "Error!Must Time Type";
                    }
                    else
                    {
                        isDataCorrect = false;
                        driverModel.LicenseFromDate = "Error!Not Null";
                    }


                    if (!string.IsNullOrEmpty(cellList.GetCell(10) + ""))
                    {
                        driverModel.LicenseToDate = cellList.GetCell(10) + "";
                    }
                    else if (!(cellList.GetCell(10) is DateTime))
                    {
                        isDataCorrect = false;
                        driverModel.LicenseToDate = "Error!Must Time Type";
                    }
                    else
                    {
                        isDataCorrect = false;
                        driverModel.LicenseToDate = "Error!Not Null";
                    }
                    #endregion

                    #region 解析司機車輛信息
                    VehicleInformationModel carModel = new VehicleInformationModel();
                    //車輛型號
                    if (!string.IsNullOrEmpty(cellList.GetCell(12) + ""))
                    {
                        carModel.CarModelType = cellList.GetCell(12) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        carModel.CarModelType = "Error!Not Null";
                    }
                    //車身顏色
                    if (!string.IsNullOrEmpty(cellList.GetCell(13) + ""))
                    {
                        carModel.ExteriorColor = cellList.GetCell(13) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        carModel.ExteriorColor = "Error!Not Null";
                    }
                    //座位數(shù)
                    if (!string.IsNullOrEmpty(cellList.GetCell(14) + ""))
                    {
                        carModel.Seats = cellList.GetCell(14) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        carModel.Seats = "Error!Not Null";
                    }

                    //出廠日期
                    if (!string.IsNullOrEmpty(cellList.GetCell(15) + ""))
                    {
                        carModel.ProductionDate = cellList.GetCell(15) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        carModel.ProductionDate = "Error!Not Null";
                    }

                    //車牌號
                    if (!string.IsNullOrEmpty(cellList.GetCell(16) + ""))
                    {
                        carModel.LicensePlate = cellList.GetCell(16) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        carModel.LicensePlate = "Error!Not Null";
                    }

                    //保險開始日期
                    if (!string.IsNullOrEmpty(cellList.GetCell(17) + ""))
                    {
                        carModel.InsuranceFromDate = cellList.GetCell(17) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        carModel.InsuranceFromDate = "Error!Not Null";
                    }

                    //保險結(jié)束日期
                    if (!string.IsNullOrEmpty(cellList.GetCell(18) + ""))
                    {
                        carModel.InsuranceToDate = cellList.GetCell(18) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        carModel.InsuranceToDate = "Error!Not Null";
                    }
                    #endregion

                    #region 解析司機其他信息
                    OtherInformation otherModel = new OtherInformation();

                    //臺班費
                    if (!string.IsNullOrEmpty(cellList.GetCell(20) + ""))
                    {
                        otherModel.Percentage_Or_Amount = cellList.GetCell(20) + "";
                        //臺班費收費周期
                        if (!string.IsNullOrEmpty(cellList.GetCell(22) + ""))
                        {
                            otherModel.ChargeCycle = cellList.GetCell(22) + "";
                        }
                        else
                        {
                            isDataCorrect = false;
                            otherModel.ChargeCycle = "Error!Not Null";
                        }
                    }

                    //訂單抽成
                    if (!string.IsNullOrEmpty(cellList.GetCell(21) + ""))
                    {
                        otherModel.Percentage = cellList.GetCell(21) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        otherModel.Percentage = "Error!Not Null";
                    }

                    //賬戶狀態(tài)
                    if (!string.IsNullOrEmpty(cellList.GetCell(23) + ""))
                    {
                        otherModel.IsEnabled = cellList.GetCell(23) + "";
                    }
                    else
                    {
                        isDataCorrect = false;
                        otherModel.IsEnabled = "Error!Not Null";
                    }
                    #endregion

                    //如果該條數(shù)據(jù)數(shù)據(jù)校驗全通過,則添加到list中準(zhǔn)備入庫
                    if (isDataCorrect)
                    {
                        DriverImportList db_import = new DriverImportList();
                        db_import.PersonalInformationModel = driverModel;
                        db_import.VehicleInformationModel = carModel;
                        db_import.OtherInformation = otherModel;
                        importList.Add(db_import);
                    }
                    else
                    {
                        DriverImportList errorModel = new DriverImportList();
                        errorModel.PersonalInformationModel = driverModel;
                        errorModel.VehicleInformationModel = carModel;
                        errorModel.OtherInformation = otherModel;
                        errorList.Add(errorModel);
                    }
                }
            }
            catch (Exception ex)
            {

                throw Oops.Oh("解析失敗,請在下載的模板文件上進行編輯并上傳");
            }

            #endregion
            //表頭信息
            var headers = new List<ExcelHeader>
            {
                //司機信息
                new ExcelHeader{ Adress="B2", Value="PersonalInformation\r\n(司機信息)" },
                new ExcelHeader{ Adress="B3",Width=15,Value="First_Name"},
                new ExcelHeader{ Adress="C3",Width=15,Value="Last_Name"},
                new ExcelHeader{ Adress="D3",Width=15,Value="Phonet_No"},
                new ExcelHeader{ Adress="E3",Width=15,Value="E_Mail"},
                new ExcelHeader{ Adress="F3",Width=30,Value="Social_Insurance\r\n(社會保險)"},
                new ExcelHeader{ Adress="G3",Width=15,Value="License\r\n(駕照)"},
                new ExcelHeader{ Adress="H3",Width=40,Value="License_First_Issue_Date\r\n(駕照首次領(lǐng)證日期)"},
                new ExcelHeader{ Adress="I3",Width=35,Value="License_From_Date\r\n(駕照起始日期)"},
                new ExcelHeader{ Adress="J3",Width=35,Value="License_To_Date\r\n(駕照結(jié)束日期)"},

                //車輛信息
                new ExcelHeader{ Adress="L2", Value="VehicleInformation\r\n(車輛信息)"},
                new ExcelHeader{ Adress="L3",Width=25,Value="Car_Model_Type\r\n(車輛型號)"},
                new ExcelHeader{ Adress="M3",Width=25,Value="Exterior_Color\r\n(車輛顏色)"},
                new ExcelHeader{ Adress="N3",Width=25,Value="Seats\r\n(座椅數(shù)量)"},
                new ExcelHeader{ Adress="O3",Width=25,Value="Production_Date\r\n(出廠日期)"},
                new ExcelHeader{ Adress="P3",Width=25,Value="License_Plate\r\n(車牌號)"},
                new ExcelHeader{ Adress="Q3",Width=25,Value="Insurance_From_Date\r\n(保險起始日期)"},
                new ExcelHeader{ Adress="R3",Width=25,Value="Insurance_To_Date\r\n(保險結(jié)束日期)"},

                //其他信息
                new ExcelHeader{ Adress="T2", Value="OtherInformation\r\n(其他信息)"},
                new ExcelHeader{ Adress="T3",Width=30,Value="Percentage_Or_Amount\r\n\r\n(臺班費)"},
                new ExcelHeader{ Adress="U3",Width=30,Value="Percentage\r\n(訂單抽成)"},
                new ExcelHeader{ Adress="V3",Width=30,Value="ChargeCycle\r\n(臺班費收費周期)"},
                new ExcelHeader{ Adress="W3",Width=30,Value="IsEnabled\r\n(賬戶狀態(tài))"},
            };

            string localPath = AppDomain.CurrentDomain.BaseDirectory + System.DateTime.Now.ToString("yyyyMMdd");
            var filepath = Path.Combine(localPath, $"{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}.xlsx");
            FileInfo file = new FileInfo(filepath);
            if (file.Exists)
            {
                file.Delete();
                file = new FileInfo(filepath);
            }

            //創(chuàng)建文件夾
            if (!Directory.Exists(localPath))
                Directory.CreateDirectory(localPath);

            ExcelPackage.LicenseContext = OfficeOpenXml.LicenseContext.NonCommercial;
            ExcelPackage package = new ExcelPackage(file);
            //創(chuàng)建sheet
            ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("DriverData");

            //生成表頭
            for (int i = 0; i < headers.Count; i++)
            {
                worksheet.Cells[headers[i].Adress].Value = headers[i].Value;
                //合并單元格
                worksheet.Cells[2, 2, 2, 12].Merge = true;
                worksheet.Cells[2, 14, 2, 23].Merge = true;
                worksheet.Cells[2, 24, 2, 26].Merge = true;

                worksheet.Cells[headers[i].Adress].Style.Font.Size = 12; //字體大小
                worksheet.Cells[headers[i].Adress].Style.Font.Bold = true; //設(shè)置粗體
                worksheet.Cells[headers[i].Adress].Style.HorizontalAlignment = OfficeOpenXml.Style.ExcelHorizontalAlignment.Center; //水平居中對齊
                worksheet.Cells[headers[i].Adress].Style.VerticalAlignment = OfficeOpenXml.Style.ExcelVerticalAlignment.Center; //垂直居中對齊
                if (headers[i].Width > 0)
                    worksheet.Column(ColumnIndex(headers[i].Adress)).Width = headers[i].Width;
                //給第三行設(shè)置行高
                worksheet.Row(3).Height = 35;
                //設(shè)置表格邊框線(設(shè)置單元格所有邊框)
                #region 表頭設(shè)置邊框線
                worksheet.Cells["B2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["C2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["D2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["E2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["F2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["G2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["H2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["I2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["J2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));

                worksheet.Cells["L2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["M2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["N2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["O2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["P2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["Q2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["R2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["S2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["T2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));


                worksheet.Cells["V2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["W2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["X2"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));

                worksheet.Cells["B3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["C3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["D3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["E3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["F3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["G3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["H3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["I3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["J3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));

                worksheet.Cells["L3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["M3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["N3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["O3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["P3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["Q3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["R3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["S3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["T3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));


                worksheet.Cells["V3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["W3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                worksheet.Cells["X3"].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));

                //worksheet.Cells[1, 1].Style.Border.Bottom.Style = ExcelBorderStyle.Thin;//單獨設(shè)置單元格底部邊框樣式和顏色(上下左右均可分開設(shè)置)
                //worksheet.Cells[1, 1].Style.Border.Bottom.Color.SetColor(Color.FromArgb(191, 191, 191));
                #endregion
            }
            //循環(huán)填充內(nèi)容
            if (errorList != null)
            {
                //設(shè)置背景色
                Color colFromHex = System.Drawing.ColorTranslator.FromHtml("#7fcbfe");
                for (int i = 0; i < errorList.Count; i++)
                {
                    if (errorList[i].PersonalInformationModel != null)
                    {
                        //姓
                        worksheet.Cells["B" + (4 + i)].Value = errorList[i].PersonalInformationModel.FirstName;
                        worksheet.Cells["B" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.FirstName != null && errorList[i].PersonalInformationModel.FirstName.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["B" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["B" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //名
                        worksheet.Cells["C" + (4 + i)].Value = errorList[i].PersonalInformationModel.LastName;
                        worksheet.Cells["C" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.LastName != null && errorList[i].PersonalInformationModel.LastName.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["C" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["C" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //電話號碼
                        worksheet.Cells["D" + (4 + i)].Value = errorList[i].PersonalInformationModel.PhonetNo;
                        worksheet.Cells["D" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.PhonetNo != null && errorList[i].PersonalInformationModel.PhonetNo.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["D" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["D" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //郵箱
                        worksheet.Cells["E" + (4 + i)].Value = errorList[i].PersonalInformationModel.EMail;
                        worksheet.Cells["E" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.EMail != null && errorList[i].PersonalInformationModel.EMail.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["E" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["E" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //社會保障號
                        worksheet.Cells["F" + (4 + i)].Value = errorList[i].PersonalInformationModel.SocialInsurance;
                        worksheet.Cells["F" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.SocialInsurance != null && errorList[i].PersonalInformationModel.SocialInsurance.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["F" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["F" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //駕照號碼
                        worksheet.Cells["G" + (4 + i)].Value = errorList[i].PersonalInformationModel.License;
                        worksheet.Cells["G" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.License != null && errorList[i].PersonalInformationModel.License.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["G" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["G" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //初次領(lǐng)證日期
                        worksheet.Cells["H" + (4 + i)].Value = errorList[i].PersonalInformationModel.LicenseFirstIssueDate;
                        worksheet.Cells["H" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.LicenseFirstIssueDate != null && errorList[i].PersonalInformationModel.LicenseFirstIssueDate.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["H" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["H" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //駕照起始日期
                        worksheet.Cells["I" + (4 + i)].Value = errorList[i].PersonalInformationModel.LicenseFromDate;
                        worksheet.Cells["I" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.LicenseFromDate != null && errorList[i].PersonalInformationModel.LicenseFromDate.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["I" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["I" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //駕照結(jié)束日期
                        worksheet.Cells["J" + (4 + i)].Value = errorList[i].PersonalInformationModel.LicenseToDate;
                        worksheet.Cells["J" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].PersonalInformationModel.LicenseToDate != null && errorList[i].PersonalInformationModel.LicenseToDate.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["J" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["J" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }
                    }
                    if (errorList[i].VehicleInformationModel != null)
                    {
                        //車輛型號
                        worksheet.Cells["M" + (4 + i)].Value = errorList[i].VehicleInformationModel.CarModelType;
                        worksheet.Cells["M" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].VehicleInformationModel.CarModelType != null && errorList[i].VehicleInformationModel.CarModelType.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["M" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["M" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //車身顏色
                        worksheet.Cells["N" + (4 + i)].Value = errorList[i].VehicleInformationModel.ExteriorColor;
                        worksheet.Cells["N" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].VehicleInformationModel.ExteriorColor != null && errorList[i].VehicleInformationModel.ExteriorColor.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["N" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["N" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //座位數(shù)
                        worksheet.Cells["O" + (4 + i)].Value = errorList[i].VehicleInformationModel.Seats;
                        worksheet.Cells["O" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].VehicleInformationModel.Seats != null && errorList[i].VehicleInformationModel.Seats.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["O" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["O" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //出廠日期
                        worksheet.Cells["P" + (4 + i)].Value = errorList[i].VehicleInformationModel.ProductionDate;
                        worksheet.Cells["P" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].VehicleInformationModel.ProductionDate != null && errorList[i].VehicleInformationModel.ProductionDate.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["P" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["P" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //車牌號
                        worksheet.Cells["Q" + (4 + i)].Value = errorList[i].VehicleInformationModel.LicensePlate;
                        worksheet.Cells["Q" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].VehicleInformationModel.LicensePlate != null && errorList[i].VehicleInformationModel.LicensePlate.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["Q" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["Q" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //保險起始日期
                        worksheet.Cells["R" + (4 + i)].Value = errorList[i].VehicleInformationModel.InsuranceFromDate;
                        worksheet.Cells["R" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].VehicleInformationModel.InsuranceFromDate != null && errorList[i].VehicleInformationModel.InsuranceFromDate.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["R" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["R" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //保險結(jié)束日期
                        worksheet.Cells["S" + (4 + i)].Value = errorList[i].VehicleInformationModel.InsuranceToDate;
                        worksheet.Cells["S" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].VehicleInformationModel.InsuranceToDate != null && errorList[i].VehicleInformationModel.InsuranceToDate.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["S" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["S" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                    }
                    if (errorList[i].OtherInformation != null)
                    {
                        //臺班費
                        worksheet.Cells["X" + (4 + i)].Value = errorList[i].OtherInformation.Percentage_Or_Amount;
                        worksheet.Cells["X" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].OtherInformation.Percentage_Or_Amount.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["X" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["X" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //訂單抽成
                        worksheet.Cells["X" + (4 + i)].Value = errorList[i].OtherInformation.Percentage;
                        worksheet.Cells["X" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].OtherInformation.Percentage.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["X" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["X" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //臺班費收費周期
                        worksheet.Cells["X" + (4 + i)].Value = errorList[i].OtherInformation.ChargeCycle;
                        worksheet.Cells["X" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].OtherInformation.ChargeCycle.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["X" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["X" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }

                        //賬戶狀態(tài)
                        worksheet.Cells["X" + (4 + i)].Value = errorList[i].OtherInformation.IsEnabled;
                        worksheet.Cells["X" + (4 + i)].Style.Border.BorderAround(ExcelBorderStyle.Thin, Color.FromArgb(0, 0, 0));
                        if (errorList[i].OtherInformation.IsEnabled.IndexOf("Error!") > -1)
                        {
                            worksheet.Cells["X" + (4 + i)].Style.Fill.PatternType = OfficeOpenXml.Style.ExcelFillStyle.Solid;
                            worksheet.Cells["X" + (4 + i)].Style.Fill.BackgroundColor.SetColor(colFromHex);
                        }
                    }
                }
            }
            package.Save();
            //轉(zhuǎn)成流之后下載
            using (FileStream fs = new FileStream(filepath, FileMode.Open, FileAccess.Read))
            {
                byte[] byteArray = new byte[fs.Length];
                fs.Read(byteArray, 0, byteArray.Length);


                //刪除昨日生成的excel文件夾
                System.IO.File.Delete(AppDomain.CurrentDomain.BaseDirectory + System.DateTime.Now.AddDays(-1).ToString("yyyyMMdd"));
                return new FileContentResult(byteArray, "application/octet-stream")
                {
                    FileDownloadName = $"{DateTime.Now.ToString("yyyyMMddHHmmss")}錯誤記錄.xlsx"
                };
            }

/// <summary>
/// 根據(jù)單元格地址計算出單元格所在列的索引
/// </summary>
/// <param name="reference">單元格地址,示例A1,AB2</param>
/// <returns></returns>
private static int ColumnIndex(string reference)
{
    int ci = 0;
    reference = reference.ToUpper();
    for (int ix = 0; ix < reference.Length && reference[ix] >= 'A'; ix++)
    ci = (ci * 26) + ((int)reference[ix] - 64);
    return ci;
}

model部分


public class DriverImportList
{
    public PersonalInformationModel PersonalInformationModel { get; set; }
    public VehicleInformationModel VehicleInformationModel { get; set; }
    public OtherInformation OtherInformation { get; set; }
}

/// <summary>
/// excel上傳、司機個人信息
/// </summary>
public class PersonalInformationModel
{
    /// <summary>
    /// 姓
    /// </summary>
    public string FirstName { get; set; }
    /// <summary>
    /// 名
    /// </summary>
    public string LastName { get; set; }
    /// <summary>
    /// 電話號碼
    /// </summary>
    public string PhonetNo { get; set; }
    /// <summary>
    /// 郵箱
    /// </summary>
    public string EMail { get; set; }
    /// <summary>
    /// 社會保障號
    /// </summary>
    public string SocialInsurance { get; set; }
    /// <summary>
    /// 駕照
    /// </summary>
    public string License { get; set; }
    /// <summary>
    /// 初次領(lǐng)證日期
    /// </summary>
    public string LicenseFirstIssueDate { get; set; }
    /// <summary>
    /// 駕照有效期起始時間
    /// </summary>
    public string LicenseFromDate { get; set; }
    /// <summary>
    /// 駕照有效期結(jié)束時間
    /// </summary>
    public string LicenseToDate { get; set; }
}

/// <summary>
/// excel上傳、車輛相關(guān)信息
/// </summary>
public class VehicleInformationModel
{
    /// <summary>
    /// 車輛型號
    /// </summary>
    public string CarModelType { get; set; }
    /// <summary>
    /// 車身顏色
    /// </summary>
    public string ExteriorColor { get; set; }
    /// <summary>
    /// 座椅數(shù)量
    /// </summary>
    public string Seats { get; set; }
    /// <summary>
    /// 出廠日期
    /// </summary>
    public string ProductionDate { get; set; }
    /// <summary>
    /// 車牌號
    /// </summary>
    public string LicensePlate { get; set; }
    /// <summary>
    /// 保險開始日期
    /// </summary>
    public string InsuranceFromDate { get; set; }
    /// <summary>
    /// 保險結(jié)束日期
    /// </summary>
    public string InsuranceToDate { get; set; }
}


/// <summary>
/// excel上傳、其他雜項信息
/// </summary>
public class OtherInformation
{ 
    /// <summary>
    /// 臺班費
    /// </summary>
    public string Percentage_Or_Amount { get; set; }
    /// <summary>
    /// 臺班費收費周期
    /// </summary>
    public string ChargeCycle { get; set; }
    /// <summary>
    /// 訂單抽成
    /// </summary>
    public string Percentage { get; set; }
   
    /// <summary>
    /// 賬戶狀態(tài)
    /// </summary>
    public string IsEnabled { get; set; } 
}

public class ExcelHeader
{
        /// <summary>
        /// 單元格地址A1,B2等
        /// </summary>
        public string Adress { get; set; }
        /// <summary>
        /// 單元格值
        /// </summary>
        public string Value { get; set; }
        /// <summary>
        /// 單元格合并區(qū)域,示例A1:B2,為空表示不合并
        /// </summary>
        public string MergeArea { get; set; }
        /// <summary>
        /// 列寬度,合并列不需要指定寬度,示例:
        /// | A |
        /// |B|C|
        /// 表頭A是單元格B和單元格C合并而來,不需要指定寬度,只指定B和C寬度即可
        /// </summary>
        public int Width { get; set; }
}

參考文檔

1、Asp.NET Core 導(dǎo)出數(shù)據(jù)到 Excel 文件 - 碼農(nóng)教程

2、.net5下使用EPPlus導(dǎo)出Excel(復(fù)雜表頭)_.net 導(dǎo)出excel 多表頭_數(shù)據(jù)的流的博客-CSDN博客

3、Excel操作庫--EPPLUS常用操作命令匯總(1)_韋_恩的博客-CSDN博客
?

聯(lián)系方式:

? ? ? ? ? ? ? ? ?wechat&QQ&Tel:13501715983(如查不到請加QQ:631931078或352167311)

? ? ? ? ? ? ? ? ?個人郵箱:13212644043@163.com

OK,暫且這樣~文章來源地址http://www.zghlxwxcb.cn/news/detail-670435.html

到了這里,關(guān)于.NET CORE Api 上傳excel解析并生成錯誤excel下載的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • 銀河麒麟服務(wù)器v10 sp1 .Net6.0 上傳文件錯誤 access to the path is denied

    銀河麒麟服務(wù)器v10 sp1 .Net6.0 上傳文件錯誤 access to the path is denied

    上一篇:銀河麒麟服務(wù)器v10 sp1 部署.Net6.0 http https_csdn_aspnet的博客-CSDN博客 .NET 6之前,在Linux服務(wù)器上安裝 libgdiplus 即可解決,libgdiplus是System.Drawing.Common原生端跨平臺實現(xiàn)的主要提供者,是開源mono項目。地址:GitHub - mono/libgdiplus: C-based implementation of the GDI+ API 因此,解決方法

    2024年02月12日
    瀏覽(23)
  • VisualSVN Server下載安裝和使用方法、服務(wù)器搭建、使用TortoiseSvn將項目上傳到云端服務(wù)器、各種錯誤解決方法

    VisualSVN Server下載安裝和使用方法、服務(wù)器搭建、使用TortoiseSvn將項目上傳到云端服務(wù)器、各種錯誤解決方法

    請大家多多指正,歡迎大家關(guān)注! 以A臺電腦作為服務(wù)器,B臺電腦從服務(wù)器上拉代碼下來到B電腦本地。 截止2024.01.19為最新版本 寫這篇文章主要是總是忘記如何將寫好的項目推送到服務(wù)器里這個操作,其他都是捎帶,寫下來,再忘就看這篇文章。一寫就太多了,但沒有相應(yīng)的

    2024年02月21日
    瀏覽(29)
  • .net core 上傳文件大小限制

    .net core 上傳文件大小限制

    微軟官網(wǎng)文檔中給的解釋是.net core 默認上傳文件大小限制是30M,所以即便你項目里沒有限制,這里也有個默認限制。 官網(wǎng)鏈接地址 總結(jié)了一下解決辦法: 1.首先項目里添加一個web.config自定義配置文件 在配置文件中加上這段配置 !--//上傳文件大小限制IIS設(shè)置 256M -- ? system.

    2024年02月09日
    瀏覽(92)
  • .NET Core 實現(xiàn)Excel的導(dǎo)入導(dǎo)出

    .NET Core 實現(xiàn)Excel的導(dǎo)入導(dǎo)出

    目錄 前言 NPOI簡介 一、安裝相對應(yīng)的程序包 1.1、在 “管理NuGet程序包” 中的瀏覽搜索:“NPOI” 二、新建Excel幫助類 三、調(diào)用 3.1、增加一個“keywords”模型類,用作導(dǎo)出 3.2、添加一個控制器 3.3、編寫導(dǎo)入導(dǎo)出的控制器代碼 3.3.1、重寫“Close”函數(shù) 3.3.2、添加控制器代碼 3.

    2024年02月08日
    瀏覽(22)
  • .NET Core NPOI導(dǎo)出復(fù)雜Excel

    .NET Core NPOI導(dǎo)出復(fù)雜Excel

    NPOI GitHub源碼地址: GitHub - tonyqus/npoi: a .NET library that can read/write Office formats without Microsoft Office installed. No COM+, no interop. 版本說明: NPOI 2.4.1 (注意不同版本可能使用的姿勢有點小差別) 程序包管理器控制臺輸入一下命令安裝: 1 Install-Package NPOI -Version 2.4.1 通過NuGet管理解決方

    2024年02月03日
    瀏覽(17)
  • GameFramework:打包資源,打隨app發(fā)布包,打包生成文件夾說明,上傳資源至服務(wù)器,下載資源,GameFreamworkList.dat 與GameFrameworkVersion.dat

    GameFramework:打包資源,打隨app發(fā)布包,打包生成文件夾說明,上傳資源至服務(wù)器,下載資源,GameFreamworkList.dat 與GameFrameworkVersion.dat

    左邊為ab包,中間為ab包中內(nèi)容,右邊為項目中資源文件 點擊save,SaveConfiguration,保存打包關(guān)系到ResourceCollection.xml中 是否使用文件系統(tǒng),只能在xml中手動配置,代表下載完后會把幾個零散的ab文件合成一個文件 1、AssetBundle 列表 AssetBundle列表(AssetBundle List)列出了項目中包含

    2023年04月08日
    瀏覽(24)
  • .NET Core WebAPI 基礎(chǔ) 文件上傳

    .NET Core WebAPI 基礎(chǔ) 文件上傳

    昨天分享了一個在WebApi中如何接收參數(shù)的文章 傳送門,然后有新人小伙伴就問了,那文件上傳呢,這個怎么弄,借此我寫了一個小demo,分享給大家。 通常來說,上傳文件,我們是使用POST,還是老規(guī)矩先上代碼: 這是需要上傳的txt文件。 這里有一個需要注意的地方,就是上

    2024年02月11日
    瀏覽(20)
  • MinIO (五) .net core實現(xiàn)分片上傳

    開發(fā)環(huán)境 Win11 vs2022 appsettings.json添加配置項 注入代碼 接下來是后端進行分片上傳的代碼示例,有兩個,第一個是從官方考下來的代碼示例,第二個是自己整理后的代碼示例。 從官方考下來的代碼示例 整理后的后端進行分片上傳

    2024年02月03日
    瀏覽(26)
  • .net Core API 添加 NLog

    nlog.config program.cs? NuGet packages:NLog、NLog.Web.AspNetCore?

    2024年02月12日
    瀏覽(13)
  • .NET Core6.0使用NPOI導(dǎo)入導(dǎo)出Excel

    .NET Core6.0使用NPOI導(dǎo)入導(dǎo)出Excel

    一、使用NPOI導(dǎo)出Excel //引入NPOI包 HTML JS C# 二、使用NPOI導(dǎo)入Excel HTML JS C# 控制器代碼 添加ExcelHelper類 添加Extensions類 添加實體類UserEntity,要跟Excel的列名一致 Excel模板 實現(xiàn)效果

    2024年02月12日
    瀏覽(21)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包