ExcelPackage 使用說明

2021/8/18 23:11:54

本文主要是介绍ExcelPackage 使用說明,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

1.使用方法

        public IActionResult Excel()
        {
            string sWebRootFolder = _hostingEnvironment.WebRootPath;
            string sFileName = "测试导出excel.xlsx";

            FileInfo file = new FileInfo(Path.Combine(sWebRootFolder, sFileName));

            file.Delete();

            using (ExcelPackage package = new ExcelPackage(file))

            {
                // 添加worksheet

                ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("部落");

                //添加头
                //worksheet.Cells[1, 1].Value = "ID";
                //worksheet.Cells[1, 2].Value = "Name";
                //worksheet.Cells[1, 3].Value = "Url";

                worksheet.Cells["A1"].Value = "编号";
                worksheet.Cells["B1"].Value = "姓名";
                worksheet.Cells["C1"].Value = "Url";
                worksheet.Cells["D1"].Value = "时间";

                //添加值
                worksheet.Cells["A2"].Value = 1000;
                worksheet.Cells["B2"].Value = "For丨丶";
                worksheet.Cells["C2"].Value = "网页链接";
                worksheet.Cells["D2"].Value = DateTime.Now.ToString();

                worksheet.Cells["A3"].Value = 1001;
                worksheet.Cells["B3"].Value = "For丨丶Tomorrow";
                worksheet.Cells["C3"].Value = "网页链接";
                worksheet.Cells["C3"].Style.Font.Bold = true;

                package.Save();
            }
            return File(sFileName, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", sFileName);
        }

  



这篇关于ExcelPackage 使用說明的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程