asp.net core MiniExcelLibs 导出excel

浪淘沙2年前后端224
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 Task 返回类型

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

使用 Razor Pages 的多个 Handler

<form method="post" asp-page-handler="Save">    ...

asp.net core razor 使用ClosedXML.Excel 导出表格

            using var workbook...

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

private readonly HttpClient _httpClient;    public RemoteReq...

asp.net core razor .cshtml.cs 如何改变写入中文后变成ANSI格式为utf-8

根目录下,添加.editorconfig并写入[*.cshtml.cs] charset = utf-8已生成的文件另存为 utf-8格式...

sqlite数据库备份

  public IActionResult OnPostBf()   {      ...

发表评论    

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