asp.net core MiniExcelLibs 导出excel

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

  
}


相关文章

asp.net core razor 中文搜索 url转码

 return Redirect("feedback_list?fst=" + fst + "&Status=" + Status + &qu...

asp.net core 发送253短信

<form method="post">     <button type="submit...

asp.net core razor 输出html

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

asp.net core Task 返回类型

public async Task<IActionResult> OnPostAsync()   {   &nbs...

asp.net core rzaor page 中的ViewComponent 视图用法

asp.net core rzaor page 中的ViewComponent 视图用法

1、/Pages/Components 新建:MyViewComponent.csusing Microsoft.AspNetCore.Mvc; namespace xxts...

发表评论    

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