diff --git a/Assets/QuickSheet/Editor/BaseMachineEditor.cs b/Assets/QuickSheet/Editor/BaseMachineEditor.cs index 91433ef..80fa36f 100644 --- a/Assets/QuickSheet/Editor/BaseMachineEditor.cs +++ b/Assets/QuickSheet/Editor/BaseMachineEditor.cs @@ -7,9 +7,10 @@ /////////////////////////////////////////////////////////////////////////////// using UnityEngine; using UnityEditor; +using System; +using System.IO; using System.Collections; using System.Collections.Generic; -using System.IO; namespace UnityQuickSheet { @@ -28,6 +29,21 @@ protected virtual void Import(bool reimport = false) Debug.LogWarning("!!! It should be implemented in the derived class !!!"); } + /// + /// Check the given header column has valid name which should not be any c# keywords. + /// + protected bool IsValidHeader(string s) + { + // no case sensitive! + string comp = s.ToLower(); + + string found = Array.Find(Util.Keywords, x => x == comp); + if (string.IsNullOrEmpty(found)) + return true; + + return false; + } + /// /// Generate script files with the given templates. /// Total four files are generated, two for runtime and others for editor. diff --git a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelMachineEditor.cs b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelMachineEditor.cs index 518e0ae..30fe084 100644 --- a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelMachineEditor.cs +++ b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelMachineEditor.cs @@ -207,13 +207,28 @@ protected override void Import(bool reimport = false) ); return; } + + int startRowIndex = 0; string error = string.Empty; - var titles = new ExcelQuery(path, sheet).GetTitle(0, ref error); + var titles = new ExcelQuery(path, sheet).GetTitle(startRowIndex, ref error); if (titles == null || !string.IsNullOrEmpty(error)) { EditorUtility.DisplayDialog("Error", error, "OK"); return; } + else + { + // check the column header is valid + foreach(string column in titles) + { + if (!IsValidHeader(column)) + { + error = string.Format(@"Invalid column header name {0}. Any c# keyword should not be used for column header. Note it is not case sensitive.", column); + EditorUtility.DisplayDialog("Error", error, "OK"); + return; + } + } + } List titleList = titles.ToList(); @@ -221,17 +236,17 @@ protected override void Import(bool reimport = false) { var headerDic = machine.HeaderColumnList.ToDictionary(header => header.name); - // collect non changed header columns + // collect non-changed column headers var exist = from t in titleList where headerDic.ContainsKey(t) == true - select new HeaderColumn { name = t, type = headerDic[t].type, OrderNO = headerDic[t].OrderNO }; + select new HeaderColumn { name = t, type = headerDic[t].type, isArray = headerDic[t].isArray, OrderNO = headerDic[t].OrderNO }; - // collect newly added or changed header columns + // collect newly added or changed column headers var changed = from t in titleList where headerDic.ContainsKey(t) == false select new HeaderColumn { name = t, type = CellType.Undefined, OrderNO = titleList.IndexOf(t) }; - // merge two + // merge two list via LINQ var merged = exist.Union(changed).OrderBy(x => x.OrderNO); machine.HeaderColumnList.Clear(); diff --git a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelQuery.cs b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelQuery.cs index c12a8b4..014cf02 100644 --- a/Assets/QuickSheet/ExcelPlugin/Editor/ExcelQuery.cs +++ b/Assets/QuickSheet/ExcelPlugin/Editor/ExcelQuery.cs @@ -219,13 +219,8 @@ public string[] GetTitle(int start, ref string error) } else { - if (IsValidHeader(value)) - result.Add(value); - else - { - error = string.Format(@"Error at column {0}, {1} is invalid name as header column.", i, value); - return null; - } + // column header is not an empty string, we check its validation later. + result.Add(value); } } @@ -236,21 +231,6 @@ public string[] GetTitle(int start, ref string error) return null; } - /// - /// Check the given header column has valid name which should not be any c# keywords. - /// - private bool IsValidHeader(string s) - { - // no case sensitive! - string comp = s.ToLower(); - - string found = Array.Find(Util.Keywords, x => x == comp); - if (string.IsNullOrEmpty(found)) - return true; - - return false; - } - /// /// Convert type of cell value to its predefined type in the sheet's ScriptMachine setting file. /// diff --git a/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs b/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs index 21f25e1..a4111fc 100644 --- a/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs +++ b/Assets/QuickSheet/GDataPlugin/Editor/GoogleMachineEditor.cs @@ -220,6 +220,14 @@ protected override void Import(bool reimport = false) if (int.Parse(m.Value) > 1) return; + // check the column header is valid + if (!IsValidHeader(cell.Value)) + { + string error = string.Format(@"Invalid column header name {0}. Any c# keyword should not be used for column header. Note it is not case sensitive.", cell.Value); + EditorUtility.DisplayDialog("Error", error, "OK"); + return; + } + HeaderColumn column = new HeaderColumn(); column.name = cell.Value; if (headerDic != null && headerDic.ContainsKey(cell.Value))