예제 #1
0
    public static Excel Parse(string file)
    {
        ISheet sheet = GetMainSheet(file);

        if (sheet != null)
        {
            Excel excel = new Excel(sheet);
            excel.path          = file;
            excel.isServerTable = ExcelParserFileHelper.IsServer(file);
            excel.SetTableName(file);
            excel.ParsePropertyInfos();
            excel.ParseExcelContents();
            return(excel);
        }
        return(null);
    }
예제 #2
0
 private LuaTableData InitLuaTableData(string excelpath)
 {
     if (!_lTableDataDic.ContainsKey(excelpath))
     {
         LuaTableData ltd = new LuaTableData
         {
             tableDiffs = new List <tablediff>()
         };
         #region 对比md5,看是否需要重新生成LocalLuaTable llt
         string tablename = string.Format("Table_{0}", Path.GetFileNameWithoutExtension(excelpath));
         string slltpath  = GetLocalServerLuaPath(tablename);
         string clltpath  = GetLocalClientLuaPath(excelpath);
         string md5       = ExcelParserFileHelper.GetMD5HashFromFile(excelpath);
         bool   isServer  = ExcelParserFileHelper.IsServer(excelpath);
         if (md5 == null)
         {
             return(null);
         }
         if (!File.Exists(slltpath) || md5 != ReadTableMD5(slltpath) ||
             (!isServer && (!File.Exists(clltpath) || md5 != ReadTableMD5(clltpath))))
         {
             if (!ExcelParser.ReGenLuaTable(excelpath))
             {
                 return(null);
             }
         }
         #endregion
         try
         {
             ltd.tables[0] = parse(slltpath, excelpath);
         }
         catch (LuaTableException ex) /*可能会有重复ID的错误 和 Lua table 语法错误*/
         {
             System.Windows.Forms.MessageBoxButtons button  = System.Windows.Forms.MessageBoxButtons.OK;
             System.Windows.Forms.DialogResult      errorDr = System.Windows.Forms.MessageBox.Show(ex.Message, "错误", button);
             if (errorDr == System.Windows.Forms.DialogResult.OK)
             {
                 return(null);
             }
         }
         for (int i = 1; i < BranchCount + 1; i++)
         {
             string serverLuaPath = GetBranchServerLuaPath(tablename, i - 1);
             if (File.Exists(serverLuaPath))
             {
                 try {
                     ltd.tables[i] = parse(serverLuaPath, excelpath);
                 }
                 catch (LuaTableException ex)
                 {
                     System.Windows.Forms.MessageBoxButtons button  = System.Windows.Forms.MessageBoxButtons.OK;
                     System.Windows.Forms.DialogResult      errorDr = System.Windows.Forms.MessageBox.Show(serverLuaPath + "\n" + ex.Message, "错误", button);
                     if (errorDr == System.Windows.Forms.DialogResult.OK)
                     {
                         return(null);
                     }
                 }
             }
             else
             {
                 string excelName = Path.GetFileNameWithoutExtension(excelpath);
                 ltd.tables[i] = new table(ReadTableMD5(slltpath), string.Format("Table_{0}", excelName), excelpath);
             }
         }
         _lTableDataDic[excelpath] = ltd;
     }
     return(_lTableDataDic[excelpath]);
 }