ASP.NET 导入Excel数据,量大时,导入慢的有关问题

ASP.NET 导入Excel数据,量大时,导入慢的问题?
本帖最后由 bbsstrange 于 2014-08-15 14:09:32 编辑
以下是我的导入代码,当Excel数据为1000条时,导入就要20秒,请问下面写法有什么改进,能让时间缩短?求高手解答?

try
            {
                string fileName = excelUploadUrl;
                Microsoft.Office.Interop.Excel.Application excel = new Microsoft.Office.Interop.Excel.Application();
                object oMissing = System.Reflection.Missing.Value;
                excel.Application.Workbooks.Open(fileName, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing, oMissing);
                Microsoft.Office.Interop.Excel.Workbook book = excel.Workbooks[1];
                Microsoft.Office.Interop.Excel.Worksheet sheet = (Microsoft.Office.Interop.Excel.Worksheet)excel.Worksheets[1];

                string strSheetName = sheet.Name;
                string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = " + fileName + ";Extended Properties ='Excel 8.0;HDR=NO;IMEX=1'";
                string strExcel = "select * from  [" + strSheetName + "$]";
                DataSet ds = new DataSet();
                OleDbConnection conn = new OleDbConnection(strConn);
                conn.Open();
                OleDbDataAdapter adapter = new OleDbDataAdapter(strExcel, conn);
                adapter.Fill(ds);
                DataRow[] dr = ds.Tables[0].Select();
                int ss = ds.Tables[0].Rows.Count;
                int rowsnum = ds.Tables[0].Rows.Count;
                if (rowsnum == 0)
                {
                    return Json(new OperateReturnInfo(OperateCodeEnum.Failed, "导入失败!Excel表为空表,无数据!"), JsonRequestBehavior.AllowGet);
                }
                //检查门店编码是否存在
                bool IsExist = false;
                for (int i = 1; i < rowsnum; i++)
                {
                    bool result = StoreIPManager.CheckStoreCode(dr[i][0].ToString());
                    if (result)
                    {
                        IsExist = true;
                        return Json(new OperateReturnInfo(OperateCodeEnum.Failed, "导入失败!门店编码'" + dr[i][0].ToString() + "'已经存在,请修改后再重新导入!"), JsonRequestBehavior.AllowGet);
                    }
                }
                //全部核查通过,执行插入数据库
                if (!IsExist)
                {