public DataSet ReadExcel(string str, DataSet ds, HttpFileCollection FileCollect) { EmployeeImportHelpers th = new EmployeeImportHelpers(); HttpPostedFile FileSave = FileCollect[str]; //用key获取单个文件对象HttpPostedFile string fileName = FileSave.FileName.Substring(FileSave.FileName.LastIndexOf("\\") + 1); string filePath = string.Format(HttpRuntime.AppDomainAppPath.ToString() + @"Upload"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string Path = string.Format("{0}\\{1}_{2}", filePath, DateTime.Now.ToString("yyyyMMddHHmmss"), fileName); FileSave.SaveAs(Path); ds = th.ReadExlToDt(Path); System.IO.File.Delete(Path); return(ds); }
//打开excel public ActionResult OpenExcel(FormCollection form) { EmployeeImportHelpers th = new EmployeeImportHelpers(); HttpRequest request = System.Web.HttpContext.Current.Request; HttpFileCollection FileCollect = request.Files; if (FileCollect.Count > 0) { foreach (string str in FileCollect) { HttpPostedFile FileSave = FileCollect[str]; //用key获取单个文件对象HttpPostedFile string fileName = FileSave.FileName.Substring(FileSave.FileName.LastIndexOf("\\") + 1); string filePath = string.Format(HttpRuntime.AppDomainAppPath.ToString() + @"Upload"); if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } string Path = string.Format("{0}\\{1}_{2}", filePath, DateTime.Now.ToString("yyyyMMddHHmmss"), fileName); FileSave.SaveAs(Path); //将上传的文件保存 //return Json(ResultData.CreateError("维护中,暂不能用!")); dsRead = th.ReadExlToDt(Path); combo.Clear(); // Dictionary<string, int> list = new Dictionary<string, int>(); for (int i = 0; i < dsRead.Tables.Count; i++) { combobox combobox = new combobox(); combobox.id = i.ToString(); combobox.text = dsRead.Tables[i].TableName; combo.Add(combobox); //list.Add(dsRead.Tables[i].TableName, i); } return(Json(ResultData.Create(null), "text/html;charset=utf-8", JsonRequestBehavior.AllowGet)); } } return(View(form)); }