Example #1
0
        public static void Load(byte[] buffer)
        {
            if (buffer == null)
            {
                return;
            }
            HashSet <string> dirtyWord = new HashSet <string>();
            WorkBook         workBook  = BaseExcelMgr.ReadWorkbook(buffer);

            if (workBook != null && workBook.Count > 0)
            {
                foreach (var sheet in workBook)
                {
                    if (sheet.Name.StartsWith(SysConst.Prefix_Lang_Notes))
                    {
                        continue;
                    }
                    foreach (var row in sheet)
                    {
                        if (row.Cells.Count > 0)
                        {
                            var text = row.Cells[0].Text;
                            if (!text.IsInv())
                            {
                                dirtyWord.Add(text);
                            }
                        }
                    }
                }
            }
            Load(dirtyWord);
        }
Example #2
0
        void LoadLanguageData(byte[] buffer)
        {
            var workbook = BaseExcelMgr.ReadWorkbook(buffer);

            if (workbook == null)
            {
                CLog.Error("无法读取下面文件");
                return;
            }
            //读取每一个Sheet
            foreach (var sheet in workbook)
            {
                if (sheet.Count <= 0)
                {
                    continue;
                }
                if (sheet.Name.StartsWith(SysConst.Prefix_Lang_Notes))
                {
                    continue;
                }
                string lastedCategory = "";
                int    NumberOfRows   = sheet.Rows.Count;
                int    NumberOfCols   = sheet.Rows[0].Count;
                if (NumberOfRows <= 0 || NumberOfCols <= 0)
                {
                    continue;
                }
                //读取行
                for (int rowIndex = 0; rowIndex < NumberOfRows; ++rowIndex)
                {
                    #region key
                    //读取第一行
                    if (rowIndex == 0)
                    {
                        for (int colIndex = 0; colIndex < NumberOfCols; ++colIndex)
                        {
                            string tempStr = sheet.Rows[rowIndex][colIndex].ToString();
                            if (tempStr.IsInv())
                            {
                                continue;
                            }
                            if (!FirstRowStrs.ContainsKey(tempStr))
                            {
                                CLog.Error("语言包错误!无效的首行:" + tempStr + ",TableName:" + sheet.Name + ",ID:" + sheet.ID);
                                foreach (var item in FirstRowStrs)
                                {
                                    CLog.Error("首行:" + item.Key.ToString());
                                }
                                return;
                            }
                        }
                    }
                    #endregion
                    #region 读取翻译
                    //读取非首行
                    else
                    {
                        string key = "";
                        for (int colIndex = 0; colIndex < NumberOfCols; ++colIndex)
                        {
                            if (sheet.Rows[rowIndex].Count <= colIndex)
                            {
                                continue;
                            }
                            if (colIndex - 1 >= LangTypes.Count)
                            {
                                continue;
                            }
                            //读取key
                            if (colIndex == 0)
                            {
                                key = sheet.Rows[rowIndex][colIndex].ToString();
                                //跳过无效的字符
                                if (key.IsInv())
                                {
                                    continue;
                                }
                                //跳过注释
                                if (key.StartsWith(Const.Prefix_Lang_Notes))
                                {
                                    continue;
                                }
                                //跳过分类
                                if (key.StartsWith(Const.Prefix_Lang_Category))
                                {
                                    lastedCategory = key.Remove(0, 1);
                                    continue;
                                }
                            }
                            //读取desc
                            else
                            {
                                string firstRowKey = sheet.Rows[0][colIndex].ToString();
                                if (!FirstRowStrs.ContainsKey(firstRowKey))
                                {
                                    CLog.Error("语言包错误!无效的首行:" + firstRowKey);
                                }
                                string desc = sheet.Rows[rowIndex][colIndex].ToString();
                                if (desc.IsInv())
                                {
                                    continue;
                                }
                                Add(FirstRowStrs[firstRowKey], key, desc, "", lastedCategory);
                            }
                        }
                    }
                    #endregion
                }
            }
        }