Esempio n. 1
0
        public void init(Excel.Cells v_data, int v_row, SheetHeader v_header)
        {
            sheetName = v_header.getData(v_data, v_row, "sheet名") as string;
            //optFileName = v_header.getData(v_data, v_row, "导出文件") as string;
            dataOffX       = Convert.ToInt32(v_header.getData(v_data, v_row, "数据偏移X"));
            dataOffY       = Convert.ToInt32(v_header.getData(v_data, v_row, "数据偏移Y"));
            optCliFileName = v_header.getData(v_data, v_row, "导出客户端文件") as string;
            optCliLanguage = getLuaguage(optCliFileName);
            optSrvFileName = v_header.getData(v_data, v_row, "导出服务端文件") as string;
            optSrvLanguage = getLuaguage(optSrvFileName);
            pmKey          = _getPmKey(v_header.getData(v_data, v_row, "主键") as string);
            string shieldColNames = v_header.getData(v_data, v_row, "屏蔽字段") as string;

            if (string.IsNullOrEmpty(shieldColNames))
            {
                shildKeys = new string[0];
            }
            else
            {
                shildKeys = (v_header.getData(v_data, v_row, "屏蔽字段") as string).Split(',', ',');
            }
            isOpt             = readBool(v_header, v_data, v_row, "是否导出");
            isDataPersistence = readBool(v_header, v_data, v_row, "常驻内存");
            isSingleKey       = readBool(v_header, v_data, v_row, "SingleKey");
            note = v_header.getData(v_data, v_row, "表注释") as string;
        }
Esempio n. 2
0
 public bool readData(Excel.Cells v_data, int v_row, SheetHeader v_header)
 {
     try
     {
         int fieldNameIdx    = v_header["字段名"];
         int tableNameIdx    = v_header["表名"];
         int sheetNameIdx    = v_header["sheet名"];
         int columIndexIdx   = v_header["列行数"];
         int colimNameIdx    = v_header["列名"];
         int noteColNameIdx  = v_header["备注名"];
         int dataRowBeginIdx = v_header["起始行"];
         int valueTypeIdx    = v_header["值类型"];
         fieldName     = v_data[v_row, fieldNameIdx].StringValue;
         excelFileName = v_data[v_row, tableNameIdx].StringValue;
         sheetName     = v_data[v_row, sheetNameIdx].StringValue;
         headRow       = v_data[v_row, columIndexIdx].IntValue;
         columName     = v_data[v_row, colimNameIdx].StringValue;
         noteColName   = v_data[v_row, noteColNameIdx].StringValue;
         dataRowBegin  = v_data[v_row, dataRowBeginIdx].IntValue;
         valueType     = v_data[v_row, valueTypeIdx].StringValue;
     }
     catch (Exception ex)
     {
         Debug.Error(ex.ToString());
         return(false);
     }
     return(true);
 }
Esempio n. 3
0
        private void btnOptDesign_Click(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < Config.designer_opt_configs.Count; i++)
                {
                    Output_designer_config optRequest       = Config.designer_opt_configs[i];
                    Excel.Workbook         src_book         = new Excel.Workbook(optRequest.src_path);
                    Excel.Worksheet        src_sheet        = src_book.Worksheets[optRequest.src_sheet];
                    SheetHeader            src_sheet_header = new SheetHeader();
                    src_sheet_header.readHeader(src_sheet, optRequest.src_head_row);
                    src_sheet_header.readDataWithIndex(optRequest.src_pm_key, optRequest.src_row_beg);

                    Excel.Workbook  tar_book         = new Excel.Workbook(optRequest.tar_path);
                    Excel.Worksheet tar_sheet        = tar_book.Worksheets[optRequest.tar_sheet];
                    SheetHeader     tar_sheet_header = new SheetHeader();
                    tar_sheet_header.readHeader(tar_sheet, optRequest.tar_head_row);
                    tar_sheet_header.readDataWithIndex(optRequest.tar_pm_key, optRequest.tar_row_beg);
                    ExcelTableConvert.convert(src_sheet_header, tar_sheet_header, optRequest.src_cols, optRequest.tar_cols);

                    tar_book.Save(optRequest.tar_path);
                }
            }
            catch (Exception ex) { Debug.Error(ex.ToString()); }

            Debug.Info("导出完成");
        }
