private void DoImpUser()
        {
            string FileName  = RequestData.Get("FileId") + "";
            string SurveyId  = RequestData.Get("SurveyId") + "";
            string InputType = RequestData.Get("InputType") + "";     //导入的类型

            FileName = MapPath("/Document/") + FileName;
            ComUtility Ut = new ComUtility();
            DataTable  dt = Ut.ExcelToDataTable(FileName);
        }
Beispiel #2
0
        /// <summary>
        /// Excel转成DataTable
        /// </summary>
        /// <param name="FileName">文件全路径</param>
        /// <returns></returns>
        public DataTable ExcelToDataTable(string FileName)
        {
            string Extend  = string.Empty;  //文件扩展名
            string strConn = string.Empty;

            if (FileName.Contains(","))
            {
                FileName = FileName.Substring(0, FileName.Length - 1);
                Extend   = FileName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)[1];
            }
            else
            {
                Extend = FileName.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)[1];
            }

            strConn = ComUtility.GetConStr(FileName);  //获取Excel连接字符串

            OleDbConnection  XLSconn = new OleDbConnection(strConn);
            OleDbDataAdapter da      = new OleDbDataAdapter("select * from [Sheet1$]", XLSconn);
            DataTable        dt      = new DataTable();

            da.Fill(dt);


            if (dt.Rows.Count > 0)
            {
                try
                {
                    if (File.Exists(FileName))
                    {
                        File.Delete(FileName);
                    }
                }
                catch
                {
                }
            }

            return(dt);
        }