C# 使用EPPlus 秒导出10万条数据
2021-07-01 07:06
标签:引用 .sh 输入 pac col condition ima file time 1.先要引用dll文件,可以直接使用vs自带的包管理,如下图: 输入 EPPlus 我这里是安装过了的所以这里显示的是卸载而不是安装。 安装成功了之后会看到这个dll文件 代码如下: C# 使用EPPlus 秒导出10万条数据 标签:引用 .sh 输入 pac col condition ima file time 原文地址:https://www.cnblogs.com/LoveQin/p/9957254.html//导出Excel
protected void BtnMemExcel_Click(object sender, EventArgs e)
{
Mem bllMember = new Mem();
int Counts = NetPagerParameter.RecordCount;
string strSql = QueryCondition();
strSql += "and Mem.MemShopID = SysShop.ShopID and Mem.MemLevelID = MemLevel.LevelID and Mem.MemUserID = SysUser.UserID";
strSql += (" and Mem.MemShopID =SysShopMemLevel.ShopID and SysShopMemLevel.MemLevelID=MemLevel.LevelID ");
DataTable db = bllMember.GetListSP(100000, 1, out Counts, PubFunction.GetShopAuthority(_UserShopID, "MemShopID", strSql)).Tables[0];//讲数据填充到table中
//核心代码
using (ExcelPackage package = new ExcelPackage())
{
ExcelWorksheet worksheet = package.Workbook.Worksheets.Add("Sheet");
worksheet.Cells[1, 1].Value = "会员卡号";
worksheet.Cells[1, 2].Value = "会员姓名";
worksheet.Cells[1, 3].Value = "会员余额" + DateTime.Now.ToString("yyyy-MM-dd HH:mmssffff");
for (int i = 2; i 2; i++)
{
worksheet.Cells[i, 1].Value = db.Rows[i - 2]["MemCard"];
worksheet.Cells[i, 2].Value = db.Rows[i - 2]["MemName"];
worksheet.Cells[i, 3].Value = db.Rows[i - 2]["MemMobile"];
worksheet.Cells[i, 4].Value = db.Rows[i - 2]["MemBirthday"];
worksheet.Cells[i, 5].Value = db.Rows[i - 2]["MemPoint"];
worksheet.Cells[i, 6].Value = db.Rows[i - 2]["MemConsumeMoney"];
worksheet.Cells[i, 7].Value = db.Rows[i - 2]["ShopName"];
}
var data = package.GetAsByteArray();
//保存和归来的Excel文件作为一个ByteArray
HttpResponse response = HttpContext.Current.Response;
Response.Clear();
//输出头文件
Response.AddHeader("content-disposition", "attachment; filename=会员信息.xlsx");
Response.ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
Response.BinaryWrite(data);
Response.Flush();
Response.End();
//package.Save();//这个方法是直接下载到本地
}
}
文章标题:C# 使用EPPlus 秒导出10万条数据
文章链接:http://soscw.com/index.php/essay/100216.html