Exemplo n.º 1
0
 public static ExcelManager Instance()
 {
     if (null == ms_handle)
     {
         ms_handle = new ExcelManager();
     }
     return(ms_handle);
 }
Exemplo n.º 2
0
        public static void _ConvertTable(object param)
        {
            while (true)
            {
                ConvertParams curParam = null;
                int           iNum     = 0;
                lock (param)
                {
                    var contents = param as List <ConvertParams>;
                    if (null != contents && contents.Count > 0)
                    {
                        curParam = contents [0];
                        contents.RemoveAt(0);
                    }
                }

                if (null == curParam)
                {
                    break;
                }

                if (ExcelManager.Instance().Convert(curParam.applicationPath, curParam.name, curParam.eConvertType))
                {
                    lock (param)
                    {
                        iNum = ++ms_num;
                    }
                    Debug.LogFormat("[npoi] convert [{0}/{1}] <color=#00ff00>{2}</color> ok !!!", iNum, curParam.sum, curParam.name);
                }
                else
                {
                    lock (param)
                    {
                        iNum = ++ms_num;
                    }
                    Debug.LogErrorFormat("[npoi] convert [{0}/{1}] <color=#ffff00>{2}</color> failed !!!", iNum, curParam.sum, curParam.name);
                }

                if (iNum == curParam.sum)
                {
                    _OnConvertDone();
                }
            }
        }
Exemplo n.º 3
0
        protected void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("过滤器", GUILayout.Width(100));
            filter = EditorGUILayout.TextField(filter, GUILayout.Width(100));
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("刷新", GUILayout.Width(100)))
            {
                _ListAllExcelFiles();
            }
            if (GUILayout.Button("全选", GUILayout.Width(100)))
            {
                for (int i = 0; i < fileNames.Count; ++i)
                {
                    fileNames [i].bSelected = true;
                }
            }
            if (GUILayout.Button("反选", GUILayout.Width(100)))
            {
                for (int i = 0; i < fileNames.Count; ++i)
                {
                    fileNames [i].bSelected = !fileNames[i].bSelected;
                }
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("转表-PROTO", GUILayout.Width(100)))
            {
                for (int i = 0; i < fileNames.Count; ++i)
                {
                    if (fileNames [i].bSelected)
                    {
                        if (ExcelManager.Instance().Convert(Application.dataPath, fileNames [i].name, ExcelHelper.ConvertType.CT_PROTO))
                        {
                            UnityEngine.Debug.LogFormat("<color=#00ff00>convert <color=#ffff00>{0}.proto</color> succeed !!</color>", fileNames [i].name);
                        }
                        else
                        {
                            UnityEngine.Debug.LogFormat("<color=#ff0000>convert <color=#ffff00>{0}.proto</color> succeed !!</color>", fileNames [i].name);
                        }
                    }
                }
            }
            if (GUILayout.Button("转表-CS", GUILayout.Width(100)))
            {
                for (int i = 0; i < fileNames.Count; ++i)
                {
                    if (fileNames [i].bSelected)
                    {
                        var dir       = Path.GetFullPath(Application.dataPath + ExcelConfig.XLSX_PATH + fileNames [i].name + ".xls");
                        var excelUnit = new ExcelUnit(dir);
                        excelUnit.Init();
                        if (excelUnit.succeed)
                        {
                            string proto_path = Path.GetFullPath(Application.dataPath + ExcelConfig.PROTO_PATH + excelUnit.SheetName + ".proto");
                            string out_path   = Path.GetFullPath(Application.dataPath + ExcelConfig.TABLE_SCRIPTS_PATH + excelUnit.SheetName + ".cs");
                            string ccode_path = Path.GetFullPath(Application.dataPath + ExcelConfig.TABLE_SCRIPTS_CCODE_PATH + excelUnit.SheetName + ".cc");

                            ProtoBuf.CodeGenerator.CommandLineOptions.BuildXsxl2Cs(proto_path, out_path, ccode_path);
                        }
                        else
                        {
                            UnityEngine.Debug.LogErrorFormat("表{0}转cs文件失败!", fileNames [i]);
                        }
                        excelUnit.Close();
                    }
                }
            }
            if (GUILayout.Button("转表-TXT", GUILayout.Width(100)))
            {
                for (int i = 0; i < fileNames.Count; ++i)
                {
                    if (fileNames [i].bSelected)
                    {
                        var dir       = Path.GetFullPath(Application.dataPath + ExcelConfig.XLSX_PATH + fileNames [i].name + ".xls");
                        var excelUnit = new ExcelUnit(dir);
                        excelUnit.Init();
                        excelUnit.LoadProtoBase();
                        excelUnit.generateText(Application.dataPath);
                        if (excelUnit.succeed)
                        {
                            UnityEngine.Debug.LogFormat("<color=#00ff00>convert <color=#ffff00>{0}.txt</color> succeed !!</color>", excelUnit.SheetName);
                            ExcelHelper.ConvertAsset(excelUnit.SheetName + ".txt");
                        }
                        else
                        {
                            UnityEngine.Debug.LogFormat("<color=#ff0000>convert <color=#ffff00>{0}.txt</color> succeed !!</color>", excelUnit.SheetName);
                        }
                        var txtPath = Path.GetFullPath(Application.dataPath + ExcelConfig.TXT_SAVE_PATH + excelUnit.SheetName + ".txt");
                        if (File.Exists(txtPath))
                        {
                            File.Delete(txtPath);
                        }
                        excelUnit.Close();
                    }
                }
            }
            EditorGUILayout.EndHorizontal();

            //excel-table-name
            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);
            EditorGUILayout.BeginVertical();
            var defColor = GUI.color;

            for (int i = 0; i < fileNames.Count; ++i)
            {
                if (fileNames [i].name.StartsWith(filter))
                {
                    EditorGUILayout.BeginHorizontal();
                    if (i % 2 == 0)
                    {
                        GUI.color = Color.yellow;
                    }
                    else
                    {
                        GUI.color = Color.cyan;
                    }
                    EditorGUILayout.LabelField(fileNames [i].name);
                    fileNames [i].bSelected = EditorGUILayout.Toggle(fileNames [i].bSelected);
                    EditorGUILayout.EndHorizontal();
                }
            }
            GUI.color = defColor;
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }