怎么实现点击导出调用ExportUser
发布于 8 年前 作者 ltjzwfy 4570 次浏览 来自
粉丝福利 : 关注VUE中文社区公众号,回复视频领取粉丝福利

<button v-on:click="educe" >导出</abutton >

educe() { window.location.href = ‘/user/exportuser’; }

public object ExportUser() { DataTable dt = db.T("select * from UserProfile ").ExecuteDataTable();//获取需要导出的datatable数据
//创建Excel文件的对象
NPOI.HSSF.UserModel.HSSFWorkbook book = new NPOI.HSSF.UserModel.HSSFWorkbook(); //添加一个sheet
NPOI.SS.UserModel.ISheet sheet1 = book.CreateSheet(“Sheet1”); //给sheet1添加第一行的头部标题
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0); //row1.RowStyle.FillBackgroundColor = “”;
for (int i = 0; i < dt.Columns.Count; i++) { row1.CreateCell(i).SetCellValue(dt.Columns[i].ColumnName); } //将数据逐步写入sheet1各个行
for (int i = 0; i < dt.Rows.Count; i++) { NPOI.SS.UserModel.IRow rowtemp = sheet1.CreateRow(i + 1); for (int j = 0; j < dt.Columns.Count; j++) { rowtemp.CreateCell(j).SetCellValue(dt.Rows[i][j].ToString().Trim()); } } string strdate = DateTime.Now.ToString(“yyyyMMddhhmmss”);//获取当前时间
// 写入到客户端
MemoryStream ms = new System.IO.MemoryStream(); book.Write(ms); ms.Seek(0, SeekOrigin.Begin); return File(ms, “application/vnd.ms-excel”, strdate + “Excel.xls”); }

回到顶部