コード例 #1
0
        private void readModelXmlFile(string content, ExcelStateObj table)
        {
            List <string> ColIdList = new List <string>();

            ColIdList.Clear();
            colDict.Clear();
            ColIdList.Add("None");
            TextReader tr     = new StringReader(content);
            XmlReader  reader = new XmlTextReader(tr);

            while (reader.Read())
            {
                if (reader.NodeType == XmlNodeType.Element)
                {
                    if (!string.IsNullOrEmpty(reader.LocalName))
                    {
                        for (int i = 0; i < reader.AttributeCount; i++)
                        {
                            reader.MoveToAttribute(i);
                            string attrName = reader.Name;
                            if (!string.IsNullOrEmpty(attrName) && !ColIdList.Contains(attrName))
                            {
                                ColIdList.Add(attrName);
                                colDict[attrName] = 0;
                            }
                        }
                        ;
                    }
                }
            }

            table.ColunmModel = ColIdList.ToArray();
            //Debug.Log(table.ColunmModel);
        }
コード例 #2
0
        private void readModelJsonFile(string content, ExcelStateObj table)
        {
            List <string> ColIdList = new List <string>();

            ColIdList.Clear();
            colDict.Clear();
            ColIdList.Add("None");
            JsonData jd = JsonMapper.ToObject(content);

            if (jd.Count == 0)
            {
                return;
            }
            List <string> list = new List <string>(jd[0].Keys);

            foreach (var attrName in list)
            {
                if (!string.IsNullOrEmpty(attrName) && !ColIdList.Contains(attrName))
                {
                    ColIdList.Add(attrName);
                    colDict[attrName] = 0;
                }
            }

            table.ColunmModel = ColIdList.ToArray();
        }
コード例 #3
0
        private void readModel(string url, ExcelStateObj table)
        {
            if (string.IsNullOrEmpty(url))
            {
                return;
            }
            table.ModelName = System.IO.Path.GetFileNameWithoutExtension(url);
            FileInfo fi      = new FileInfo(url);
            string   content = ExcelFunction.LoadFileStr(url);

            switch (fi.Extension)
            {
            case ".xml":
            case ".XML":
            case ".Xml":
                readModelXmlFile(content, table);
                break;

            case ".json":
            case ".JSON":
            case ".Json":
                readModelJsonFile(content, table);
                break;
            }
        }
コード例 #4
0
        public static List <ExcelStateObj> ReadExcel(string path)
        {
            MemoryStream         memory      = new MemoryStream(LoadFilebytes(path));
            List <ExcelStateObj> list        = new List <ExcelStateObj>();
            IExcelDataReader     excelReader = ExcelReaderFactory.CreateOpenXmlReader(memory);

            do
            {
                // sheet name
                //Debug.Log(excelReader.Name);
                List <RowStateObj> rowList = new List <RowStateObj>();
                int rowCount = 0;
                int colCount = 0;
                while (excelReader.Read())
                {
                    bool        isAdd = false;
                    RowStateObj row   = new RowStateObj(excelReader.FieldCount);
                    colCount = Mathf.Max(excelReader.FieldCount, colCount);
                    for (int i = 0; i < colCount; i++)
                    {
                        CellStateObj cell = new CellStateObj();
                        row.Cells[i] = cell;
                        if (i < excelReader.FieldCount)
                        {
                            string value = excelReader.IsDBNull(i) ? "" : excelReader.GetString(i);
                            cell.Value = value;
                            if (!string.IsNullOrEmpty(value))
                            {
                                isAdd = true;
                            }
                        }
                    }
                    if (isAdd)
                    {
                        rowCount++;
                        rowList.Add(row);
                    }
                }
                ExcelStateObj excelStateObj = new ExcelStateObj(rowCount, colCount);
                excelStateObj.ExcelName = excelReader.Name;
                excelStateObj.Rows      = rowList.ToArray();
                list.Add(excelStateObj);
            }while(excelReader.NextResult());
            //DataSet result = excelReader.AsDataSet();
            excelReader.Close();
            excelReader.Dispose();
            memory.Close();
            memory.Dispose();
            return(list);
        }
コード例 #5
0
        private void DrawSelect()
        {
            float wid = position.width;            //EditorGUIUtility.currentViewWidth;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("SelectTable:", GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / 3));
            GUILayout.Label(tables[currentTable], GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / 3));
            int _tableIndex = currentTable;

            _tableIndex = EditorGUILayout.Popup(currentTable, tables, GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / 3));
            if (selectTable == null || _tableIndex != currentTable)
            {
                selectTable = excelDict[tables[_tableIndex]];
            }
            currentTable = _tableIndex;
            EditorGUILayout.EndHorizontal();
        }
コード例 #6
0
        private void DrawTable()
        {
            ExcelStateObj table = selectTable;

            if (table == null)
            {
                return;
            }
            if (table.modelDict == null)
            {
                table.modelDict = new Dictionary <int, int>();
            }
            if (table.ColunmModel == null)
            {
                return;
            }
            float wid      = position.width;
            int   StartRow = table.StartRow;

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("Start Row:", GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / 4));
            StartRow = EditorGUILayout.IntField(table.StartRow, GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / 4));
            int StartCol = table.StartCol;

            GUILayout.Label("Start Colunm:", GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / 4));
            StartCol = EditorGUILayout.IntField(table.StartCol, GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / 4));

            if (StartRow != table.StartRow)
            {
                table.StartRow = StartRow;
            }
            if (StartCol != table.StartCol)
            {
                table.StartCol = StartCol;
            }
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / (table.ColCount + 1 - table.StartCol)));
            RowStateObj row = table.Rows[0];

            for (int j = table.StartCol; j < table.ColCount; j++)
            {
                CellStateObj cell = row.Cells[j];
                EditorGUILayout.LabelField(cell.Value, GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / (table.ColCount + 1 - table.StartCol)));
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("", GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / (table.ColCount + 1 - table.StartCol)));
            for (int j = table.StartCol; j < table.ColCount; j++)
            {
                if (!table.modelDict.ContainsKey(j))
                {
                    table.modelDict[j] = 0;
                }
                int isShow = table.modelDict[j];
                isShow = EditorGUILayout.Popup(isShow, table.ColunmModel, GUILayout.MinWidth(0), GUILayout.MaxWidth(wid / (table.ColCount + 1 - table.StartCol)));
                if (isShow != table.modelDict[j])
                {
                    if (isShow != 0)
                    {
                        table.SetExportColunmExport(j, true);
                        table.SetExportColunmName(j, table.ColunmModel[isShow]);
                    }
                    else
                    {
                        table.SetExportColunmExport(j, false);
                    }
                }

                table.modelDict[j] = isShow;
            }
            EditorGUILayout.EndHorizontal();
            EditorGUILayout.BeginVertical();
            _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos);

            for (int i = table.StartRow; i < table.RowCount; i++)
            {
                RowStateObj _row = table.Rows[i];
                DrawRow(_row);
            }
            EditorGUILayout.EndVertical();
            EditorGUILayout.EndScrollView();
        }