Esempio n. 4
0
        public void init(Excel.Cells v_data, int v_row, SheetHeader v_header)
        {
            sheetName = v_header.getData(v_data, v_row, "sheet名") as string;
            //optFileName = v_header.getData(v_data, v_row, "导出文件") as string;
            dataOffX       = Convert.ToInt32(v_header.getData(v_data, v_row, "数据偏移X"));
            dataOffY       = Convert.ToInt32(v_header.getData(v_data, v_row, "数据偏移Y"));
            optCliFileName = v_header.getData(v_data, v_row, "导出客户端文件") as string;
            optCliLanguage = getLuaguage(optCliFileName);
            optSrvFileName = v_header.getData(v_data, v_row, "导出服务端文件") as string;
            optSrvLanguage = getLuaguage(optSrvFileName);
            pmKey          = _getPmKey(v_header.getData(v_data, v_row, "主键") as string);
            string shieldColNames = v_header.getData(v_data, v_row, "屏蔽字段") as string;

            if (string.IsNullOrEmpty(shieldColNames))
            {
                shildKeys = new string[0];
            }
            else
            {
                shildKeys = (v_header.getData(v_data, v_row, "屏蔽字段") as string).Split(',', ',');
            }
            Object optCols = v_header.getData(v_data, v_row, "是否导出");

            if (optCols == null)
            {
                optCols = false;
            }
            if (optCols is bool)
            {
                isOpt = (bool)optCols;
            }
            else
            {
                isOpt = optCols.ToString().Equals("TRUE");
            }
            note = v_header.getData(v_data, v_row, "表注释") as string;
            Object dataPersistence = v_header.getData(v_data, v_row, "是否导出");

            if (dataPersistence == null)
            {
                dataPersistence = false;
            }
            if (dataPersistence is bool)
            {
                isDataPersistence = (bool)dataPersistence;
            }
            else
            {
                isDataPersistence = optCols.ToString().Equals("TRUE");
            }
        }
Esempio n. 5
0
        public void calMonsterData(Excel.Worksheet v_monsterSheet)
        {
            Excel.Cells data   = v_monsterSheet.Cells;
            SheetHeader header = new SheetHeader();

            header.readHeader(v_monsterSheet, 1);
            m_monsterAttr = new List <MonsterAttr>();
            //读取设置数据
            for (int i = 2; true; i++)
            {
                object oid = header.getData(data, i, "ID");
                if (oid == null || string.IsNullOrWhiteSpace(oid.ToString()))
                {
                    break;
                }
                MonsterAttr tmp = new MonsterAttr();
                tmp.id                 = Convert.ToInt32(oid);
                tmp.note               = header.getData(data, i, "备注").ToString();
                tmp.groupID            = Convert.ToInt32(header.getData(data, i, "组ID"));
                tmp.level              = Convert.ToInt32(header.getData(data, i, "等级"));
                tmp.iniAngry           = Convert.ToInt32(header.getData(data, i, "初始怒气"));
                tmp.angryRecover       = Convert.ToInt32(header.getData(data, i, "怒气回复"));
                tmp.killMonsterRound   = Convert.ToSingle(header.getData(data, i, "玩家杀怪回合数"));
                tmp.hpCost             = Convert.ToSingle(header.getData(data, i, "消耗血量"));
                tmp.phisicalDefPercent = Convert.ToSingle(header.getData(data, i, "物防百分比"));
                tmp.magicalDefPercent  = Convert.ToSingle(header.getData(data, i, "法防百分比"));
                tmp.playerCureNum      = Convert.ToSingle(header.getData(data, i, "玩家治疗数"));
                tmp.monsterCureNum     = Convert.ToSingle(header.getData(data, i, "怪物治疗数"));
                m_monsterAttr.Add(tmp);
            }
            //进行计算,并填表
            for (int i = 0; i < m_monsterAttr.Count; i++)
            {
                MonsterAttr  cur        = m_monsterAttr[i];
                int          playerIdx  = getPlayerAttrIdx(cur.groupID, cur.level);
                BaseAttrData playerAttr = m_playerAttrdatas[playerIdx];
                cur.playerAttr = playerAttr;
                cur.calMonsterAttr();
                header.setData(data, i + 2, "玩家血量", playerAttr.Hp);
                header.setData(data, i + 2, "玩家攻击", playerAttr.Atk);
                header.setData(data, i + 2, "玩家物防", playerAttr.PhisicalDef);
                header.setData(data, i + 2, "玩家法防", playerAttr.MagicalDef);
                header.setData(data, i + 2, "怪物血量", cur.monsterAttr.Hp);
                header.setData(data, i + 2, "怪物攻击", cur.monsterAttr.Atk);
                header.setData(data, i + 2, "怪物物防", cur.monsterAttr.PhisicalDef);
                header.setData(data, i + 2, "怪物法防", cur.monsterAttr.MagicalDef);
            }
        }
