导出excel

浪淘沙1年前后端113
@page
@model xxtsoft.Web.Entry.Pages.test2Model
@{
}
<form method="post">
    <button type="submit" asp-page-handler="down" class="btn">导出excel1</button>

    <button type="submit" asp-page-handler="down02" class="btn">导出excel2</button>
</form>
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;

using MiniExcelLibs;

using System.Data;

using xxtsoft.Common;
using xxtsoft.Core.Common;

namespace xxtsoft.Web.Entry.Pages
{
    public class test2Model : PageModel
    {
        private readonly SqlSugar.ISqlSugarClient _db;
        public test2Model(SqlSugar.ISqlSugarClient db)
        {
            this._db = db;
            //_db.ChangeDatabase("1");
        }
        public void OnGet()
        {
          
        }


        public IActionResult OnPostDown()
        {
            DataTable dt = _db.Ado.GetDataTable("select * from qy_info");
            EPPlusHelper epp = new EPPlusHelper();
            return epp.outExcel(dt,"2.xlsx");
           //return Page();

        }
        public IActionResult OnPostDown02()
        {
            DataTable dt = _db.Ado.GetDataTable("select * from qy_info");          

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

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

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


           

        }
    }
}


相关文章

visual studio 配置 asp.net core razor .shtml文件类型和包含,支持跨平台通用

自己在 ASP.NET Core 里写 Middleware 解析 SSI自己在 ASP.NET Core 里写 Middleware 解析 ...

asp.net core MiniExcelLibs 导出excel

public IActionResult OnPostDown() {        DataTable ...

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格式...

asp.net core ZipDeploy iis发布 忽略某一件文件夹被删除

  services.AddZipDeploy(o => o.IgnorePathStarting("wwwroot/")); //iis发布...

ckeditor编辑器

@page @model xxtsoft.Web.Entry.Pages.Index2Model @{ } <script src="~/ckeditor/...

发表评论    

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