public IHttpActionResult Temp() { // return Ok("导入成功"); var filePath = @"D:\aaa.xls"; //string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + filePath + ";" + "Extended Properties=Excel 8.0;"; string strConn = string.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0};Extended Properties='Excel 8.0;HDR=Yes;IMEX=1;'", filePath); System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(strConn); conn.Open(); string strExcel = ""; System.Data.OleDb.OleDbDataAdapter myCommand = null; System.Data.DataSet ds = null; strExcel = "select * from [Sheet1$]"; myCommand = new System.Data.OleDb.OleDbDataAdapter(strExcel, strConn); ds = new System.Data.DataSet(); myCommand.Fill(ds, "table1"); var table = ds.Tables[0]; for (var i = 0; i < table.Rows.Count; i++) { var row = table.Rows[i]; var location = _locationService.GetLocationByName(row[0].ToString()); if (location == null) { continue; } var scene = new PanoramaScene(); scene.Views = 0; scene.Stars = 0; scene.ProductionDate = Convert.ToDateTime(row[1]); scene.LastViewDate = DateTime.Now; scene.PanoramaLocation = location; _sceneService.InsertPanoramaScene(scene); location.DefaultPanoramaSceneId = scene.Id; _locationService.UpdatePanoramaLocation(location); } return(Ok("更新完成")); }