Esempio n. 6
0
        public static void convert(SheetHeader v_et1, SheetHeader v_et2, string[] v_concernCols1, string[] v_concernCols2)
        {
            Excel.Cells data1         = v_et1.data;
            Excel.Cells data2         = v_et2.data;
            int         pmIdx1        = v_et1.PmIndex;
            int         concernColLen = v_concernCols1.Length;

            int[] sheet1_concernCols = new int[concernColLen];
            int[] sheet2_concernCols = new int[concernColLen];

            for (int i = 0; i < concernColLen; i++)
            {
                sheet1_concernCols[i] = v_et1[v_concernCols1[i]];
                if (sheet1_concernCols[i] == -1)
                {
                    Debug.Exception("表1没有设置关心列{0}", v_concernCols1[i]);
                    return;
                }
                sheet2_concernCols[i] = v_et2[v_concernCols2[i]];
                if (sheet2_concernCols[i] == -1)
                {
                    Debug.Exception("表2没有设置关心列{0}", v_concernCols2[i]);
                    return;
                }
            }


            for (int i = 0; i < v_et1.DataRows; i++)
            {
                string pmVal     = data1[i + v_et1.RowBegin, pmIdx1].StringValue;
                int    sheet2Row = v_et2.getPMRow(pmVal);
                if (sheet2Row == -1)
                {
                    Debug.Exception("表2中没找到主键{0}", pmVal);
                    return;
                }

                for (int j = 0; j < concernColLen; j++)
                {
                    var cellVal = data1[i + v_et1.RowBegin, sheet1_concernCols[j]].Value;
                    if (cellVal != null && cellVal.ToString() != "#N/A")
                    {
                        data2[sheet2Row, sheet2_concernCols[j]].Value = cellVal;
                    }
                }
            }
        }
Esempio n. 7
0
        public void readData(Excel.Worksheet v_sheet)
        {
            Excel.Cells data   = v_sheet.Cells;
            SheetHeader header = new SheetHeader();

            header.readHeader(v_sheet, 1);
            for (int i = 2; i < 100000; i++)
            {
                object idIdx = header.getData(data, i, "等级");
                if (idIdx == null || string.IsNullOrWhiteSpace(idIdx.ToString()))
                {
                    break;
                }
                int        groupId  = Convert.ToInt32(header.getData(data, i, "组ID"));
                List <int> arrIndex = null;
                if (!m_playerDataIndex.ContainsKey(groupId))
                {
                    arrIndex = new List <int>();
                    m_playerDataIndex.Add(groupId, arrIndex);
                }
                else
                {
                    arrIndex = m_playerDataIndex[groupId];
                }
                arrIndex.Add(m_playerDatas.Count);
                if (arrIndex == null)
                {
                    arrIndex = new List <int>();
                    m_playerDataIndex.Add(groupId, arrIndex);
                }
                arrIndex.Add(m_playerDatas.Count);
                playerData pd     = new playerData();
                string[]   strIpt = new string[titles.Length];
                for (int j = 0; j < titles.Length; j++)
                {
                    object tmp = header.getData(data, i, titles[j]);
                    if (tmp == null)
                    {
                        Debug.Info("读取第{0}行第{1}列时发生错误", i, titles[j]);
                    }
                    strIpt[j] = Convert.ToString(tmp);
                }
                pd.init(strIpt);
                m_playerDatas.Add(pd);
            }
        }
