|
MVC中使用NPOI导出excel
controller中
public FileResult btnExport_Click()
{
DataTable dt = ((DataSet)Session["dll_ds"]).Tables[0];
NPOI.HSSF.UserModel.HSSFWorkbook b = new NPOI.HSSF.UserModel.HSSFWorkbook();
NPOI.SS.UserModel.ISheet sheet1 = b.CreateSheet("Sheet1");
NPOI.SS.UserModel.IRow row1 = sheet1.CreateRow(0);
{
row1.CreateCell(i).SetCellValue(dt.Columns[i].ColumnName);
}
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());
}
}
// 写入到客户端
System.IO.MemoryStream ms = new System.IO.MemoryStream();
b.Write(ms);
ms.Seek(0, SeekOrigin.Begin);
return File(ms, "application/vnd.ms-excel", "Excel.xls");
}
前端view中
F.Button()
.ID("btnExport")
.Text("导出excel")
.DisableControlBeforePostBack(false)
.OnClick(Url.Action("btnExport_Click")),
结果页面没有反应,这种办法在asp.net mvc中没问题,但FNEUI不行,正确写法应该是怎么?谢谢
|
|