Exemplo n.º 1
0
    /// <summary>
    /// 转换Excel文件
    /// </summary>
    private static void Convert()
    {
        //删除旧的文件
        //输出类型
        string outpath = Application.dataPath + LanguageSettings.OUTPUT_PATH;

        if (Directory.Exists(outpath))
        {
            DirectoryInfo direction = new DirectoryInfo(outpath);
            FileInfo[]    files     = direction.GetFiles("*", SearchOption.AllDirectories);

            for (int i = 0; i < files.Length; i++)
            {
                if (files [i].Name.EndsWith(".txt"))
                {
                    FileUtil.DeleteFileOrDirectory(files [i].ToString());
                }
            }
        }


        foreach (LanguageConfig lc in excelList)
        {
            //获取Excel文件的绝对路径
            string excelPath = pathRoot + LanguageSettings.INPUT_PATH + lc.GetTableName();
            //构造Excel工具类
            ExcelUtility excel = new ExcelUtility(excelPath);
            //编码类型
            Encoding encoding = Encoding.GetEncoding("utf-8");


            excel.ConvertToTXT(outpath, encoding, lc);

            //判断是否保留源文件
            if (!keepSource)
            {
                FileUtil.DeleteFileOrDirectory(excelPath);
            }

            //刷新本地资源
            AssetDatabase.Refresh();
        }

        //转换完后关闭插件
        //这样做是为了解决窗口
        //再次点击时路径错误的Bug
        instance.Close();
    }