Esempio n. 8
0
        private bool readBool(SheetHeader v_header, Excel.Cells v_cell, int v_row, string v_colName)
        {
            object oVal = v_header.getData(v_cell, v_row, v_colName);

            if (oVal == null)
            {
                return(false);
            }
            if (oVal is bool)
            {
                return((bool)oVal);
            }
            else
            {
                return(oVal.ToString().Equals("TRUE"));
            }
        }
Esempio n. 9
0
        //protected List<BaseAttrData> monsterAttr;
        public void calPlayerAttr(Excel.Worksheet v_monsterSheet)
        {
            const int OFF_Y = 2;

            Excel.Cells data = v_monsterSheet.Cells;
            m_playerAttrdatas = new List <BaseAttrData>();
            m_playerAttrIndex = new Dictionary <int, List <int> >();
            SheetHeader header = new SheetHeader();

            header.readHeader(v_monsterSheet, 1);

            for (int i = 0; i < m_playerDatas.Count; i++)
            {
                BaseAttrData attrVal = new BaseAttrData();
                attrVal.init();
                BaseAttrData attrFac = new BaseAttrData();
                attrFac.init();
                playerData pd = m_playerDatas[i];

                //计算武将属性
                attrVal = attrVal + m_heroAttr * pd.heroAptitude * (pd.level + 10) * (float)Math.Pow(1.2, (double)pd.heroBreak);
                //计算武器
                attrVal = attrVal + m_equipStrengthenData.Weapon * (8 + pd.equipStrengthenLv);
                //计算胸甲
                attrVal = attrVal + m_equipStrengthenData.Breast * (8 + pd.equipStrengthenLv);
                //计算头盔
                attrVal = attrVal + m_equipStrengthenData.halmet * (8 + pd.equipStrengthenLv);
                //计算鞋子
                attrVal = attrVal + m_equipStrengthenData.shoose * (8 + pd.equipStrengthenLv);
                //计算神器
                attrFac = attrFac + m_equipStrengthenData.almulet_1 * (10 + pd.amulet_level) * pd.heroNum;
                //计算圣器
                attrFac = attrFac + m_equipStrengthenData.almulet_2 * (10 + pd.amulet_level) * pd.heroNum;
                //计算装备突破
                for (int j = 0; j < 4; j++)
                {
                    attrFac = attrFac + m_equipBreakupData.getData(j + 1, pd.equipBreakLv);
                }
                //计算宝物精炼
                for (int j = 0; j < pd.amuletQualityArrHp.Length; j++)
                {
                    attrVal = attrVal + m_amuletRecoinData.getData(0, j, pd.amulet_recoin) * pd.amuletQualityArrHp[j];
                    attrVal = attrVal + m_amuletRecoinData.getData(1, j, pd.amulet_recoin) * pd.amuletQualityArrAtk[j];
                }
                //计算战宠培养
                attrVal = attrVal + m_petFosterData.levelData[pd.pet_level] * pd.heroNum;
                //计算战宠星语
                attrFac = attrFac + m_petStarData.levelData[pd.pet_xingyu] * pd.heroNum;
                //计算最终结果
                attrVal = attrVal / pd.heroNum;
                attrFac = attrFac / pd.heroNum;
                BaseAttrData finalAttr = attrVal * attrFac;
                //考虑英雄技能系数
                float avgSkillFac = 0;
                for (int j = 0; j < 5; j++)
                {
                    avgSkillFac += m_skillFac[j] * pd.heroQualitys[j];
                }
                avgSkillFac   /= pd.heroNum;
                finalAttr.Atk *= avgSkillFac;
                float[] arrAttr = new float[] { (float)Math.Round(finalAttr.Hp, 2),
                                                (float)Math.Round(finalAttr.Atk, 2),
                                                (float)Math.Round(finalAttr.PhisicalDef, 2),
                                                (float)Math.Round(finalAttr.MagicalDef, 2) };
                BaseAttrData bad = new BaseAttrData();
                bad.init(arrAttr);
                List <int> arrPlayerAttrIndex = null;
                if (!m_playerAttrIndex.ContainsKey(pd.groupID))
                {
                    arrPlayerAttrIndex = new List <int>();
                    m_playerAttrIndex.Add(pd.groupID, arrPlayerAttrIndex);
                }
                else
                {
                    arrPlayerAttrIndex = m_playerAttrIndex[pd.groupID];
                }
                arrPlayerAttrIndex.Add(m_playerAttrdatas.Count);
                m_playerAttrdatas.Add(bad);


                header.setData(data, OFF_Y + i, "玩家血", bad.Hp);
                header.setData(data, OFF_Y + i, "玩家攻", bad.Atk);
                header.setData(data, OFF_Y + i, "玩家物防", bad.PhisicalDef);
                header.setData(data, OFF_Y + i, "玩家法防", bad.MagicalDef);
            }
        }
