Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);
            var    excelToJson = new ExcelToJson();
            string json        = excelToJson.OpenExcelAndToJson("../../../Res/Examples/ExampleData.xlsx");

            Console.WriteLine(json);
        }
Ejemplo n.º 2
0
 private static void Init()
 {
     instance  = GetWindow <ExcelToJson>();
     pathRoot  = Application.dataPath;
     pathRoot  = pathRoot.Substring(0, pathRoot.LastIndexOf("/"));
     excelList = new List <string>();
     scrollPos = new Vector2(instance.position.x, instance.position.y + 75);
 }
Ejemplo n.º 3
0
    static void DisplayerExcelToJsonWindow()
    {
        ExcelToJson excelToJsonWindow = EditorWindow.GetWindow <ExcelToJson>();//获取窗口对象

        excelToJsonWindow.Show();

        // 读取目录
        ExcelObj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(defaultExcelPath);

        // 初始化输出目录
        UnityEngine.Object outputObj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(defaultJsonPath);
        if (outputObj == null)
        {
            int endIndex = defaultJsonPath.LastIndexOf("/");
            AssetDatabase.CreateFolder(defaultJsonPath.Substring(0, endIndex), defaultJsonPath.Substring(endIndex + 1));
            outputObj = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(defaultJsonPath);
        }
        OutputDirectory = AssetDatabase.LoadAssetAtPath <UnityEngine.Object>(defaultJsonPath);
    }
Ejemplo n.º 4
0
    /// <summary>
    /// 生成对应的CS文件
    /// </summary>
    void LoadCSVToCS()
    {
        foreach (string VARIABLE in ListOfFiles)
        {
            string        result   = Utility.LoacCSV(FilesPath + VARIABLE);
            string        FileName = VARIABLE.Remove(VARIABLE.Length - 4);
            List <string> CaseList = new List <string>();
            string[,] CSVresult = Utility.SplitCsvGrid(result);
            Utility.DebugOutputGrid(CSVresult);
            for (int i = 0; i < CSVresult.GetUpperBound(0) - 1; i++)
            {
                string ProPertyname   = CSVresult[i, 0];
                string ProPerty       = CSVresult[i, 1];
                string ProPertyString = "public {1} {0} __LK__ get; set; __RK__ ";
                CaseList.Add("/// <summary>");
                CaseList.Add("///" + ProPertyname);
                CaseList.Add("/// <summary>");
                CaseList.Add(string.Format(ProPertyString, ProPerty, "string"));
            }
            string CaseCode = string.Join("\r\n    ", CaseList.ToArray());
            string code     = string.Format(BEHAVIOUR_FORMAT, FileName, CaseCode);
            code = code.Replace("__LK__", "{");
            code = code.Replace("__RK__", "}");
            string path = Application.dataPath + UIVIEW_PATH;

            string behaviourCodeFile = Path.Combine(path, FileName) + ".cs";


            Utility.SaveStringToFile(behaviourCodeFile, code);

            AssetDatabase.SaveAssets();
            AssetDatabase.Refresh();
        }

        ExcelToJson.excelToJson();
    }