Beispiel #1
0
        /// <summary>
        /// 读取excel
        /// </summary>
        /// <param name="path"></param>
        private void ReadExcel(int index)
        {
            if (PathNames == null || PathNames.Length <= index)
            {
                return;
            }
            SelectKey = PathNames[index];
            Workbook  = ExcelMgr.ReadExcel(SelectKey);
            if (Workbook == null)
            {
                if (EditorUtility.DisplayDialog("错  误", string.Format("Excel路径<{0}>没有找到指定配置表!", SelectKey), "确定"))
                {
                    return;
                }
                return;
            }
            SheetNum = Workbook.NumberOfSheets;
            //sheetsName = new string[mSheetNum];
            ToggleSheetList = new bool[SheetNum];
            SheetsName      = ExcelMgr.GetSheetsName(Workbook);
//             for (int i = 0; i < mSheetNum; i++)
//             {
//                 sheetsName[i] = mWorkbook.GetSheetName(i);
//             }

            //
            //             ISheet sheet = workbook.GetSheetAt(0);  //获取第一个工作表
            //             IRow row;// = sheet.GetRow(0);            //新建当前工作表行数据
            //             for (int i = 0; i < sheet.LastRowNum; i++)  //对工作表每一行
            //             {
            //                 row = sheet.GetRow(i);   //row读入第i行数据
            //                 if (row != null)
            //                 {
            //                     for (int j = 0; j < row.LastCellNum; j++)  //对工作表每一列
            //                     {
            //                         string cellValue = row.GetCell(j).ToString(); //获取i行j列数据
            //                         //Console.WriteLine(cellValue);
            //                     }
            //                 }
            //             }
            //Console.ReadLine();
            ExcelMgr.CloseExcel(Workbook);
        }
Beispiel #2
0
        public static void GeneratingResourceFiles(Dictionary <string, Table> dic)
        {
            if (dic == null)
            {
                return;
            }
            EditorUtility.DisplayCancelableProgressBar("生成配置文件", "开始生成", 0);
            int len   = dic.Values.Count;
            int index = 0;

            foreach (Table table in dic.Values)
            {
                if (!table.IsOutput)
                {
                    continue;
                }
                EditorUtility.DisplayCancelableProgressBar("生成配置文件", string.Format("正在读取Excel配置表:{0}", table.Path), index / len);
                IWorkbook workbook = ExcelMgr.ReadExcel(table.Path);
                if (workbook == null)
                {
                    continue;
                }
                Dictionary <string, TableInfo> .ValueCollection values = table.Dic.Values;
                foreach (TableInfo ti in values)
                {
                    if (!ti.IsOutput)
                    {
                        continue;
                    }
                    EditorUtility.DisplayCancelableProgressBar("生成配置文件", string.Format("正在解析Excel配置表:{0}分页:{0}", Path.GetDirectoryName(table.Path), ti.Sheet), index / len);
                    Generating(table.Path, workbook, ti);
                }
                EditorUtility.DisplayCancelableProgressBar("生成配置文件", string.Format("Excel配置表{0}cfg文件生成完成, 关闭{0}Excel表", Path.GetDirectoryName(table.Path), table.Path), index / len);
                ExcelMgr.CloseExcel(workbook);
                index++;
            }
            EditorUtility.DisplayCancelableProgressBar("生成配置文件", "Excel配置表数据生成完毕!!", 1);
            EditorUtility.ClearProgressBar();
        }
Beispiel #3
0
        private IEnumerator Read(string path, Action <string, Color> setTipVal, Action finish)
        {
            if (mWorkbook == null)
            {
                mWorkbook = ExcelMgr.ReadExcel(mPath);
            }
            yield return(new WaitForEndOfFrame());

            if (mWorkbook == null)
            {
                setTipVal(string.Format("Excel路径<{0}>没有找到指定配置表!", mPath), Color.red);
            }
            else
            {
                mProgressBar.value = 0.01f;
                setTipVal("读取完成", Color.green);
                yield return(new WaitForEndOfFrame());

                List <object> outputList = new List <object>();
                string        cfgName    = null;
                string[]      keys       = null;
                int           count      = mWorkbook.NumberOfSheets;
                var           pgs        = 0.9f / count;
                for (var page = 0; page < count; page++)
                {
                    ISheet sheet = mWorkbook.GetSheetAt(page);
                    if (sheet != null)
                    {
                        if (keys == null)
                        {
                            IRow row = ExcelMgr.GetSheetRow(sheet, 1);
                            keys = new string[row.LastCellNum];
                            if (row != null && row.LastCellNum > 1)
                            {
                                for (int c = 0; c < row.LastCellNum; c++)
                                {
                                    var str = row.GetCell(c).ToString();
                                    if (string.IsNullOrEmpty(str))
                                    {
                                        yield return(new WaitForEndOfFrame());

                                        goto ROW_CELL_IS_NULL;
                                    }
                                    keys[c] = str;
                                }
                            }
                            else
                            {
                                yield return(new WaitForEndOfFrame());

                                goto DECODE_EXCEL_FAIL;
                            }
                        }
                        var rowLen = sheet.LastRowNum + 1;
                        mProgressBar.value = (pgs * page) - (rowLen * pgs) * 2;
                        if (rowLen <= 2)
                        {
                            continue;
                        }
                        for (var r = 2; r < rowLen; r++)
                        {
                            IRow row = ExcelMgr.GetSheetRow(sheet, r);
                            if (row != null && row.LastCellNum > 1)
                            {
                                object cfg = null;
                                for (int c = 0; c < row.LastCellNum; c++)
                                {
                                    var key = keys[c];
                                    if (c == 0)
                                    {
                                        if (!string.IsNullOrEmpty(key))
                                        {
                                            cfg = InfoTool.InstantiationScript(key);
                                            if (cfg == null)
                                            {
                                                goto GET_ASSEMBLY_FAIL;
                                            }
                                            cfgName = key;
                                            yield return(new WaitForEndOfFrame());
                                        }
                                        else
                                        {
                                            yield return(new WaitForEndOfFrame());

                                            goto GET_ASSEMBLY_FAIL;
                                        }
                                    }
                                    else
                                    {
                                        var cell = row.GetCell(c);
                                        if (cell == null)
                                        {
                                            continue;
                                        }
                                        WriteCfg(keys[c], row.GetCell(c).ToString(), ref cfg);
                                    }
                                }
                                if (cfg == null)
                                {
                                    continue;
                                }
                                outputList.Add(cfg);
                            }
                            mProgressBar.value = (pgs * page) - (rowLen * pgs) * r;
                            yield return(new WaitForEndOfFrame());
                        }
                    }
                }
                mProgressBar.value = 0.9f;
                setTipVal("解码完成", Color.green);
                yield return(new WaitForEndOfFrame());

                string outputPath = string.Format("{0}{1}", PathTool.DataPath, PathTool.Temp);
                Config.OutputConfig <object>(outputPath, cfgName, outputList, SuffixTool.TableInfo.ToLower());
                mProgressBar.value = 1.0f;
            }
            goto FINISH;
            ROW_CELL_IS_NULL  : MessageBox.Error("配置表字段key为null"); goto RETURN;
            GET_ASSEMBLY_FAIL : MessageBox.Error("程序集没有识别到Assembly对应的脚本。"); goto RETURN;
            DECODE_EXCEL_FAIL : MessageBox.Error("解析excel失败"); goto RETURN;
            RETURN            : Clear();
FINISH:
            setTipVal("导出完成", Color.green);
            Clear();
            finish();
        }