Esempio n. 10
0
        public void apposeReadExcel(string v_filePath)
        {
            Excel.Workbook  book        = new Excel.Workbook(v_filePath);
            Excel.Worksheet index_sheet = book.Worksheets["INDEX"];
            if (index_sheet == null)
            {
                __old_readExcel(v_filePath);
                return;
            }
            //读取索引表
            List <IndexSheetData> indexes      = new List <IndexSheetData>();
            SheetHeader           index_header = new SheetHeader();

            index_header.readHeader(index_sheet);
            Excel.Cells datas = index_sheet.Cells;

            for (int i = 1; i < 100; i++)
            {
                try
                {
                    if (datas[i, 0].Value == null || string.IsNullOrEmpty(datas[i, 0].Value.ToString()))
                    {
                        break;
                    }
                    IndexSheetData the_index = new IndexSheetData();
                    the_index.init(datas, i, index_header);
                    indexes.Add(the_index);
                }
                catch (Exception ex)
                {
                    Debug.Error("{0}读取索引列,第{1}行时报错,报错信息如下\r\n{2}", Path.GetFileName(v_filePath), i + 2, ex.ToString());
                    return;
                }
            }


            Dictionary <string, ExcelToMapData>[] table_memo    = new Dictionary <string, ExcelToMapData> [2];
            Dictionary <string, ExportSheetBin>[] sheetBin_memo = new Dictionary <string, ExportSheetBin> [2];
            string[] root_pathes = { Config.cliPath, Config.servPath };
            int[]    optCode     = { 1, 2 };
            for (int i = 0; i < table_memo.Length; i++)
            {
                table_memo[i]    = new Dictionary <string, ExcelToMapData>();
                sheetBin_memo[i] = new Dictionary <string, ExportSheetBin>();
            }
            //根据索引表读取各sheet
            foreach (IndexSheetData curIndex in indexes)
            {
                if (!curIndex.isOpt)
                {
                    continue;
                }
                Excel.Worksheet curSheet = book.Worksheets[curIndex.sheetName];
                if (curSheet == null)
                {
                    Debug.Error("{0}没有找到sheet[{1}]", Path.GetFileName(v_filePath), curIndex.sheetName);
                    return;
                }

                ExportSheetBin sheetBin = new ExportSheetBin();
                try
                {
                    if (!sheetBin.init(curSheet, curIndex))
                    {
                        return;
                    }
                }
                catch (Exception ex)
                {
                    Debug.Error("{0}_[{1}]导出基础数据时出现错误,错误信息为:\r\n{2}", Path.GetFileNameWithoutExtension(v_filePath), curIndex.sheetName, ex.ToString());
                    return;
                }
                //根据服务端的文件名,创建获取luamap
                string[] file_names = { curIndex.optCliFileName, curIndex.optSrvFileName };
                for (int i = 0; i < table_memo.Length; i++)//客户端服务端各生成一遍
                {
                    if (string.IsNullOrEmpty(file_names[i]))
                    {
                        continue;
                    }
                    if (!table_memo[i].ContainsKey(file_names[i]))
                    {
                        ExcelMapData   new_map           = new ExcelMapData();
                        bool           isDataPersistence = curIndex.isDataPersistence && (!string.IsNullOrEmpty(curIndex.optCliFileName)) && curIndex.optCliFileName.EndsWith(".lua");
                        ExcelToMapData new_data          = new ExcelToMapData(new_map,
                                                                              isDataPersistence,
                                                                              Path.GetFileNameWithoutExtension(file_names[i]));
                        table_memo[i].Add(file_names[i], new_data);
                    }
                    if (!sheetBin_memo[i].ContainsKey(file_names[i]))
                    {
                        sheetBin_memo[i].Add(file_names[i], sheetBin);
                    }
                    ExcelToMapData root_table = table_memo[i][file_names[i]];
                    root_table.add_sheetbin(sheetBin);
                    //把表中的数据读取到lua map里
                    //应当把这里的逻辑改为,把表中数据读到一个map_data中,而后转到各语言的结构中
                    try
                    {
                        sheetBin.getExportMap(root_table._data, optCode[i]);
                    }
                    catch (Exception ex)
                    {
                        Debug.Error("在装载【{0}】数据到中间结构时发生错误,错误信息是{1}", curIndex.sheetName, ex.ToString());
                    }
                }
            }

            //这里应当写为,根据后缀名导出不同的语言
            for (int i = 0; i < table_memo.Length; i++)
            {
                foreach (var cur_pair in table_memo[i])
                {
                    string         opt_path     = root_pathes[i] + cur_pair.Key;
                    OptData        optData      = null;
                    ExportSheetBin cur_sheetBin = sheetBin_memo[i][cur_pair.Key];
                    ELanguage      optLanguage  = cur_sheetBin.indexData.getOptLanguage(i);
                    bool           skip         = false;

                    switch (optLanguage)
                    {
                    case ELanguage.lua:
                        optData = LuaExporter.getExportContent(cur_pair.Value, optCode[i]);
                        break;

                    case ELanguage.json:
                        optData = JsonExporter.getExportContent(cur_pair.Value, optCode[i]);
                        break;

                    case ELanguage.xml:
                        Debug.Error("xml导出未实现");
                        break;

                    case ELanguage.none:
                        skip = true;
                        break;

                    default:
                        Debug.Error("未知导出语言");
                        break;
                    }
                    if (!skip)
                    {
                        if (optData.errList.Count > 0)
                        {
                            Debug.Error(string.Format("在导出{0}时发生错误:\r\n", cur_pair.Key) + optData.getErrInfo());
                            return;
                        }
                        File.WriteAllText(opt_path, optData.content);

                        //todo 如果是Realease模式,把文件输出到一个临时文件夹,调用LUAC,把lua文件生成到配置的cli文件夹中。
                    }
                }
            }
            Debug.Info("{0}:导表完成~~~", Path.GetFileName(v_filePath));
        }
