Asp.net 导入Excel

前台代码:

<body>
    <form id="form1" runat="server">
    <div>
        <asp:FileUpload ID="FileUpload" runat="server" />
        <asp:Button ID="btn" runat="server" Text="Button" OnClick="btn_Click" />
    </div>
    </form>
</body>   

后台代码:

protected void btn_Click(object sender, EventArgs e)
        {
            if (!this.FileUpload.HasFile)
            {
                this.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(‘路径不能为空!‘);</script>");
                return;
            }   

            ////判断文件是否小于10Mb
            //if (FileUpload.PostedFile.ContentLength < 10485760)
            //{
            try
            {
                //上传文件并指定上传目录的路径
                FileUpload.PostedFile.SaveAs(Server.MapPath("~/UploadFiles/")
                    + FileUpload.FileName);
                string fileName = System.Web.HttpContext.Current.Server.MapPath("~/UploadFiles/" + FileUpload.FileName + "");   

//把Excel数据转化成datatable数据  引用实体类DataTableToExcel的方法InputFromExcel()
                DataTable dt = new Common.DataTableToExcel().InputFromExcel(System.Web.HttpContext.Current.Server.MapPath("~/UploadFiles/" + FileUpload.FileName + ""), "Sheet1");   

                List<String> list = new List<string>();
                string strInsertComm = "";
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    strInsertComm = "Insert into STUDENT_WishSelectSchool(EduId,MiddleSchoolCode,WishType)";//数据库表的字段
                    strInsertComm += " values(";
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        if (j > 0)
                        {
                            strInsertComm += ",‘" + dt.Rows[i][j].ToString().Trim() + "‘";
                        }
                        else
                        {
                            strInsertComm += "‘" + dt.Rows[i][j].ToString().Trim() + "‘";
                        }
                    }
                    strInsertComm += ")";
                    list.Add(strInsertComm);
                }
                Maticsoft.BLL.Wish.SelectSchool bll = new BLL.Wish.SelectSchool();
                if (bll.Add(list) > 0)
                {
                    this.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(‘导入成功!‘);</script>");
                }
                else
                {
                    this.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(‘导入失败!‘);</script>");
                }
            }
            catch (Exception ex)
            {
                this.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert(‘" + ex.Message + "‘);</script>");
            }   

            //}
            //else
            //{
            //    //lblMessage.Text = "上传文件不能大于10MB!";
            //}
        }  

连接数据库:

//执行批量添加的时候用事物添加(回滚)
public int Add(List<String> list)
        {
            object obj = DbHelperSQL.ExecuteSqlTran(list);
            if (obj == null)
            {
                return 0;
            }
            else
            {
                return Convert.ToInt32(obj);
            }
        }   

 /// <summary>
        /// 执行多条SQL语句,实现数据库事务。
        /// </summary>
        /// <param name="SQLStringList">多条SQL语句</param>
        public static int ExecuteSqlTran(List<String> SQLStringList)
        {
            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                SqlTransaction tx = conn.BeginTransaction();
                cmd.Transaction = tx;
                try
                {
                    int count = 0;
                    for (int n = 0; n < SQLStringList.Count; n++)
                    {
                        string strsql = SQLStringList[n];
                        if (strsql.Trim().Length > 1)
                        {
                            cmd.CommandText = strsql;
                            count += cmd.ExecuteNonQuery();
                        }
                    }
                    tx.Commit();
                    return count;
                }
                catch
                {
                    tx.Rollback();
                    return 0;
                }
            }
        }   

连接Excel并把数据转化成datatable的类

