asp.net core MiniExcelLibs 导出excel

浪淘沙12个月前后端76
public IActionResult OnPostDown()
{
  
    DataTable table = new DataTable();
    table.Columns.Add("部门", typeof(string));
    table.Columns.Add("姓名", typeof(string));
    table.Columns.Add("职务", typeof(string));
    table.Columns.Add("评定等级", typeof(string));

    table.Columns.Add("年份", typeof(string));
    table.Columns.Add("次数", typeof(string));
    table.Columns.Add("详细", typeof(string));

    DataTable dt = _db.Ado.GetDataTable("select * from pub_member where bm<>'校领导' and groupid<>3 order by id asc");//bm asc,
    if (dt.Rows.Count > 0)
    {

        for (int i = 0; i < dt.Rows.Count; i++)
        {
            DataRow dr = table.NewRow();
            dr[0] = dt.Rows[i]["bm"].ToString();
            dr[1] = dt.Rows[i]["truename"].ToString();
            dr[2] = dt.Rows[i]["zw"].ToString();
            table.Rows.Add(dr);

        }


    }

    // 创建内存流用于存储 Excel 数据
    using var stream = new MemoryStream();

    // 使用 MiniExcel 将数据写入到内存流
    stream.SaveAs(table);

    // 返回 Excel 文件作为文件下载响应
    return File(stream.ToArray(), "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "评定表_"+ tbl + ".xlsx");

  
}


相关文章

SqlSugar

   var dt = _db.SqlQueryable<object>("select * fr...

oss文件上传

using Aliyun.OSS; #region Oss文件上传  /// <summary>  /// O...

asp.net core弹出对话框最佳实践

 public void OnGet()  {         ...

asp.net core 引用ckeditor编辑器

网页<script src="~/ckeditor/ckeditor.js"></script> <script src=&qu...

asp.net core razor 远程请求 认证Basic auth 模式 body传递 json

private readonly HttpClient _httpClient;    public RemoteReq...

asp.net core指定运行端口 如:http://localhost:5002

网站根目录新建:hosting.json输入:{   "urls": "http://localhost:5002" }...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。