Esempio n. 11
0
        private void frmMain_Load(object sender, EventArgs e)
        {
            try
            {
                Config.load();
            }
            catch (Exception ex) { Debug.Error("xml解析时失败" + ex.ToString()); }
            //加载luastate
            LuaState.Init(Config.luaCfgPath + "main.lua");
            LuaState.SetPath(Config.luaCfgPath);
            LuaState.DoMain();
            cliPath   = Config.cliPath;
            servPath  = Config.servPath;
            excelPath = Config.excelPath;
            Excel.Workbook  indexBook  = new Excel.Workbook(Config.indexPath);
            Excel.Worksheet indexSheet = indexBook.Worksheets["index"];
            Excel.Cells     data       = indexSheet.Cells;
            SheetHeader     header     = new SheetHeader();

            header.readHeader(indexSheet);
            List <NameCatchIndexData> nameCatchIndexDatas = new List <NameCatchIndexData>();

            //读取需要索引的数据列表
            for (int row = 1; row < 200; row++)
            {
                if (data[row, 0].Value == null || string.IsNullOrWhiteSpace(data[row, 0].Value.ToString()))
                {
                    break;
                }
                NameCatchIndexData rowData = new NameCatchIndexData();
                rowData.readData(data, row, header);
                nameCatchIndexDatas.Add(rowData);
            }
            NickNameColCatchManager nickNameColCatchManager = NickNameColCatchManager.getInstence();

            //打开各表,生成各名称ID转换
            foreach (NameCatchIndexData curIndex in nameCatchIndexDatas.ToArray())
            {
                string          excelPath = Config.excelPath + curIndex.excelFileName + ".xlsx";
                Excel.Worksheet sheet     = null;
                if (!File.Exists(excelPath))
                {
                    Debug.Error("{0}不存在", excelPath);
                    return;
                }
                try
                {
                    Excel.Workbook book = new Excel.Workbook(excelPath);
                    sheet = book.Worksheets[curIndex.sheetName];
                    if (sheet == null)
                    {
                        Debug.Exception("没有找到名为[" + curIndex.sheetName + "]的sheet");
                    }
                }
                catch (Exception ex) {
                    Debug.Error(ex.ToString());
                    Application.Exit();
                    return;
                }
                SheetHeader theHeader = new SheetHeader();
                theHeader.readHeader(sheet, curIndex.headRow - 1);
                int idColIndex = theHeader[curIndex.columName];
                if (idColIndex == -1)
                {
                    Debug.Error("{1}  列{0}不存在", curIndex.columName, curIndex.excelFileName + "[" + curIndex.sheetName + "]");
                    return;
                }
                int noteIndex = theHeader[curIndex.noteColName];
                if (noteIndex == -1)
                {
                    Debug.Error("{1}  列{0}不存在", curIndex.noteColName, curIndex.excelFileName + "[" + curIndex.sheetName + "]");
                    return;
                }
                Excel.Cells theDatas = sheet.Cells;
                for (int row = curIndex.dataRowBegin - 1; row < 100000; row++)
                {
                    nickNameColCatchManager.createCatch(curIndex.fieldName, curIndex.valueType);
                    if (theDatas[row, 0].Value == null || string.IsNullOrWhiteSpace(theDatas[row, 0].Value.ToString()))
                    {
                        break;
                    }
                    try
                    {
                        int    id       = theDatas[row, idColIndex].IntValue;
                        string nickName = theDatas[row, noteIndex].StringValue;
                        nickNameColCatchManager.addData(curIndex.fieldName, nickName, id);
                    }
                    catch (Exception ex)
                    {
                        Debug.Error("{0}表[{1}],第{2}行出错啦,错误信息为:\r\n  " + ex.ToString(), curIndex.excelFileName, curIndex.sheetName, row + 1);
                        return;
                    }
                }
            }
        }
