码迷,mamicode.com
首页 > 其他好文 > 详细

导入导出

时间:2019-05-31 21:22:30      阅读:88      评论:0      收藏:0      [点我收藏+]

标签:post   info   serialize   write   sub   data   orm   name   app   

//导入1111
public ActionResult lead(HttpPostedFileBase fname)
{
if (fname!=null)
{
Stream steam = fname.InputStream;
var table = ExcelHelper.ImportToDataTables(steam);
var json = JsonConvert.SerializeObject(table);
var list = JsonConvert.DeserializeObject<List<student>>(json);
return View("Index", list);
}
else
{
Response.Write("<script>alert(‘请选择文件‘);location.href=‘/Default/Index‘");
return View();
}
}
*****************
@using (Html.BeginForm("lead", "Default", FormMethod.Post, new { enctype = "multipart/form-data" }))
{
<input id="File1" type="file" name="fname" />
<input id="Submit1" type="submit" value="导入" />
}
------------------------------------------------------------------------
//导出
public FileResult derive()
{
var table = bl.Show();
var fs = ExcelHelper.ExportToXlss(table);
return File(fs,"application/vnd.ms-excel","测试.xls");
}
*****************
<input id="Button1" type="button" value="导出" onclick="location.href=‘/Default/derive‘" />
------------------------------------------------------------------------

导入导出

标签:post   info   serialize   write   sub   data   orm   name   app   

原文地址:https://www.cnblogs.com/gaoyuhui/p/10957321.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!