public class DataTableToExcel
    {
        #region 数据导出至Excel文件
        /// </summary>
        /// 导出Excel文件,自动返回可下载的文件流
        /// </summary>
        public void DataTable1Excel(System.Data.DataTable dtData)
        {
            GridView gvExport = null;
            HttpContext curContext = HttpContext.Current;
            StringWriter strWriter = null;
            HtmlTextWriter htmlWriter = null;
            if (dtData != null)
            {
                curContext.Response.ContentType = "application/vnd.ms-excel";
                curContext.Response.ContentEncoding = System.Text.Encoding.GetEncoding("gb2312");
                curContext.Response.Charset = "utf-8";
                strWriter = new StringWriter();
                htmlWriter = new HtmlTextWriter(strWriter);
                gvExport = new GridView();
                gvExport.DataSource = dtData.DefaultView;
                gvExport.AllowPaging = false;
                gvExport.DataBind();
                gvExport.RenderControl(htmlWriter);
                curContext.Response.Write("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=gb2312\"/>" + strWriter.ToString());
                curContext.Response.End();
            }
        }   

        /// <summary>
        /// 导出Excel文件,转换为可读模式
        /// </summary>
        public void DataTable2Excel(System.Data.DataTable dtData)
        {
            DataGrid dgExport = null;
            HttpContext curContext = HttpContext.Current;
            StringWriter strWriter = null;
            HtmlTextWriter htmlWriter = null;   

            if (dtData != null)
            {
                curContext.Response.ContentType = "application/vnd.ms-excel";
                curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
                curContext.Response.Charset = "";
                strWriter = new StringWriter();
                htmlWriter = new HtmlTextWriter(strWriter);
                dgExport = new DataGrid();
                dgExport.DataSource = dtData.DefaultView;
                dgExport.AllowPaging = false;
                dgExport.DataBind();
                dgExport.RenderControl(htmlWriter);
                curContext.Response.Write(strWriter.ToString());
                curContext.Response.End();
            }
        }   

        /// <summary>
        /// 导出Excel文件,并自定义文件名
        /// </summary>
        public void DataTable3Excel(System.Data.DataTable dtData, String FileName)
        {
            GridView dgExport = null;
            HttpContext curContext = HttpContext.Current;
            StringWriter strWriter = null;
            HtmlTextWriter htmlWriter = null;   

            if (dtData != null)
            {
                HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8);
                curContext.Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName, System.Text.Encoding.UTF8) + ".xls");
                curContext.Response.ContentType = "application nd.ms-excel";
                curContext.Response.ContentEncoding = System.Text.Encoding.UTF8;
                curContext.Response.Charset = "GB2312";
                strWriter = new StringWriter();
                htmlWriter = new HtmlTextWriter(strWriter);
                dgExport = new GridView();
                dgExport.DataSource = dtData.DefaultView;
                dgExport.AllowPaging = false;
                dgExport.DataBind();
                dgExport.RenderControl(htmlWriter);
                curContext.Response.Write(strWriter.ToString());
                curContext.Response.End();
            }
        }   

        /// <summary>
        /// 将数据导出至Excel文件
        /// </summary>
        /// <param name="Table">DataTable对象</param>
        /// <param name="ExcelFilePath">Excel文件路径</param>
        public bool OutputToExcel(DataTable Table, string ExcelFilePath)
        {
            if (File.Exists(ExcelFilePath))
            {
                throw new Exception("该文件已经存在!");
            }   

            if ((Table.TableName.Trim().Length == 0) || (Table.TableName.ToLower() == "table"))
            {
                Table.TableName = "Sheet1";
            }   

            //数据表的列数
            int ColCount = Table.Columns.Count;   

            //用于记数,实例化参数时的序号
            int i = 0;   

            //创建参数
            OleDbParameter[] para = new OleDbParameter[ColCount];   

            //创建表结构的SQL语句
            string TableStructStr = @"Create Table " + Table.TableName + "(";   

            //连接字符串
            string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ExcelFilePath + ";Extended Properties=Excel 8.0;";
            OleDbConnection objConn = new OleDbConnection(connString);   

            //创建表结构
            OleDbCommand objCmd = new OleDbCommand();   

            //数据类型集合
            ArrayList DataTypeList = new ArrayList();
            DataTypeList.Add("System.Decimal");
            DataTypeList.Add("System.Double");
            DataTypeList.Add("System.Int16");
            DataTypeList.Add("System.Int32");
            DataTypeList.Add("System.Int64");
            DataTypeList.Add("System.Single");   

            //遍历数据表的所有列,用于创建表结构
            foreach (DataColumn col in Table.Columns)
            {
                //如果列属于数字列,则设置该列的数据类型为double
                if (DataTypeList.IndexOf(col.DataType.ToString()) >= 0)
                {
                    para[i] = new OleDbParameter("@" + col.ColumnName, OleDbType.Double);
                    objCmd.Parameters.Add(para[i]);   

                    //如果是最后一列
                    if (i + 1 == ColCount)
                    {
                        TableStructStr += col.ColumnName + " double)";
                    }
                    else
                    {
                        TableStructStr += col.ColumnName + " double,";
                    }
                }
                else
                {
                    para[i] = new OleDbParameter("@" + col.ColumnName, OleDbType.VarChar);
                    objCmd.Parameters.Add(para[i]);   

                    //如果是最后一列
                    if (i + 1 == ColCount)
                    {
                        TableStructStr += col.ColumnName + " varchar)";
                    }
                    else
                    {
                        TableStructStr += col.ColumnName + " varchar,";
                    }
                }
                i++;
            }   

            //创建Excel文件及文件结构
            try
            {
                objCmd.Connection = objConn;
                objCmd.CommandText = TableStructStr;   

                if (objConn.State == ConnectionState.Closed)
                {
                    objConn.Open();
                }
                objCmd.ExecuteNonQuery();
            }
            catch (Exception exp)
            {
                throw exp;
            }   

            //插入记录的SQL语句
            string InsertSql_1 = "Insert into " + Table.TableName + " (";
            string InsertSql_2 = " Values (";
            string InsertSql = "";   

            //遍历所有列,用于插入记录,在此创建插入记录的SQL语句
            for (int colID = 0; colID < ColCount; colID++)
            {
                if (colID + 1 == ColCount)  //最后一列
                {
                    InsertSql_1 += Table.Columns[colID].ColumnName + ")";
                    InsertSql_2 += "@" + Table.Columns[colID].ColumnName + ")";
                }
                else
                {
                    InsertSql_1 += Table.Columns[colID].ColumnName + ",";
                    InsertSql_2 += "@" + Table.Columns[colID].ColumnName + ",";
                }
            }   

            InsertSql = InsertSql_1 + InsertSql_2;   

            //遍历数据表的所有数据行
            for (int rowID = 0; rowID < Table.Rows.Count; rowID++)
            {
                for (int colID = 0; colID < ColCount; colID++)
                {
                    if (para[colID].DbType == DbType.Double && Table.Rows[rowID][colID].ToString().Trim() == "")
                    {
                        para[colID].Value = 0;
                    }
                    else
                    {
                        para[colID].Value = Table.Rows[rowID][colID].ToString().Trim();
                    }
                }
                try
                {
                    objCmd.CommandText = InsertSql;
                    objCmd.ExecuteNonQuery();
                }
                catch (Exception exp)
                {
                    string str = exp.Message;
                }
            }
            try
            {
                if (objConn.State == ConnectionState.Open)
                {
                    objConn.Close();
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return true;
        }   

        /// <summary>
        /// 将数据导出至Excel文件
        /// </summary>
        /// <param name="Table">DataTable对象</param>
        /// <param name="Columns">要导出的数据列集合</param>
        /// <param name="ExcelFilePath">Excel文件路径</param>
        public bool OutputToExcel(DataTable Table, ArrayList Columns, string ExcelFilePath)
        {
            if (File.Exists(ExcelFilePath))
            {
                throw new Exception("该文件已经存在!");
            }   

            //如果数据列数大于表的列数,取数据表的所有列
            if (Columns.Count > Table.Columns.Count)
            {
                for (int s = Table.Columns.Count + 1; s <= Columns.Count; s++)
                {
                    Columns.RemoveAt(s);   //移除数据表列数后的所有列
                }
            }   

            //遍历所有的数据列,如果有数据列的数据类型不是 DataColumn,则将它移除
            DataColumn column = new DataColumn();
            for (int j = 0; j < Columns.Count; j++)
            {
                try
                {
                    column = (DataColumn)Columns[j];
                }
                catch (Exception)
                {
                    Columns.RemoveAt(j);
                }
            }
            if ((Table.TableName.Trim().Length == 0) || (Table.TableName.ToLower() == "table"))
            {
                Table.TableName = "Sheet1";
            }   

            //数据表的列数
            int ColCount = Columns.Count;   

            //创建参数
            OleDbParameter[] para = new OleDbParameter[ColCount];   

            //创建表结构的SQL语句
            string TableStructStr = @"Create Table " + Table.TableName + "(";   

            //连接字符串
            string connString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + ExcelFilePath + ";Extended Properties=Excel 8.0;";
            OleDbConnection objConn = new OleDbConnection(connString);   

            //创建表结构
            OleDbCommand objCmd = new OleDbCommand();   

            //数据类型集合
            ArrayList DataTypeList = new ArrayList();
            DataTypeList.Add("System.Decimal");
            DataTypeList.Add("System.Double");
            DataTypeList.Add("System.Int16");
            DataTypeList.Add("System.Int32");
            DataTypeList.Add("System.Int64");
            DataTypeList.Add("System.Single");   

            DataColumn col = new DataColumn();   

            //遍历数据表的所有列,用于创建表结构
            for (int k = 0; k < ColCount; k++)
            {
                col = (DataColumn)Columns[k];   

                //列的数据类型是数字型
                if (DataTypeList.IndexOf(col.DataType.ToString().Trim()) >= 0)
                {
                    para[k] = new OleDbParameter("@" + col.Caption.Trim(), OleDbType.Double);
                    objCmd.Parameters.Add(para[k]);   

                    //如果是最后一列
                    if (k + 1 == ColCount)
                    {
                        TableStructStr += col.Caption.Trim() + " Double)";
                    }
                    else
                    {
                        TableStructStr += col.Caption.Trim() + " Double,";
                    }
                }
                else
                {
                    para[k] = new OleDbParameter("@" + col.Caption.Trim(), OleDbType.VarChar);
                    objCmd.Parameters.Add(para[k]);   

                    //如果是最后一列
                    if (k + 1 == ColCount)
                    {
                        TableStructStr += col.Caption.Trim() + " VarChar)";
                    }
                    else
                    {
                        TableStructStr += col.Caption.Trim() + " VarChar,";
                    }
                }
            }   

            //创建Excel文件及文件结构
            try
            {
                objCmd.Connection = objConn;
                objCmd.CommandText = TableStructStr;   

                if (objConn.State == ConnectionState.Closed)
                {
                    objConn.Open();
                }
                objCmd.ExecuteNonQuery();
            }
            catch (Exception exp)
            {
                throw exp;
            }   

            //插入记录的SQL语句
            string InsertSql_1 = "Insert into " + Table.TableName + " (";
            string InsertSql_2 = " Values (";
            string InsertSql = "";   

            //遍历所有列,用于插入记录,在此创建插入记录的SQL语句
            for (int colID = 0; colID < ColCount; colID++)
            {
                if (colID + 1 == ColCount)  //最后一列
                {
                    InsertSql_1 += Columns[colID].ToString().Trim() + ")";
                    InsertSql_2 += "@" + Columns[colID].ToString().Trim() + ")";
                }
                else
                {
                    InsertSql_1 += Columns[colID].ToString().Trim() + ",";
                    InsertSql_2 += "@" + Columns[colID].ToString().Trim() + ",";
                }
            }   

            InsertSql = InsertSql_1 + InsertSql_2;   

            //遍历数据表的所有数据行
            DataColumn DataCol = new DataColumn();
            for (int rowID = 0; rowID < Table.Rows.Count; rowID++)
            {
                for (int colID = 0; colID < ColCount; colID++)
                {
                    //因为列不连续,所以在取得单元格时不能用行列编号,列需得用列的名称
                    DataCol = (DataColumn)Columns[colID];
                    if (para[colID].DbType == DbType.Double && Table.Rows[rowID][DataCol.Caption].ToString().Trim() == "")
                    {
                        para[colID].Value = 0;
                    }
                    else
                    {
                        para[colID].Value = Table.Rows[rowID][DataCol.Caption].ToString().Trim();
                    }
                }
                try
                {
                    objCmd.CommandText = InsertSql;
                    objCmd.ExecuteNonQuery();
                }
                catch (Exception exp)
                {
                    string str = exp.Message;
                }
            }
            try
            {
                if (objConn.State == ConnectionState.Open)
                {
                    objConn.Close();
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }
            return true;
        }
        #endregion   

        /// <summary>
        /// 获取Excel文件数据表列表
        /// </summary>
        public ArrayList GetExcelTables(string ExcelFileName)
        {
            DataTable dt = new DataTable();
            ArrayList TablesList = new ArrayList();
            if (File.Exists(ExcelFileName))
            {
                string com = GetCom(ExcelFileName);
                using (OleDbConnection conn = new OleDbConnection(com))
                {
                    try
                    {
                        conn.Open();
                        dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" });
                    }
                    catch (Exception exp)
                    {
                        throw exp;
                    }   

                    //获取数据表个数
                    int tablecount = dt.Rows.Count;
                    for (int i = 0; i < tablecount; i++)
                    {
                        string tablename = dt.Rows[i][2].ToString().Trim().TrimEnd(‘$‘);
                        if (TablesList.IndexOf(tablename) < 0)
                        {
                            TablesList.Add(tablename);
                        }
                    }
                }
            }
            return TablesList;
        }   

        /// <summary>
        /// 将Excel文件导出至DataTable(第一行作为表头)
        /// </summary>
        /// <param name="ExcelFilePath">Excel文件路径</param>
        /// <param name="TableName">数据表名,如果数据表名错误,默认为第一个数据表名</param>
        public DataTable InputFromExcel(string ExcelFilePath, string TableName)
        {
            if (!File.Exists(ExcelFilePath))
            {
                throw new Exception("Excel文件不存在!");
            }   

            //如果数据表名不存在,则数据表名为Excel文件的第一个数据表
            ArrayList TableList = new ArrayList();
            TableList = GetExcelTables(ExcelFilePath);   

            if (TableName.IndexOf(TableName) < 0)
            {
                TableName = TableList[0].ToString().Trim();
            }   

            string com = GetCom(ExcelFilePath);   

            DataTable table = new DataTable();
            OleDbConnection dbcon = new OleDbConnection(com);
            OleDbCommand cmd = new OleDbCommand("select * from [" + TableName + "$]", dbcon);
            OleDbDataAdapter adapter = new OleDbDataAdapter(cmd);   

            try
            {
                if (dbcon.State == ConnectionState.Closed)
                {
                    dbcon.Open();
                }
                adapter.Fill(table);
            }
            catch (Exception exp)
            {
                throw exp;
            }
            finally
            {
                if (dbcon.State == ConnectionState.Open)
                {
                    dbcon.Close();
                }
            }
            return table;
        }   

        /// <summary>
        /// 获取Excel文件指定数据表的数据列表
        /// </summary>
        /// <param name="ExcelFileName">Excel文件名</param>
        /// <param name="TableName">数据表名</param>
        public ArrayList GetExcelTableColumns(string ExcelFileName, string TableName)
        {
            DataTable dt = new DataTable();
            ArrayList ColsList = new ArrayList();
            if (File.Exists(ExcelFileName))
            {
                using (OleDbConnection conn = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" + ExcelFileName))
                {
                    conn.Open();
                    dt = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, TableName, null });   

                    //获取列个数
                    int colcount = dt.Rows.Count;
                    for (int i = 0; i < colcount; i++)
                    {
                        string colname = dt.Rows[i]["Column_Name"].ToString().Trim();
                        ColsList.Add(colname);
                    }
                }
            }
            return ColsList;
        }   

        public string GetCom(string ExcelFilePath)
        {
            string com = null;
            if (ExcelFilePath.Substring(ExcelFilePath.LastIndexOf(‘.‘)) == ".xls")
            {
                com = "Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties=Excel 8.0;Data Source=" + ExcelFilePath;
            }
            else
            {
                com = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + ExcelFilePath + ";Extended Properties=‘Excel 12.0 Xml;HDR=YES;‘";
            }
            return com;
        }
    }  
时间: 2024-11-06 03:30:35

Asp.net 导入Excel的相关文章

ASP.NET 导入EXCEl文档

鉴于教务一般都是手动输入学生信息,在未了解本校数据库的客观情况之下,我们准备设计一个导入excel文档中学生信息如数据库的功能.结合网上各类大牛的综合版本出炉.. 首先具体的实现思想如下: 1.先使用FileUpload控件fuload将Excel文件上传到服务器上得某一个文件夹. 2.使用OleDb将已经上传到服务器上的Excel文件读出来,这里将Excel文件当做一个数据库来读.在联系数据库语句中,Data Source就是该文件在服务器上得物理路径 3.将第二步中读出的数据以DataTab

ASP.NETCore -----导入Excel文件

前端上传excel文件利用npoi读取数据转换成datatable(netcore坑爹啊,用的vs2017竟然不能可视化) 前端界面 @{ Layout = null; } <!DOCTYPE html> <html> <head> <meta name="viewport" content="width=device-width" /> <title>Xlsx</title> </hea

Asp.Net 导入Excel表格

前台页面: <div align="center" style="background-color:Beige"> <table style="width: 576px; border-collapse: separate; text-align: center"> <tr><td>Excel导入SQL数据库</td></tr> <tr> <td style

ASP.NET——导入Excel数据

原文:http://www.cnblogs.com/xiaopin/archive/2011/03/31/2001199.html 本代码目前只支持xls文件,不支持xlsx文件. protected void btnImport_Click(object sender, EventArgs e)    {        if (FileUpload1.HasFile == false)//HasFile用来检查FileUpload是否有指定文件        {            Resp

Ajax asp.net 导入Excel

首先使用ajax以POST的方式提交excel文件: $("#btnUploadExcelSave").click(function () { var fileObj = document.getElementById("file").files[0]; // js 获取文件对象 var FileController = "../FileHandler.ashx?type=3"; // 接收上传文件的后台地址 // FormData 对象 var

C#,Asp.NET 导入Excel,时间格式一串数字转换.

在Excel中.日期或者时间格式为:42093.6506944444 或者 0.650694444444444 大于0 表示有日期(2015-03-30),小于零则是时间(15:37) 在C# 导入读取这列时,转换会发生错误; 现在将这格式转换为正常的日期格式:如下 1 /// <summary> 2 /// 数字转换时间格式 3 /// </summary> 4 /// <param name="timeStr">数字,如:42095.706944

Asp.NET MVC 导入Excel数据教程 手把手教你系列!!!

先上效果图 1.引言 小弟最近接了个大学生的毕业设计,收了100块钱让做一个ASP.NET MVC导入Excel到数据库的功能,由于以前没做过就到处搜索资料,但是发现网上的资料不是直接贴一大堆乱起八遭的源码,就是需要借用NPOI第三方类库太麻烦了,况且预算才100RMB简直不值得,所以小弟尝试自己动手丰衣足食,所以就有了这篇博客. 先上一张小弟的思路图: (说明:没有安装做流程图的软件!凑合着看吧) 2 进入正题 首先跟着小弟先创建一个默认的MVC项目(相信大家都会创建,这里就不演示了) 第一步

asp.net采用OLEDB方式导入Excel数据时提示:未在本地计算机上注册&quot;Microsoft.Jet.OLEDB.4.0&quot; 提供程序&quot;

asp.net采用OLEDB方式导入Excel数据时提示:未在本地计算机上注册"Microsoft.Jet.OLEDB.4.0" 提供程序" 笔者在项目中做做了一个从Excel表格中导入数据的模块.大体上asp.net项目中导入Excel大体分成三类: 1)采用c#内置方案System.Data.OleDb(限制较小, 通用) 2)采用Excel的COM组件(会有版本问题) 3)采用伪Excel文件.即使用文本流的方式根据需求自己定义数据格式.同时在服务端进行反格式化 笔者采

ASP.NET写一个导入EXCEL ,错误调整方式

这两天用ASP.NET写一个导入EXCEL数据到ORACLE的程序,调试通过,但是部署到服务器上就不能用了. Retrieving the COM class factory for component with CLSID {00024500-0000-000 后来终于解决: 在服务器上, 1,运行dcomcnfg打开组件服务 2,依次展开"组件服务"->"计算机"->"我的电脑"->"DCOM配置" 3,