示例#1
0
        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            DbConfigManager manager = new DbConfigManagerImpl();

            switch (dbOperation)
            {
            case Constant.DB_INSERT_STUDENT_DATA:
                e.Result = manager.insertStudentData(Utility.readExcel(filePath, dbOperation));
                break;

            case Constant.DB_UPDATE_STUDENT_DATA:
                e.Result = manager.updateStudentData(Utility.readExcel(filePath, dbOperation));
                break;
            }
        }
示例#2
0
        public static IList <Object> readExcel(string filePath, int operation)
        {
            Excel.Application xlApp       = null;
            Excel.Workbook    xlWorkBook  = null;
            Excel.Worksheet   xlWorkSheet = null;;
            Excel.Range       xlRange;
            IList <Object>    dataList = null;

            try
            {
                xlApp = new Excel.Application();
                xlApp.IgnoreRemoteRequests = false;
                xlWorkBook = xlApp.Workbooks.Open(filePath,// 0, true, 5, "", "", true, Microsoft.Office.Interop.Excel.XlPlatform.xlWindows, "\t", false, false, 0, true, 1, 0);
                                                  Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing,
                                                  Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);

                xlWorkSheet = (Excel.Worksheet)xlWorkBook.Worksheets.get_Item(1);
                xlRange     = xlWorkSheet.UsedRange;

                DbConfigManager dbManager = new DbConfigManagerImpl();
                dataList = dbManager.getListFromExcel(xlRange, operation);

                xlWorkBook.Close(false, filePath, null);
                xlApp.Quit();
            }
            catch (Exception ex)
            {
                logFile("Utility : readExcel:: " + ex.Message, ex, Constant.LOGTYPE_ERROR);
                dataList = null;
            }
            finally
            {
                releaseCOMObj(xlWorkSheet);
                releaseCOMObj(xlWorkBook);
                releaseCOMObj(xlApp);

                //    killProcess("EXCEL");
            }
            return(dataList);
        }