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); }
public void ExportNameLocationData() { DataTable dt = new DataTable(); dt.Columns.Add("ID", typeof(string)); dt.Columns.Add("中文", typeof(string)); dt.Columns.Add("英文", typeof(string)); dt.Columns.Add("繁体", typeof(string)); dt.Columns.Add("日语", typeof(string)); dt.Columns.Add("西语", typeof(string)); dt.Columns.Add("文言文", typeof(string)); dt.Rows.Add(">>姓氏>>>>>>>>>>>>>"); foreach (var item in Last) { dt.Rows.Add( BaseConstMgr.Prefix_SurnameTrans + item, item, BaseStrUtils.ToPinying(item), BaseStrUtils.ToTraditional(item), item, item, item ); } dt.Rows.Add(">>女名>>>>>>>>>>>>>"); foreach (var item in Female) { dt.Rows.Add( BaseConstMgr.Prefix_NameTrans + item, item, BaseStrUtils.ToPinying(item), BaseStrUtils.ToTraditional(item), item, item, item ); } dt.Rows.Add(">>男名>>>>>>>>>>>>>"); foreach (var item in Male) { dt.Rows.Add( BaseConstMgr.Prefix_NameTrans + item, item, BaseStrUtils.ToPinying(item), BaseStrUtils.ToTraditional(item), item, item, item ); } BaseExcelMgr.WriteExcelNPOI(dt, Path.Combine(BaseConstMgr.Path_Dev, TDID + ".xls")); }
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 } } }
void LoadLanguageData(string item) { HSSFWorkbook dataSet = BaseExcelMgr.ReadExcelNPOI(item); if (dataSet == null) { CLog.Error("无法读取下面文件{0}:", item); return; } //读取每一个Sheet for (int i = 0; i < dataSet.NumberOfSheets; ++i) { ISheet sheet = dataSet.GetSheetAt(i); var collect = sheet.GetRowEnumerator(); //读取每一行 while (collect.MoveNext()) { //读取语言类型:中文,英文,繁体等等 IRow row = (IRow)collect.Current; if (row.RowNum == 0) { foreach (var cell in row.Cells) { if (cell.ColumnIndex == 0) { continue; } else { try { LangTypes.Add((LanguageType)Enum.Parse(typeof(LanguageType), cell.ToString())); } catch (Exception e) { CLog.Error("解析Excel表格错误:" + e.ToString()); } } } } //读取翻译 else { string key = ""; //读取每一列 foreach (var cell in row.Cells) { //读取每一行的key if (cell.ColumnIndex == 0) { key = cell.ToString(); if (key.IsInvStr()) { continue; } } //读取每一行的翻译 else { string val = cell.ToString(); if (val.IsInvStr()) { val = key; } Add(LangTypes[cell.ColumnIndex - 1], key, val); } } } } } }