Esempio n. 1
0
        public bool Init(string filePath)
        {
            try
            {
                System.IO.FileStream fs = System.IO.File.OpenRead(filePath);
                if (fs == null)
                {
                    return(false);
                }

                Workbook = new HSSFWorkbook(fs);
                HSSFSheet sheet = (HSSFSheet)Workbook.GetSheet("MainSheet");

                var row = sheet.GetRow(0);
                for (int j = 0; j < row.LastCellNum; j++)
                {
                    var cell = row.GetCell(j);

                    var bd = new ExcelBinder();
                    bd.Sheet  = sheet;
                    bd.Name   = cell.StringCellValue;
                    bd.Column = j;
                    Binder.Add(bd.Name, bd);
                }
            }
            catch (Exception ex)
            {
                EngineNS.Profiler.Log.WriteException(ex);
                return(false);
            }
            return(true);
        }
Esempio n. 2
0
        public bool Init(string filePath, System.Type type)
        {
            try
            {
                try
                {
                    if (CEngine.Instance.FileManager.FileExists(filePath))
                    {
                        System.IO.FileStream fs = System.IO.File.OpenRead(filePath);
                        if (fs != null)
                        {
                            Workbook = new HSSFWorkbook(fs);
                        }
                    }
                }
                catch
                {
                }
                HSSFSheet sheet = GetSheetSure("MainSheet");
                var       row   = InitSheet(sheet, type);

                for (int j = 1; j < row.LastCellNum; j++)
                {
                    var cell = row.GetCell(j);

                    var bd = new ExcelBinder();
                    bd.Sheet  = sheet;
                    bd.Name   = cell.StringCellValue;
                    bd.Column = j;
                    Binder.Add(bd.Name, bd);
                }
            }
            catch (Exception ex)
            {
                EngineNS.Profiler.Log.WriteException(ex);
                return(false);
            }
            return(true);
        }