asp.net core MiniExcelLibs 导出excel

浪淘沙1年前后端141
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");

  
}


相关文章

DBeaver连接oracle 下载驱动报错

https://blog.csdn.net/weixin_45764765/article/details/124327194...

asp.net core razor 输出html

@Html.Raw(Model.HtmlContent)...

asp.net core 取得页面form中所有表单值

public IActionResult OnPostSubmit()         { &n...

取消 "将 null 文本或可能的 null 值转换为不可为 null 类型。 "提示

在 .csproj 文件中添加或修改:<PropertyGroup>  <Nullable>disable</Nullable></Pro...

asp.net core razor 获取当前url

 @Request.Scheme://@Request.Host/anysc/dd_ts_stu...

短信发送

@page @model xxtsoft.Web.Entry.Pages.Index1Model @{ } <form method="post"...

发表评论    

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