Example #1
0
 public static string[] SheetNames(string fileName)
 {
     var rval = new List<string>();
     ExcelUtility xls = new ExcelUtility(fileName);
     foreach (DataTable item in xls.Workbook.Tables)
     {
         rval.Add(item.TableName);
     }
     return rval.ToArray();
 }
Example #2
0
        /// <summary>
        /// loads spreadsheet from disk or gets a referecne to cached refererence
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static DataSet GetWorkbookReference(string filename)
        {
            DataSet      workbook = null;
            ExcelUtility xls      = null;

            if (s_cache.ContainsKey(filename))
            { // allready in memory.
                Logger.WriteLine("Found file in cache: " + Path.GetFileName(filename));
                xls      = s_cache[filename];
                workbook = xls.Workbook;
                FileInfo fi = new FileInfo(filename);

                if (fi.LastWriteTime > xls.LastWriteTime)
                {
                    Logger.WriteLine("xls File has changed... updating cache");
                    xls               = new ExcelUtility(filename);
                    workbook          = xls.Workbook;
                    s_cache[filename] = xls;
                }
            }
            else
            {
                Logger.WriteLine("reading file from disk: " + Path.GetFileName(filename));
                if (!File.Exists(filename))
                {
                    Logger.WriteLine("File does not exist: '" + filename + "'");
                }
                xls      = new ExcelUtility(filename);
                workbook = xls.Workbook;

                int max_cache_size = 10;
                if (s_cache.Count >= max_cache_size)
                {
                    s_cache.Clear();
                    Logger.WriteLine(" s_cache.Clear()");
                }
                s_cache.Add(filename, xls);
            }
            return(workbook);
        }
Example #3
0
        /// <summary>
        /// loads spreadsheet from disk or gets a reference to cached refererence
        /// </summary>
        /// <param name="filename"></param>
        /// <returns></returns>
        public static DataSet GetWorkbookReference(string filename)
        {
            DataSet workbook = null;
            ExcelUtility xls = null;
            if (s_cache.ContainsKey(filename))
            { // allready in memory.
                Logger.WriteLine("Found file in cache: " + Path.GetFileName(filename));
                xls = s_cache[filename];
                workbook = xls.Workbook;
                FileInfo fi = new FileInfo(filename);

                if (fi.LastWriteTime > xls.LastWriteTime)
                {
                    Logger.WriteLine("xls File has changed... updating cache");
                    xls = new ExcelUtility(filename);
                    workbook = xls.Workbook;
                    s_cache[filename] = xls;
                }
            }
            else
            {
                Logger.WriteLine("reading file from disk: " + Path.GetFileName(filename));
                if (!File.Exists(filename))
                {
                    Logger.WriteLine("File does not exist: '" + filename + "'");
                }
                xls = new ExcelUtility(filename);
                workbook = xls.Workbook;

                int max_cache_size = 10;
                if (s_cache.Count >= max_cache_size)
                {
                    s_cache.Clear();
                    Logger.WriteLine(" s_cache.Clear()");
                }
                s_cache.Add(filename, xls);
            }
            return workbook;
        }
Example #4
0
 public static string[] SheetNames(string fileName)
 {
     var rval = new List<string>();
     ExcelUtility xls = new ExcelUtility(fileName);
     foreach (DataTable item in xls.Workbook.Tables)
     {
         rval.Add(item.TableName);
     }
     return rval.ToArray();
 }