导出excel

浪淘沙2年前后端224
@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");


           

        }
    }
}


相关文章

ckeditor编辑器

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

asp.net core 图片转正

在 ASP.NET Core 中将图片旋转为正向,通常你需要处理图片的 EXIF 信息,因为一些相机和手机拍摄的照片会包含方向信息,表示照片应该如何旋转才能显示为正确的方向。可以使用一个图像处理库来实...

asp.net core 对datatable 中的内容 组装a1,a2,a3

var fzlm_name = string.Join(",",       &...

C#JNTemplate模板引擎,标签指定${set(pagetotal=20)},后端如何获取pagetotal的值

using JinianNet.JNTemplate; class Program {     static void&...

asp.net core vue element plus select 下拉绑定

一、后端public List<dynamic> yxm { get; set; } = new();//就...

asp.net 导出word ktb 带图片

一、引用using Aspose.Words; using Aspose.Words.Drawing; using Aspose.Words.Replacing;二、...

发表评论    

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