求解asp.net mvc 中上传excel 怎么导入到数据库中!
求解asp.net mvc 中上传excel 如何导入到数据库中!!!
如何在mvc中实现excel的导入,并将导入的数据,先存到临时表,然后根据选择性的数据,插入到数据库。。。求各位MVC高手指教!!!最好附加个例子!!源码更好,借鉴研究一下! O(∩_∩)O谢谢各位喽!
------解决方案--------------------
读取excel模板,导出excel的例子:
------解决方案--------------------
ExcelExportHandler类的定义:
如何在mvc中实现excel的导入,并将导入的数据,先存到临时表,然后根据选择性的数据,插入到数据库。。。求各位MVC高手指教!!!最好附加个例子!!源码更好,借鉴研究一下! O(∩_∩)O谢谢各位喽!
------解决方案--------------------
读取excel模板,导出excel的例子:
public ActionResult ExportQualifiedExaminees(int serviceid, int funcid, string condition)
{
RegistrationBLL bll = new RegistrationBLL();
IList<QualifiedExamineeEn> list = bll.GetQualifiedExaminees(serviceid, condition);
if (list == null
------解决方案--------------------
list.Count == 0)
{
return Alert("没有准考证信息", "~/Views/ExamService/SaveSuccess.aspx", new { controller = "Registration", action = "GetExamineeByPage", serviceid = serviceid, funcid = funcid });
}
using (MemoryStream m = bll.ExportQualifiedExaminees(Server.MapPath("~/Resources/考生签到表导出模版.xls"), list1[0].fServiceName, list, Server.MapPath("~/Common/Images/toeic_log.PNG")))
{
ExcelExportHandler.ExportFile(m, "application/ms-excel", "UTF-8", "GB2312", "考生签到表.xls");
}
return new EmptyResult();
}
------解决方案--------------------
ExcelExportHandler类的定义:
public class ExcelExportHandler
{
public static void ExportFile(string content, string contentType, string charSet, string encodingName, string outPutFileName)
{
byte[] htmlBy = System.Text.Encoding.GetEncoding("GB2312").GetBytes(content);
MemoryStream stream = new MemoryStream(htmlBy);
ExportFile(stream, contentType, charSet, encodingName, outPutFileName);
}
public static void ExportFile(MemoryStream stream, string contentType, string charSet, string encodingName, string outPutFileName)
{
HttpContext.Current.Response.Clear();