Example #1
0
    // 加载指定路径的表格;
    public static void LoadExcel(string className, string fileName)
    {
#if UNITY_EDITOR
        TextAsset textAsset = UnityEditor.AssetDatabase.LoadAssetAtPath <TextAsset>(fileName);
#else
        TextAsset textAsset = Resources.Load <TextAsset>(fileName);
#endif
        if (textAsset == null)
        {
            Debug.LogError(fileName + "加载失败");
            return;
        }

        string excelContent = textAsset.text;
        if (string.IsNullOrEmpty(excelContent))
        {
            //Debug.Log("loadfile=" + fileName);
            using (StringReader reader = new StringReader(excelContent))
            {
                // 表头;
                string lineData = reader.ReadLine();

                while (!string.IsNullOrEmpty(lineData))
                {
                    lineData = reader.ReadLine();
                    if (!string.IsNullOrEmpty(lineData))
                    {
                        string[] datas = lineData.Split(Separators, StringSplitOptions.None); // 不移除空格子

                        var line = ExcelFactory.InitExcelLine(className, datas);
                    }
                }
            }
        }
    }