Esempio n. 1
0
        /// <summary>
        /// 获取所有的xlsx文件
        /// </summary>
        /// <returns></returns>
        public static List <string> GetAllExcelFiles(string exceltype = "*.xlsx")
        {
            List <string> tablePathList = new List <string>();

            foreach (var path in Directory.GetDirectories("Assets", "*", SearchOption.TopDirectoryOnly))
            {
                var tablePath = IPath.Combine(path, EXCEL_PATH); //  + "/";
                if (!Directory.Exists(tablePath))
                {
                    continue;
                }

                tablePathList.Add(tablePath);
            }

            //寻找所有的excel文件
            List <string> xlslFiles = new List <string>();

            foreach (var r in tablePathList)
            {
                var fs = Directory.GetFiles(r, exceltype, SearchOption.AllDirectories);
                xlslFiles.AddRange(fs);
            }

            for (int i = 0; i < xlslFiles.Count; i++)
            {
                xlslFiles[i] = IPath.FormatPathOnUnity3d(xlslFiles[i]);
            }

            return(xlslFiles);
        }
Esempio n. 2
0
        /// <summary>
        /// excel导出sqlite
        /// 需要主动连接数据库
        /// </summary>
        /// <param name="filePath"></param>
        public static void Excel2SQLite(string filePath, DBType dbType)
        {
            filePath = IPath.FormatPathOnUnity3d(filePath); //.Replace("\\", "/").ToLower();
            //收集所有的类型
            CollectTableTypes();
            //
            var excelHash = FileHelper.GetMurmurHash3(filePath);

            //table判断
            SqliteHelper.DB.Connection.CreateTable <ImportExcelLog>();

            var table     = SqliteHelper.DB.GetTable <ImportExcelLog>();
            var importLog = table?.Where((ie) => ie.Path == filePath).FirstOrDefault();

            if (importLog == null || !importLog.Hash.Equals(excelHash))
            {
                //开始导表
                var excel = new ExcelExchangeTools(filePath);
                var json  = excel.GetJson(dbType);
                try
                {
                    Json2Sqlite(filePath, json);
                }
                catch (Exception e)
                {
                    Debug.LogError(e);
                    EditorUtility.ClearProgressBar();
                }

                //插入新版本数据
                if (importLog == null)
                {
                    importLog      = new ImportExcelLog();
                    importLog.Path = filePath;
                    importLog.Hash = excelHash;
                    importLog.Date = DateTime.Now.ToString("yyyyMMdd HH:mm:ss");
                    ;
                    importLog.UnityVersion = Application.unityVersion;
                    SqliteHelper.DB.Insert(importLog);
                }
                else
                {
                    importLog.Hash = excelHash;
                    importLog.Date = DateTime.Now.ToString();
                    ;
                    importLog.UnityVersion = Application.unityVersion;
                    SqliteHelper.DB.Connection.Update(importLog);
                }
            }
            else
            {
                Debug.Log($"<color=green>【Excel2Sql】内容一致,无需导入 {Path.GetFileName(filePath)} - Hash :{excelHash} </color>");
            }
        }