Esempio n. 12
0
        protected void _load()
        {
            //加载luastate
            if (Config.bLoadLua)
            {
                updateDesc("加载luastate......");
                try
                {
                    LuaState.Init(Config.luaCfgPath + "main.lua");
                    LuaState.SetPath(Config.luaCfgPath);
                    LuaState.DoMain();
                }
                catch (Exception ex)
                {
                    Debug.Error("加载lua报错,信息是" + ex.ToString());
                    return;
                }
                updateDesc("luastate加载完成");
            }
            Thread.Sleep(50);
            if (Config.bReadIndex)
            {
                updateDesc("读取INDEX表......");
                Excel.Workbook  indexBook  = new Excel.Workbook(Config.indexPath);
                Excel.Worksheet indexSheet = indexBook.Worksheets["index"];
                Excel.Cells     data       = indexSheet.Cells;
                SheetHeader     header     = new SheetHeader();
                header.readHeader(indexSheet);
                List <NameCatchIndexData> nameCatchIndexDatas = new List <NameCatchIndexData>();

                //读取需要索引的数据列表
                for (int row = 1; row < 200; row++)
                {
                    if (data[row, 0].Value == null || string.IsNullOrWhiteSpace(data[row, 0].Value.ToString()))
                    {
                        break;
                    }
                    NameCatchIndexData rowData = new NameCatchIndexData();
                    rowData.readData(data, row, header);
                    nameCatchIndexDatas.Add(rowData);
                }
                updateDesc("INDEX表读取完成");
                Thread.Sleep(50);
                updateDesc("根据INDEX表加载各名称表......");
                NickNameColCatchManager nickNameColCatchManager = NickNameColCatchManager.getInstence();
                nickNameColCatchManager.init();
                Thread.Sleep(50);
                //打开各表,生成各名称ID转换
                foreach (NameCatchIndexData curIndex in nameCatchIndexDatas.ToArray())
                {
                    string excelPath = Config.excelPath + curIndex.excelFileName;
                    updateDesc(string.Format("加载表{0},处理名称{1}......", curIndex.excelFileName, curIndex.fieldName));
                    Excel.Worksheet sheet = null;
                    if (!File.Exists(excelPath))
                    {
                        Debug.Error("{0}不存在", excelPath);
                        return;
                    }
                    try
                    {
                        Excel.Workbook book = new Excel.Workbook(excelPath);
                        sheet = book.Worksheets[curIndex.sheetName];
                        if (sheet == null)
                        {
                            Debug.Exception("没有找到名为[" + curIndex.sheetName + "]的sheet");
                        }
                    }
                    catch (Exception ex)
                    {
                        Debug.Error(ex.ToString());
                        Application.Exit();
                        return;
                    }
                    SheetHeader theHeader = new SheetHeader();
                    theHeader.readHeader(sheet, curIndex.headRow - 1);
                    int idColIndex = theHeader[curIndex.columName];
                    if (idColIndex == -1)
                    {
                        Debug.Error("{1}  列{0}不存在", curIndex.columName, curIndex.excelFileName + "[" + curIndex.sheetName + "]");
                        return;
                    }
                    int noteIndex = theHeader[curIndex.noteColName];
                    if (noteIndex == -1)
                    {
                        Debug.Error("{1}  列{0}不存在", curIndex.noteColName, curIndex.excelFileName + "[" + curIndex.sheetName + "]");
                        return;
                    }
                    Excel.Cells theDatas = sheet.Cells;
                    for (int row = curIndex.dataRowBegin - 1; row < 100000; row++)
                    {
                        nickNameColCatchManager.createCatch(curIndex.fieldName, curIndex.valueType);
                        if (theDatas[row, 0].Value == null || string.IsNullOrWhiteSpace(theDatas[row, 0].Value.ToString()))
                        {
                            break;
                        }
                        try
                        {
                            long   id       = long.Parse(theDatas[row, idColIndex].StringValue);
                            string nickName = theDatas[row, noteIndex].StringValue;
                            nickNameColCatchManager.addData(curIndex.fieldName, nickName, id);
                        }
                        catch (Exception ex)
                        {
                            Debug.Error("{0}表[{1}],第{2}行出错啦,错误信息为:\r\n  " + ex.ToString(), curIndex.excelFileName, curIndex.sheetName, row + 1);
                            return;
                        }
                    }
                    updateDesc(string.Format("表{0}加载完成", curIndex.excelFileName));
                    Thread.Sleep(50);
                }
            }
            else
            {
                updateDesc("INDEX表没有配置,不加载nickNameCatch");
                Thread.Sleep(50);
            }
            workFinished();
        }