├── .gitignore ├── ExcelToJsonConverter ├── ExcelDataReader.meta ├── ExcelDataReader │ ├── Excel.dll │ ├── Excel.dll.meta │ ├── LICENSE │ └── LICENSE.meta ├── ExcelToJsonConverter.cs ├── ExcelToJsonConverter.cs.meta ├── ExcelToJsonConverterWindow.cs ├── ExcelToJsonConverterWindow.cs.meta ├── Json.meta ├── Json │ ├── Newtonsoft.Json.dll │ ├── Newtonsoft.Json.dll.meta │ ├── license.txt │ └── license.txt.meta ├── Mono.meta └── Mono │ ├── System.Data.dll │ └── System.Data.dll.meta ├── ExcelToJsonConveterExample ├── Assets │ ├── Editor.meta │ ├── Editor │ │ ├── BuildScript.cs │ │ ├── BuildScript.cs.meta │ │ ├── ExcelToJsonConverter.meta │ │ └── ExcelToJsonConverter │ │ │ ├── ExcelDataReader.meta │ │ │ ├── ExcelDataReader │ │ │ ├── Excel.dll │ │ │ ├── Excel.dll.meta │ │ │ ├── LICENSE │ │ │ └── LICENSE.meta │ │ │ ├── ExcelToJsonConverter.cs │ │ │ ├── ExcelToJsonConverter.cs.meta │ │ │ ├── ExcelToJsonConverterWindow.cs │ │ │ ├── ExcelToJsonConverterWindow.cs.meta │ │ │ ├── Json.meta │ │ │ ├── Json │ │ │ ├── Newtonsoft.Json.dll │ │ │ ├── Newtonsoft.Json.dll.meta │ │ │ ├── license.txt │ │ │ └── license.txt.meta │ │ │ ├── Mono.meta │ │ │ └── Mono │ │ │ ├── System.Data.dll │ │ │ └── System.Data.dll.meta │ ├── Excel.meta │ ├── Excel │ │ ├── Character1997Format.xls │ │ ├── Character1997Format.xls.meta │ │ ├── Character2007Format.xlsx │ │ ├── Character2007Format.xlsx.meta │ │ ├── TestMultipleSheets.xlsx │ │ └── TestMultipleSheets.xlsx.meta │ ├── Resources.meta │ └── Resources │ │ ├── Json.meta │ │ └── Json │ │ ├── CharacterSheet1997Format.json │ │ ├── CharacterSheet1997Format.json.meta │ │ ├── CharacterSheet2007Format.json │ │ ├── CharacterSheet2007Format.json.meta │ │ ├── TestSheet1.json │ │ ├── TestSheet1.json.meta │ │ ├── TestSheet3.json │ │ └── TestSheet3.json.meta └── ProjectSettings │ ├── AudioManager.asset │ ├── DynamicsManager.asset │ ├── EditorBuildSettings.asset │ ├── EditorSettings.asset │ ├── GraphicsSettings.asset │ ├── InputManager.asset │ ├── NavMeshAreas.asset │ ├── NetworkManager.asset │ ├── Physics2DSettings.asset │ ├── ProjectSettings.asset │ ├── ProjectVersion.txt │ ├── QualitySettings.asset │ ├── TagManager.asset │ └── TimeManager.asset ├── LICENSE └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.csproj 2 | *.pidb 3 | *.sln 4 | *.userprefs 5 | Library 6 | Builds 7 | Assembly-CSharp-Editor-vs.csproj 8 | Assembly-CSharp-Editor.csproj 9 | Assembly-CSharp-Editor.pidb 10 | Assembly-CSharp-firstpass-vs.csproj 11 | Assembly-CSharp-firstpass.csproj 12 | Assembly-CSharp-firstpass.pidb 13 | Assembly-CSharp-vs.csproj 14 | Assembly-CSharp.csproj 15 | Assembly-CSharp.pidb 16 | Assembly-UnityScript-firstpass-vs.unityproj 17 | Assembly-UnityScript-firstpass.pidb 18 | Assembly-UnityScript-firstpass.unityproj 19 | Assembly-UnityScript-vs.unityproj 20 | Assembly-UnityScript.pidb 21 | Assembly-UnityScript.unityproj 22 | ~$* -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelDataReader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 056ce2baf991b4da0a5dd83b19dff1b2 3 | folderAsset: yes 4 | timeCreated: 1437325404 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelDataReader/Excel.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConverter/ExcelDataReader/Excel.dll -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelDataReader/Excel.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e4c6323b19bf4e068e844650257783a 3 | timeCreated: 1434249721 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 1 13 | settings: {} 14 | Editor: 15 | enabled: 0 16 | settings: 17 | DefaultValueInitialized: true 18 | userData: 19 | assetBundleName: 20 | assetBundleVariant: 21 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelDataReader/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 ExcelDataReader 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelDataReader/LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02802cd5093dd45b88abdcd07dc0b883 3 | timeCreated: 1434249720 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelToJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.IO; 4 | using System.Data; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using Excel; 8 | using Newtonsoft.Json; 9 | using System.Text.RegularExpressions; 10 | 11 | public class ExcelToJsonConverter 12 | { 13 | public delegate void ConversionToJsonSuccessfullHandler(); 14 | public event ConversionToJsonSuccessfullHandler ConversionToJsonSuccessfull = delegate {}; 15 | 16 | public delegate void ConversionToJsonFailedHandler(); 17 | public event ConversionToJsonFailedHandler ConversionToJsonFailed = delegate {}; 18 | 19 | /// 20 | /// Converts all excel files in the input folder to json and saves them in the output folder. 21 | /// Each sheet within an excel file is saved to a separate json file with the same name as the sheet name. 22 | /// Files, sheets and columns whose name begin with '~' are ignored. 23 | /// 24 | /// Input path. 25 | /// Output path. 26 | /// If set to true, will only process recently modified files only. 27 | public void ConvertExcelFilesToJson(string inputPath, string outputPath, bool recentlyModifiedOnly = false) 28 | { 29 | List excelFiles = GetExcelFileNamesInDirectory(inputPath); 30 | Debug.Log("Excel To Json Converter: " + excelFiles.Count.ToString() + " excel files found."); 31 | 32 | if (recentlyModifiedOnly) 33 | { 34 | excelFiles = RemoveUnmodifiedFilesFromProcessList(excelFiles, outputPath); 35 | 36 | if (excelFiles.Count == 0) 37 | { 38 | Debug.Log("Excel To Json Converter: No updates to excel files since last conversion."); 39 | } 40 | else 41 | { 42 | Debug.Log("Excel To Json Converter: " + excelFiles.Count.ToString() + " excel files updated/added since last conversion."); 43 | } 44 | } 45 | 46 | bool succeeded = true; 47 | 48 | for (int i = 0 ; i < excelFiles.Count; i++) 49 | { 50 | if (!ConvertExcelFileToJson(excelFiles[i], outputPath)) 51 | { 52 | succeeded = false; 53 | break; 54 | } 55 | } 56 | 57 | if (succeeded) 58 | { 59 | ConversionToJsonSuccessfull(); 60 | } 61 | else 62 | { 63 | ConversionToJsonFailed(); 64 | } 65 | } 66 | 67 | /// 68 | /// Gets all the file names in the specified directory 69 | /// 70 | /// The excel file names in directory. 71 | /// Directory. 72 | private List GetExcelFileNamesInDirectory(string directory) 73 | { 74 | string[] directoryFiles = Directory.GetFiles(directory); 75 | List excelFiles = new List(); 76 | 77 | // Regular expression to match against 2 excel file types (xls & xlsx), ignoring 78 | // files with extension .meta and starting with ~$ (temp file created by excel when fie 79 | Regex excelRegex = new Regex(@"^((?!(~\$)).*\.(xlsx|xls$))$"); 80 | 81 | for (int i = 0; i < directoryFiles.Length; i++) 82 | { 83 | string fileName = directoryFiles[i].Substring(directoryFiles[i].LastIndexOf('/') + 1); 84 | 85 | if (excelRegex.IsMatch(fileName)) 86 | { 87 | excelFiles.Add(directoryFiles[i]); 88 | } 89 | } 90 | 91 | return excelFiles; 92 | } 93 | 94 | /// 95 | /// Converts each sheet in the specified excel file to json and saves them in the output folder. 96 | /// The name of the processed json file will match the name of the excel sheet. Ignores 97 | /// sheets whose name begin with '~'. Also ignores columns whose names begin with '~'. 98 | /// 99 | /// true, if excel file was successfully converted to json, false otherwise. 100 | /// File path. 101 | /// Output path. 102 | public bool ConvertExcelFileToJson(string filePath, string outputPath) 103 | { 104 | Debug.Log("Excel To Json Converter: Processing: " + filePath); 105 | DataSet excelData = GetExcelDataSet(filePath); 106 | 107 | if (excelData == null) 108 | { 109 | Debug.LogError("Excel To Json Converter: Failed to process file: " + filePath); 110 | return false; 111 | } 112 | 113 | string spreadSheetJson = ""; 114 | 115 | // Process Each SpreadSheet in the excel file 116 | for (int i = 0; i < excelData.Tables.Count; i++) 117 | { 118 | spreadSheetJson = GetSpreadSheetJson(excelData, excelData.Tables[i].TableName); 119 | if (String.IsNullOrEmpty(spreadSheetJson)) 120 | { 121 | Debug.LogError("Excel To Json Converter: Failed to covert Spreadsheet '" + excelData.Tables[i].TableName + "' to json."); 122 | return false; 123 | } 124 | else 125 | { 126 | // The file name is the sheet name with spaces removed 127 | string fileName = excelData.Tables[i].TableName.Replace(" ", string.Empty); 128 | WriteTextToFile(spreadSheetJson, outputPath + "/" + fileName + ".json"); 129 | Debug.Log("Excel To Json Converter: " + excelData.Tables[i].TableName + " successfully written to file."); 130 | } 131 | } 132 | 133 | return true; 134 | } 135 | 136 | /// 137 | /// Gets the excel data reader for the specified file. 138 | /// 139 | /// The excel data reader for file or null if file type is invalid. 140 | /// File path. 141 | private IExcelDataReader GetExcelDataReaderForFile(string filePath) 142 | { 143 | FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read); 144 | 145 | // Create the excel data reader 146 | IExcelDataReader excelReader; 147 | 148 | // Create regular expressions to detect the type of excel file 149 | Regex xlsRegex = new Regex(@"^(.*\.(xls$))"); 150 | Regex xlsxRegex = new Regex(@"^(.*\.(xlsx$))"); 151 | 152 | // Read the excel file depending on it's type 153 | if (xlsRegex.IsMatch(filePath)) 154 | { 155 | // Reading from a binary Excel file ('97-2003 format; *.xls) 156 | excelReader = ExcelReaderFactory.CreateBinaryReader(stream); 157 | } 158 | else if (xlsxRegex.IsMatch(filePath)) 159 | { 160 | // Reading from a OpenXml Excel file (2007 format; *.xlsx) 161 | excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); 162 | } 163 | else 164 | { 165 | Debug.LogError("Excel To Json Converter: Unexpected files type: " + filePath); 166 | stream.Close(); 167 | return null; 168 | } 169 | 170 | // Close the stream 171 | stream.Close(); 172 | 173 | // First row are columns names 174 | excelReader.IsFirstRowAsColumnNames = true; 175 | 176 | return excelReader; 177 | } 178 | 179 | /// 180 | /// Gets the Excel data from the specified file 181 | /// 182 | /// The excel data set or null if file is invalid. 183 | /// File path. 184 | private DataSet GetExcelDataSet(string filePath) 185 | { 186 | // Get the excel data reader with the excel data 187 | IExcelDataReader excelReader = GetExcelDataReaderForFile(filePath); 188 | 189 | if (excelReader == null) 190 | { 191 | return null; 192 | } 193 | 194 | // Get the data from the excel file 195 | DataSet data = new DataSet(); 196 | 197 | do 198 | { 199 | // Get the DataTable from the current spreadsheet 200 | DataTable table = GetExcelSheetData(excelReader); 201 | 202 | if (table != null) 203 | { 204 | // Add the table to the data set 205 | data.Tables.Add(table); 206 | } 207 | } 208 | while(excelReader.NextResult()); // Read the next sheet 209 | 210 | return data; 211 | } 212 | 213 | /// 214 | /// Gets the Excel data from current spreadsheet 215 | /// 216 | /// The spreadsheet data table. 217 | /// Excel Reader. 218 | private DataTable GetExcelSheetData(IExcelDataReader excelReader) 219 | { 220 | if (excelReader == null) 221 | { 222 | Debug.LogError("Excel To Json Converter: Excel Reader is null. Cannot read data"); 223 | return null; 224 | } 225 | 226 | // Ignore sheets which start with ~ 227 | Regex sheetNameRegex = new Regex(@"^~.*$"); 228 | if (sheetNameRegex.IsMatch(excelReader.Name)) 229 | { 230 | return null; 231 | } 232 | 233 | // Create the table with the spreadsheet name 234 | DataTable table = new DataTable(excelReader.Name); 235 | table.Clear(); 236 | 237 | string value = ""; 238 | bool rowIsEmpty; 239 | 240 | // Read the rows and columns 241 | while (excelReader.Read()) 242 | { 243 | DataRow row = table.NewRow(); 244 | rowIsEmpty = true; 245 | 246 | for (int i = 0; i < excelReader.FieldCount; i++) 247 | { 248 | // If the column is null and this is the first row, skip 249 | // to next iteration (do not want to include empty columns) 250 | if (excelReader.IsDBNull(i) && 251 | (excelReader.Depth == 1 || i > table.Columns.Count - 1)) 252 | { 253 | continue; 254 | } 255 | 256 | value = excelReader.IsDBNull(i) ? "" : excelReader.GetString(i); 257 | 258 | // If this is the first row, add the values as columns 259 | if (excelReader.Depth == 1) 260 | { 261 | table.Columns.Add(value); 262 | } 263 | else // Otherwise, add as rows 264 | { 265 | row[table.Columns[i]] = value; 266 | } 267 | 268 | if (!string.IsNullOrEmpty(value)) 269 | { 270 | rowIsEmpty = false; 271 | } 272 | } 273 | 274 | // Add the row to the table if it was not column headers and 275 | // the row was not empty 276 | if (excelReader.Depth != 1 && !rowIsEmpty) 277 | { 278 | table.Rows.Add(row); 279 | } 280 | } 281 | 282 | return table; 283 | } 284 | 285 | /// 286 | /// Gets the json data for the specified spreadsheet in the specified DataSet 287 | /// 288 | /// The spread sheet json. 289 | /// Excel data set. 290 | /// Sheet name. 291 | private string GetSpreadSheetJson(DataSet excelDataSet, string sheetName) 292 | { 293 | // Get the specified table 294 | DataTable dataTable = excelDataSet.Tables[sheetName]; 295 | 296 | // Remove empty columns 297 | for (int col = dataTable.Columns.Count - 1; col >= 0; col--) 298 | { 299 | bool removeColumn = true; 300 | foreach (DataRow row in dataTable.Rows) 301 | { 302 | if (!row.IsNull(col)) 303 | { 304 | removeColumn = false; 305 | break; 306 | } 307 | } 308 | 309 | if (removeColumn) 310 | { 311 | dataTable.Columns.RemoveAt(col); 312 | } 313 | } 314 | 315 | // Remove columns which start with '~' 316 | Regex columnNameRegex = new Regex(@"^~.*$"); 317 | for (int i = dataTable.Columns.Count - 1; i >= 0; i--) 318 | { 319 | if (columnNameRegex.IsMatch(dataTable.Columns[i].ColumnName)) 320 | { 321 | dataTable.Columns.RemoveAt(i); 322 | } 323 | } 324 | 325 | // Serialze the data table to json string 326 | return Newtonsoft.Json.JsonConvert.SerializeObject(dataTable); 327 | } 328 | 329 | /// 330 | /// Writes the specified text to the specified file, overwriting it. 331 | /// Creates file if it does not exist. 332 | /// 333 | /// Text. 334 | /// File path. 335 | private void WriteTextToFile(string text, string filePath) 336 | { 337 | System.IO.File.WriteAllText(filePath, text); 338 | } 339 | 340 | /// 341 | /// Removes files which have not been modified since they were last processed 342 | /// from the process list 343 | /// 344 | /// Excel files. 345 | private List RemoveUnmodifiedFilesFromProcessList(List excelFiles, string outputDirectory) 346 | { 347 | List sheetNames; 348 | bool removeFile = true; 349 | 350 | // ignore sheets whose name starts with '~' 351 | Regex sheetNameRegex = new Regex(@"^~.*$"); 352 | 353 | for (int i = excelFiles.Count - 1; i >= 0; i--) 354 | { 355 | sheetNames = GetSheetNamesInFile(excelFiles[i]); 356 | removeFile = true; 357 | 358 | for (int j = 0; j < sheetNames.Count; j++) 359 | { 360 | if (sheetNameRegex.IsMatch(sheetNames[j])) 361 | { 362 | continue; 363 | } 364 | 365 | string outputFile = outputDirectory + "/" + sheetNames[j] + ".json"; 366 | if (!File.Exists(outputFile) || 367 | File.GetLastWriteTimeUtc(excelFiles[i]) > File.GetLastWriteTimeUtc(outputFile)) 368 | { 369 | removeFile = false; 370 | } 371 | } 372 | 373 | if (removeFile) 374 | { 375 | excelFiles.RemoveAt(i); 376 | } 377 | } 378 | 379 | return excelFiles; 380 | } 381 | 382 | /// 383 | /// Gets the list of sheet names in the specified excel file 384 | /// 385 | /// The sheet names in file. 386 | /// File path. 387 | private List GetSheetNamesInFile(string filePath) 388 | { 389 | List sheetNames = new List(); 390 | 391 | // Get the excel data reader with the excel data 392 | IExcelDataReader excelReader = GetExcelDataReaderForFile(filePath); 393 | 394 | if (excelReader == null) 395 | { 396 | return sheetNames; 397 | } 398 | 399 | do 400 | { 401 | // Add the sheet name to the list 402 | sheetNames.Add(excelReader.Name); 403 | } 404 | while(excelReader.NextResult()); // Read the next sheet 405 | 406 | return sheetNames; 407 | } 408 | } 409 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelToJsonConverter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 33bb6cd6343e34626a1bb97290c4276d 3 | timeCreated: 1437325512 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelToJsonConverterWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.IO; 5 | 6 | public class ExcelToJsonConverterWindow : EditorWindow 7 | { 8 | public static string kExcelToJsonConverterInputPathPrefsName = "ExcelToJson.InputPath"; 9 | public static string kExcelToJsonConverterOuputPathPrefsName = "ExcelToJson.OutputPath"; 10 | public static string kExcelToJsonConverterModifiedFilesOnlyPrefsName = "ExcelToJson.OnlyModifiedFiles"; 11 | 12 | private string _inputPath; 13 | private string _outputPath; 14 | private bool _onlyModifiedFiles; 15 | 16 | private ExcelToJsonConverter _excelProcessor; 17 | 18 | [MenuItem ("Tools/Excel To Json Converter")] 19 | public static void ShowWindow() 20 | { 21 | EditorWindow.GetWindow(typeof(ExcelToJsonConverterWindow), true, "Excel To Json Converter", true); 22 | } 23 | 24 | public void OnEnable() 25 | { 26 | if (_excelProcessor == null) 27 | { 28 | _excelProcessor = new ExcelToJsonConverter(); 29 | } 30 | 31 | _inputPath = EditorPrefs.GetString(kExcelToJsonConverterInputPathPrefsName, Application.dataPath); 32 | _outputPath = EditorPrefs.GetString(kExcelToJsonConverterOuputPathPrefsName, Application.dataPath); 33 | _onlyModifiedFiles = EditorPrefs.GetBool(kExcelToJsonConverterModifiedFilesOnlyPrefsName, false); 34 | } 35 | 36 | public void OnDisable() 37 | { 38 | EditorPrefs.SetString(kExcelToJsonConverterInputPathPrefsName, _inputPath); 39 | EditorPrefs.SetString(kExcelToJsonConverterOuputPathPrefsName, _outputPath); 40 | EditorPrefs.SetBool(kExcelToJsonConverterModifiedFilesOnlyPrefsName, _onlyModifiedFiles); 41 | } 42 | 43 | void OnGUI() 44 | { 45 | GUILayout.BeginHorizontal(); 46 | 47 | GUIContent inputFolderContent = new GUIContent("Input Folder", "Select the folder where the excel files to be processed are located."); 48 | EditorGUIUtility.labelWidth = 120.0f; 49 | EditorGUILayout.TextField(inputFolderContent, _inputPath, GUILayout.MinWidth(120), GUILayout.MaxWidth(500)); 50 | if (GUILayout.Button(new GUIContent("Select Folder"), GUILayout.MinWidth(80), GUILayout.MaxWidth(100))) 51 | { 52 | _inputPath = EditorUtility.OpenFolderPanel("Select Folder with Excel Files", _inputPath, Application.dataPath); 53 | } 54 | 55 | GUILayout.EndHorizontal(); 56 | 57 | GUILayout.BeginHorizontal(); 58 | 59 | GUIContent outputFolderContent = new GUIContent("Output Folder", "Select the folder where the converted json files should be saved."); 60 | EditorGUILayout.TextField(outputFolderContent, _outputPath, GUILayout.MinWidth(120), GUILayout.MaxWidth(500)); 61 | if (GUILayout.Button(new GUIContent("Select Folder"), GUILayout.MinWidth(80), GUILayout.MaxWidth(100))) 62 | { 63 | _outputPath = EditorUtility.OpenFolderPanel("Select Folder to save json files", _outputPath, Application.dataPath); 64 | } 65 | 66 | GUILayout.EndHorizontal(); 67 | 68 | GUIContent modifiedToggleContent = new GUIContent("Modified Files Only", "If checked, only excel files which have been newly added or updated since the last conversion will be processed."); 69 | _onlyModifiedFiles = EditorGUILayout.Toggle(modifiedToggleContent, _onlyModifiedFiles); 70 | 71 | if (string.IsNullOrEmpty(_inputPath) || string.IsNullOrEmpty(_outputPath)) 72 | { 73 | GUI.enabled = false; 74 | } 75 | 76 | GUILayout.BeginArea(new Rect((Screen.width / 2) - (200 / 2), (Screen.height / 2) - (25 / 2), 200, 25)); 77 | 78 | if (GUILayout.Button("Convert Excel Files")) 79 | { 80 | _excelProcessor.ConvertExcelFilesToJson(_inputPath, _outputPath, _onlyModifiedFiles); 81 | } 82 | 83 | GUILayout.EndArea(); 84 | 85 | GUI.enabled = true; 86 | } 87 | } 88 | 89 | [InitializeOnLoad] 90 | public class ExcelToJsonAutoConverter 91 | { 92 | /// 93 | /// Class attribute [InitializeOnLoad] triggers calling the static constructor on every refresh. 94 | /// 95 | static ExcelToJsonAutoConverter() 96 | { 97 | string inputPath = EditorPrefs.GetString(ExcelToJsonConverterWindow.kExcelToJsonConverterInputPathPrefsName, Application.dataPath); 98 | string outputPath = EditorPrefs.GetString(ExcelToJsonConverterWindow.kExcelToJsonConverterOuputPathPrefsName, Application.dataPath); 99 | bool onlyModifiedFiles = EditorPrefs.GetBool(ExcelToJsonConverterWindow.kExcelToJsonConverterModifiedFilesOnlyPrefsName, false); 100 | 101 | ExcelToJsonConverter excelProcessor = new ExcelToJsonConverter(); 102 | excelProcessor.ConvertExcelFilesToJson(inputPath, outputPath, onlyModifiedFiles); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/ExcelToJsonConverterWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea23e13965a82471e9cc17c0bf2c5818 3 | timeCreated: 1435495530 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/Json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4913cccc9c26842b88edfcdcc5609be3 3 | folderAsset: yes 4 | timeCreated: 1437325404 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/Json/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConverter/Json/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /ExcelToJsonConverter/Json/Newtonsoft.Json.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7bb4d177a821c42a08552d175e80894a 3 | timeCreated: 1434249722 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 1 13 | settings: {} 14 | Editor: 15 | enabled: 0 16 | settings: 17 | DefaultValueInitialized: true 18 | userData: 19 | assetBundleName: 20 | assetBundleVariant: 21 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/Json/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 James Newton-King 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | software and associated documentation files (the "Software"), to deal in the Software 5 | without restriction, including without limitation the rights to use, copy, modify, 6 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | permit persons to whom the Software is furnished to do so, subject to the following 8 | conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies 11 | or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 17 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 18 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /ExcelToJsonConverter/Json/license.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a991a2f06af394d98b5bb6df8ff087f3 3 | timeCreated: 1434249725 4 | licenseType: Free 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/Mono.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3859a04de77c4436e8fd79c621a2d502 3 | folderAsset: yes 4 | timeCreated: 1437325404 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConverter/Mono/System.Data.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConverter/Mono/System.Data.dll -------------------------------------------------------------------------------- /ExcelToJsonConverter/Mono/System.Data.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e633a76adcb1450187a82a55edbe190 3 | timeCreated: 1434249725 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 1 13 | settings: {} 14 | Editor: 15 | enabled: 0 16 | settings: 17 | DefaultValueInitialized: true 18 | userData: 19 | assetBundleName: 20 | assetBundleVariant: 21 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 727a0939c10884f8abee64df3c51d6e9 3 | folderAsset: yes 4 | timeCreated: 1437326351 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/BuildScript.cs: -------------------------------------------------------------------------------- 1 | using UnityEditor; 2 | using UnityEngine; 3 | using System; 4 | using System.Diagnostics; 5 | using System.Collections.Generic; 6 | 7 | public class ScriptBatch 8 | { 9 | private static Action _excelSuccessCallback; 10 | private static BuildOptions _buildOptions; 11 | 12 | [MenuItem("MyTools/IOS Release Build")] 13 | public static void PerformIOSReleaseBuild() 14 | { 15 | _excelSuccessCallback = DoIOSReleaseBuild; 16 | 17 | _buildOptions = BuildOptions.Il2CPP; 18 | 19 | // Process the Excel Files 20 | ProcessExcelFiles(); 21 | } 22 | 23 | [MenuItem("MyTools/IOS Release Build & Run")] 24 | public static void PerformIOSReleaseBuildAndRun() 25 | { 26 | _excelSuccessCallback = DoIOSReleaseBuild; 27 | 28 | _buildOptions = BuildOptions.Il2CPP | BuildOptions.AutoRunPlayer; 29 | 30 | // Process the Excel Files 31 | ProcessExcelFiles(); 32 | } 33 | 34 | /// 35 | /// Performs the iOS Release Build 36 | /// 37 | private static void DoIOSReleaseBuild() 38 | { 39 | // Get filename. 40 | string path = EditorUtility.SaveFolderPanel("Choose Location of Built Game", "", ""); 41 | if (string.IsNullOrEmpty(path)) 42 | { 43 | return; 44 | } 45 | 46 | // Build player. 47 | BuildPipeline.BuildPlayer(GetEnabledBuildScenes(), path, BuildTarget.iOS, _buildOptions); 48 | 49 | // Run the game (Process class from System.Diagnostics). 50 | Process proc = new Process(); 51 | proc.StartInfo.FileName = path; 52 | proc.Start(); 53 | } 54 | 55 | [MenuItem("MyTools/IOS Debug Build")] 56 | public static void PerformIOSDebugBuild() 57 | { 58 | _excelSuccessCallback = DoIOSDebugBuild; 59 | 60 | _buildOptions = BuildOptions.Il2CPP | BuildOptions.Development | BuildOptions.AllowDebugging | BuildOptions.SymlinkLibraries; 61 | 62 | // Process the Excel Files 63 | ProcessExcelFiles(); 64 | } 65 | 66 | [MenuItem("MyTools/IOS Debug Build & Run")] 67 | public static void PerformIOSDebugBuildAndRun() 68 | { 69 | _excelSuccessCallback = DoIOSDebugBuild; 70 | 71 | _buildOptions = BuildOptions.Il2CPP | BuildOptions.Development | 72 | BuildOptions.AllowDebugging | BuildOptions.SymlinkLibraries | BuildOptions.AutoRunPlayer; 73 | 74 | // Process the Excel Files 75 | ProcessExcelFiles(); 76 | } 77 | 78 | /// 79 | /// Performs the iOS Debug Build 80 | /// 81 | private static void DoIOSDebugBuild() 82 | { 83 | // Get filename. 84 | string path = EditorUtility.SaveFolderPanel("Choose Location of Built Game", "", ""); 85 | if (string.IsNullOrEmpty(path)) 86 | { 87 | return; 88 | } 89 | 90 | // Build player. 91 | BuildPipeline.BuildPlayer(GetEnabledBuildScenes(), path, BuildTarget.iOS, _buildOptions); 92 | 93 | // Run the game (Process class from System.Diagnostics). 94 | Process proc = new Process(); 95 | proc.StartInfo.FileName = path; 96 | proc.Start(); 97 | } 98 | 99 | /// 100 | /// Gets the list of enabled scenes that are added to the build settings 101 | /// via the Build Settings window 102 | /// 103 | /// The enabled build scenes. 104 | private static string[] GetEnabledBuildScenes() 105 | { 106 | List scenes = new List(EditorBuildSettings.scenes); 107 | List enabledScenes = new List(); 108 | foreach (EditorBuildSettingsScene scene in scenes) 109 | { 110 | if (scene.enabled) 111 | { 112 | enabledScenes.Add(scene.path); 113 | } 114 | } 115 | 116 | return enabledScenes.ToArray(); 117 | } 118 | 119 | /// 120 | /// Processes the excel files. 121 | /// 122 | private static void ProcessExcelFiles() 123 | { 124 | ExcelToJsonConverter excelProcessor = new ExcelToJsonConverter(); 125 | excelProcessor.ConversionToJsonSuccessfull += ExcelSuccessCallback; 126 | excelProcessor.ConvertExcelFilesToJson(EditorPrefs.GetString(ExcelToJsonConverterWindow.kExcelToJsonConverterInputPathPrefsName, Application.dataPath), 127 | EditorPrefs.GetString(ExcelToJsonConverterWindow.kExcelToJsonConverterOuputPathPrefsName, Application.dataPath), 128 | false); 129 | } 130 | 131 | /// 132 | /// Callback method for Processing Excel sheets 133 | /// 134 | private static void ExcelSuccessCallback() 135 | { 136 | if (_excelSuccessCallback != null) 137 | { 138 | _excelSuccessCallback(); 139 | _excelSuccessCallback = null; 140 | } 141 | } 142 | } -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/BuildScript.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3ce6e9718c6b944c7bcc4292071cd77f 3 | timeCreated: 1437326351 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 624e66c03413a44b4bf1b7bc6e5d780d 3 | folderAsset: yes 4 | timeCreated: 1437326351 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelDataReader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 056ce2baf991b4da0a5dd83b19dff1b2 3 | folderAsset: yes 4 | timeCreated: 1437325404 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelDataReader/Excel.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelDataReader/Excel.dll -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelDataReader/Excel.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5e4c6323b19bf4e068e844650257783a 3 | timeCreated: 1434249721 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 1 13 | settings: {} 14 | Editor: 15 | enabled: 0 16 | settings: 17 | DefaultValueInitialized: true 18 | userData: 19 | assetBundleName: 20 | assetBundleVariant: 21 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelDataReader/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 ExcelDataReader 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelDataReader/LICENSE.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 02802cd5093dd45b88abdcd07dc0b883 3 | timeCreated: 1434249720 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelToJsonConverter.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System; 3 | using System.IO; 4 | using System.Data; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | using Excel; 8 | using Newtonsoft.Json; 9 | using System.Text.RegularExpressions; 10 | 11 | public class ExcelToJsonConverter 12 | { 13 | public delegate void ConversionToJsonSuccessfullHandler(); 14 | public event ConversionToJsonSuccessfullHandler ConversionToJsonSuccessfull = delegate {}; 15 | 16 | public delegate void ConversionToJsonFailedHandler(); 17 | public event ConversionToJsonFailedHandler ConversionToJsonFailed = delegate {}; 18 | 19 | /// 20 | /// Converts all excel files in the input folder to json and saves them in the output folder. 21 | /// Each sheet within an excel file is saved to a separate json file with the same name as the sheet name. 22 | /// Files, sheets and columns whose name begin with '~' are ignored. 23 | /// 24 | /// Input path. 25 | /// Output path. 26 | /// If set to true, will only process recently modified files only. 27 | public void ConvertExcelFilesToJson(string inputPath, string outputPath, bool recentlyModifiedOnly = false) 28 | { 29 | List excelFiles = GetExcelFileNamesInDirectory(inputPath); 30 | Debug.Log("Excel To Json Converter: " + excelFiles.Count.ToString() + " excel files found."); 31 | 32 | if (recentlyModifiedOnly) 33 | { 34 | excelFiles = RemoveUnmodifiedFilesFromProcessList(excelFiles, outputPath); 35 | 36 | if (excelFiles.Count == 0) 37 | { 38 | Debug.Log("Excel To Json Converter: No updates to excel files since last conversion."); 39 | } 40 | else 41 | { 42 | Debug.Log("Excel To Json Converter: " + excelFiles.Count.ToString() + " excel files updated/added since last conversion."); 43 | } 44 | } 45 | 46 | bool succeeded = true; 47 | 48 | for (int i = 0 ; i < excelFiles.Count; i++) 49 | { 50 | if (!ConvertExcelFileToJson(excelFiles[i], outputPath)) 51 | { 52 | succeeded = false; 53 | break; 54 | } 55 | } 56 | 57 | if (succeeded) 58 | { 59 | ConversionToJsonSuccessfull(); 60 | } 61 | else 62 | { 63 | ConversionToJsonFailed(); 64 | } 65 | } 66 | 67 | /// 68 | /// Gets all the file names in the specified directory 69 | /// 70 | /// The excel file names in directory. 71 | /// Directory. 72 | private List GetExcelFileNamesInDirectory(string directory) 73 | { 74 | string[] directoryFiles = Directory.GetFiles(directory); 75 | List excelFiles = new List(); 76 | 77 | // Regular expression to match against 2 excel file types (xls & xlsx), ignoring 78 | // files with extension .meta and starting with ~$ (temp file created by excel when fie 79 | Regex excelRegex = new Regex(@"^((?!(~\$)).*\.(xlsx|xls$))$"); 80 | 81 | for (int i = 0; i < directoryFiles.Length; i++) 82 | { 83 | string fileName = directoryFiles[i].Substring(directoryFiles[i].LastIndexOf('/') + 1); 84 | 85 | if (excelRegex.IsMatch(fileName)) 86 | { 87 | excelFiles.Add(directoryFiles[i]); 88 | } 89 | } 90 | 91 | return excelFiles; 92 | } 93 | 94 | /// 95 | /// Converts each sheet in the specified excel file to json and saves them in the output folder. 96 | /// The name of the processed json file will match the name of the excel sheet. Ignores 97 | /// sheets whose name begin with '~'. Also ignores columns whose names begin with '~'. 98 | /// 99 | /// true, if excel file was successfully converted to json, false otherwise. 100 | /// File path. 101 | /// Output path. 102 | public bool ConvertExcelFileToJson(string filePath, string outputPath) 103 | { 104 | Debug.Log("Excel To Json Converter: Processing: " + filePath); 105 | DataSet excelData = GetExcelDataSet(filePath); 106 | 107 | if (excelData == null) 108 | { 109 | Debug.LogError("Excel To Json Converter: Failed to process file: " + filePath); 110 | return false; 111 | } 112 | 113 | string spreadSheetJson = ""; 114 | 115 | // Process Each SpreadSheet in the excel file 116 | for (int i = 0; i < excelData.Tables.Count; i++) 117 | { 118 | spreadSheetJson = GetSpreadSheetJson(excelData, excelData.Tables[i].TableName); 119 | if (String.IsNullOrEmpty(spreadSheetJson)) 120 | { 121 | Debug.LogError("Excel To Json Converter: Failed to covert Spreadsheet '" + excelData.Tables[i].TableName + "' to json."); 122 | return false; 123 | } 124 | else 125 | { 126 | // The file name is the sheet name with spaces removed 127 | string fileName = excelData.Tables[i].TableName.Replace(" ", string.Empty); 128 | WriteTextToFile(spreadSheetJson, outputPath + "/" + fileName + ".json"); 129 | Debug.Log("Excel To Json Converter: " + excelData.Tables[i].TableName + " successfully written to file."); 130 | } 131 | } 132 | 133 | return true; 134 | } 135 | 136 | /// 137 | /// Gets the excel data reader for the specified file. 138 | /// 139 | /// The excel data reader for file or null if file type is invalid. 140 | /// File path. 141 | private IExcelDataReader GetExcelDataReaderForFile(string filePath) 142 | { 143 | FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read); 144 | 145 | // Create the excel data reader 146 | IExcelDataReader excelReader; 147 | 148 | // Create regular expressions to detect the type of excel file 149 | Regex xlsRegex = new Regex(@"^(.*\.(xls$))"); 150 | Regex xlsxRegex = new Regex(@"^(.*\.(xlsx$))"); 151 | 152 | // Read the excel file depending on it's type 153 | if (xlsRegex.IsMatch(filePath)) 154 | { 155 | // Reading from a binary Excel file ('97-2003 format; *.xls) 156 | excelReader = ExcelReaderFactory.CreateBinaryReader(stream); 157 | } 158 | else if (xlsxRegex.IsMatch(filePath)) 159 | { 160 | // Reading from a OpenXml Excel file (2007 format; *.xlsx) 161 | excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream); 162 | } 163 | else 164 | { 165 | Debug.LogError("Excel To Json Converter: Unexpected files type: " + filePath); 166 | stream.Close(); 167 | return null; 168 | } 169 | 170 | // Close the stream 171 | stream.Close(); 172 | 173 | // First row are columns names 174 | excelReader.IsFirstRowAsColumnNames = true; 175 | 176 | return excelReader; 177 | } 178 | 179 | /// 180 | /// Gets the Excel data from the specified file 181 | /// 182 | /// The excel data set or null if file is invalid. 183 | /// File path. 184 | private DataSet GetExcelDataSet(string filePath) 185 | { 186 | // Get the excel data reader with the excel data 187 | IExcelDataReader excelReader = GetExcelDataReaderForFile(filePath); 188 | 189 | if (excelReader == null) 190 | { 191 | return null; 192 | } 193 | 194 | // Get the data from the excel file 195 | DataSet data = new DataSet(); 196 | 197 | do 198 | { 199 | // Get the DataTable from the current spreadsheet 200 | DataTable table = GetExcelSheetData(excelReader); 201 | 202 | if (table != null) 203 | { 204 | // Add the table to the data set 205 | data.Tables.Add(table); 206 | } 207 | } 208 | while(excelReader.NextResult()); // Read the next sheet 209 | 210 | return data; 211 | } 212 | 213 | /// 214 | /// Gets the Excel data from current spreadsheet 215 | /// 216 | /// The spreadsheet data table. 217 | /// Excel Reader. 218 | private DataTable GetExcelSheetData(IExcelDataReader excelReader) 219 | { 220 | if (excelReader == null) 221 | { 222 | Debug.LogError("Excel To Json Converter: Excel Reader is null. Cannot read data"); 223 | return null; 224 | } 225 | 226 | // Ignore sheets which start with ~ 227 | Regex sheetNameRegex = new Regex(@"^~.*$"); 228 | if (sheetNameRegex.IsMatch(excelReader.Name)) 229 | { 230 | return null; 231 | } 232 | 233 | // Create the table with the spreadsheet name 234 | DataTable table = new DataTable(excelReader.Name); 235 | table.Clear(); 236 | 237 | string value = ""; 238 | bool rowIsEmpty; 239 | 240 | // Read the rows and columns 241 | while (excelReader.Read()) 242 | { 243 | DataRow row = table.NewRow(); 244 | rowIsEmpty = true; 245 | 246 | for (int i = 0; i < excelReader.FieldCount; i++) 247 | { 248 | // If the column is null and this is the first row, skip 249 | // to next iteration (do not want to include empty columns) 250 | if (excelReader.IsDBNull(i) && 251 | (excelReader.Depth == 1 || i > table.Columns.Count - 1)) 252 | { 253 | continue; 254 | } 255 | 256 | value = excelReader.IsDBNull(i) ? "" : excelReader.GetString(i); 257 | 258 | // If this is the first row, add the values as columns 259 | if (excelReader.Depth == 1) 260 | { 261 | table.Columns.Add(value); 262 | } 263 | else // Otherwise, add as rows 264 | { 265 | row[table.Columns[i]] = value; 266 | } 267 | 268 | if (!string.IsNullOrEmpty(value)) 269 | { 270 | rowIsEmpty = false; 271 | } 272 | } 273 | 274 | // Add the row to the table if it was not column headers and 275 | // the row was not empty 276 | if (excelReader.Depth != 1 && !rowIsEmpty) 277 | { 278 | table.Rows.Add(row); 279 | } 280 | } 281 | 282 | return table; 283 | } 284 | 285 | /// 286 | /// Gets the json data for the specified spreadsheet in the specified DataSet 287 | /// 288 | /// The spread sheet json. 289 | /// Excel data set. 290 | /// Sheet name. 291 | private string GetSpreadSheetJson(DataSet excelDataSet, string sheetName) 292 | { 293 | // Get the specified table 294 | DataTable dataTable = excelDataSet.Tables[sheetName]; 295 | 296 | // Remove empty columns 297 | for (int col = dataTable.Columns.Count - 1; col >= 0; col--) 298 | { 299 | bool removeColumn = true; 300 | foreach (DataRow row in dataTable.Rows) 301 | { 302 | if (!row.IsNull(col)) 303 | { 304 | removeColumn = false; 305 | break; 306 | } 307 | } 308 | 309 | if (removeColumn) 310 | { 311 | dataTable.Columns.RemoveAt(col); 312 | } 313 | } 314 | 315 | // Remove columns which start with '~' 316 | Regex columnNameRegex = new Regex(@"^~.*$"); 317 | for (int i = dataTable.Columns.Count - 1; i >= 0; i--) 318 | { 319 | if (columnNameRegex.IsMatch(dataTable.Columns[i].ColumnName)) 320 | { 321 | dataTable.Columns.RemoveAt(i); 322 | } 323 | } 324 | 325 | // Serialze the data table to json string 326 | return Newtonsoft.Json.JsonConvert.SerializeObject(dataTable); 327 | } 328 | 329 | /// 330 | /// Writes the specified text to the specified file, overwriting it. 331 | /// Creates file if it does not exist. 332 | /// 333 | /// Text. 334 | /// File path. 335 | private void WriteTextToFile(string text, string filePath) 336 | { 337 | System.IO.File.WriteAllText(filePath, text); 338 | } 339 | 340 | /// 341 | /// Removes files which have not been modified since they were last processed 342 | /// from the process list 343 | /// 344 | /// Excel files. 345 | private List RemoveUnmodifiedFilesFromProcessList(List excelFiles, string outputDirectory) 346 | { 347 | List sheetNames; 348 | bool removeFile = true; 349 | 350 | // ignore sheets whose name starts with '~' 351 | Regex sheetNameRegex = new Regex(@"^~.*$"); 352 | 353 | for (int i = excelFiles.Count - 1; i >= 0; i--) 354 | { 355 | sheetNames = GetSheetNamesInFile(excelFiles[i]); 356 | removeFile = true; 357 | 358 | for (int j = 0; j < sheetNames.Count; j++) 359 | { 360 | if (sheetNameRegex.IsMatch(sheetNames[j])) 361 | { 362 | continue; 363 | } 364 | 365 | string outputFile = outputDirectory + "/" + sheetNames[j] + ".json"; 366 | if (!File.Exists(outputFile) || 367 | File.GetLastWriteTimeUtc(excelFiles[i]) > File.GetLastWriteTimeUtc(outputFile)) 368 | { 369 | removeFile = false; 370 | } 371 | } 372 | 373 | if (removeFile) 374 | { 375 | excelFiles.RemoveAt(i); 376 | } 377 | } 378 | 379 | return excelFiles; 380 | } 381 | 382 | /// 383 | /// Gets the list of sheet names in the specified excel file 384 | /// 385 | /// The sheet names in file. 386 | /// File path. 387 | private List GetSheetNamesInFile(string filePath) 388 | { 389 | List sheetNames = new List(); 390 | 391 | // Get the excel data reader with the excel data 392 | IExcelDataReader excelReader = GetExcelDataReaderForFile(filePath); 393 | 394 | if (excelReader == null) 395 | { 396 | return sheetNames; 397 | } 398 | 399 | do 400 | { 401 | // Add the sheet name to the list 402 | sheetNames.Add(excelReader.Name); 403 | } 404 | while(excelReader.NextResult()); // Read the next sheet 405 | 406 | return sheetNames; 407 | } 408 | } 409 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelToJsonConverter.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 33bb6cd6343e34626a1bb97290c4276d 3 | timeCreated: 1437325512 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelToJsonConverterWindow.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using System.IO; 5 | 6 | public class ExcelToJsonConverterWindow : EditorWindow 7 | { 8 | public static string kExcelToJsonConverterInputPathPrefsName = "ExcelToJson.InputPath"; 9 | public static string kExcelToJsonConverterOuputPathPrefsName = "ExcelToJson.OutputPath"; 10 | public static string kExcelToJsonConverterModifiedFilesOnlyPrefsName = "ExcelToJson.OnlyModifiedFiles"; 11 | 12 | private string _inputPath; 13 | private string _outputPath; 14 | private bool _onlyModifiedFiles; 15 | 16 | private ExcelToJsonConverter _excelProcessor; 17 | 18 | [MenuItem ("Tools/Excel To Json Converter")] 19 | public static void ShowWindow() 20 | { 21 | EditorWindow.GetWindow(typeof(ExcelToJsonConverterWindow), true, "Excel To Json Converter", true); 22 | } 23 | 24 | public void OnEnable() 25 | { 26 | if (_excelProcessor == null) 27 | { 28 | _excelProcessor = new ExcelToJsonConverter(); 29 | } 30 | 31 | _inputPath = EditorPrefs.GetString(kExcelToJsonConverterInputPathPrefsName, Application.dataPath); 32 | _outputPath = EditorPrefs.GetString(kExcelToJsonConverterOuputPathPrefsName, Application.dataPath); 33 | _onlyModifiedFiles = EditorPrefs.GetBool(kExcelToJsonConverterModifiedFilesOnlyPrefsName, false); 34 | } 35 | 36 | public void OnDisable() 37 | { 38 | EditorPrefs.SetString(kExcelToJsonConverterInputPathPrefsName, _inputPath); 39 | EditorPrefs.SetString(kExcelToJsonConverterOuputPathPrefsName, _outputPath); 40 | EditorPrefs.SetBool(kExcelToJsonConverterModifiedFilesOnlyPrefsName, _onlyModifiedFiles); 41 | } 42 | 43 | void OnGUI() 44 | { 45 | GUILayout.BeginHorizontal(); 46 | 47 | GUIContent inputFolderContent = new GUIContent("Input Folder", "Select the folder where the excel files to be processed are located."); 48 | EditorGUIUtility.labelWidth = 120.0f; 49 | EditorGUILayout.TextField(inputFolderContent, _inputPath, GUILayout.MinWidth(120), GUILayout.MaxWidth(500)); 50 | if (GUILayout.Button(new GUIContent("Select Folder"), GUILayout.MinWidth(80), GUILayout.MaxWidth(100))) 51 | { 52 | _inputPath = EditorUtility.OpenFolderPanel("Select Folder with Excel Files", _inputPath, Application.dataPath); 53 | } 54 | 55 | GUILayout.EndHorizontal(); 56 | 57 | GUILayout.BeginHorizontal(); 58 | 59 | GUIContent outputFolderContent = new GUIContent("Output Folder", "Select the folder where the converted json files should be saved."); 60 | EditorGUILayout.TextField(outputFolderContent, _outputPath, GUILayout.MinWidth(120), GUILayout.MaxWidth(500)); 61 | if (GUILayout.Button(new GUIContent("Select Folder"), GUILayout.MinWidth(80), GUILayout.MaxWidth(100))) 62 | { 63 | _outputPath = EditorUtility.OpenFolderPanel("Select Folder to save json files", _outputPath, Application.dataPath); 64 | } 65 | 66 | GUILayout.EndHorizontal(); 67 | 68 | GUIContent modifiedToggleContent = new GUIContent("Modified Files Only", "If checked, only excel files which have been newly added or updated since the last conversion will be processed."); 69 | _onlyModifiedFiles = EditorGUILayout.Toggle(modifiedToggleContent, _onlyModifiedFiles); 70 | 71 | if (string.IsNullOrEmpty(_inputPath) || string.IsNullOrEmpty(_outputPath)) 72 | { 73 | GUI.enabled = false; 74 | } 75 | 76 | GUILayout.BeginArea(new Rect((Screen.width / 2) - (200 / 2), (Screen.height / 2) - (25 / 2), 200, 25)); 77 | 78 | if (GUILayout.Button("Convert Excel Files")) 79 | { 80 | _excelProcessor.ConvertExcelFilesToJson(_inputPath, _outputPath, _onlyModifiedFiles); 81 | } 82 | 83 | GUILayout.EndArea(); 84 | 85 | GUI.enabled = true; 86 | } 87 | } 88 | 89 | [InitializeOnLoad] 90 | public class ExcelToJsonAutoConverter 91 | { 92 | /// 93 | /// Class attribute [InitializeOnLoad] triggers calling the static constructor on every refresh. 94 | /// 95 | static ExcelToJsonAutoConverter() 96 | { 97 | string inputPath = EditorPrefs.GetString(ExcelToJsonConverterWindow.kExcelToJsonConverterInputPathPrefsName, Application.dataPath); 98 | string outputPath = EditorPrefs.GetString(ExcelToJsonConverterWindow.kExcelToJsonConverterOuputPathPrefsName, Application.dataPath); 99 | bool onlyModifiedFiles = EditorPrefs.GetBool(ExcelToJsonConverterWindow.kExcelToJsonConverterModifiedFilesOnlyPrefsName, false); 100 | 101 | ExcelToJsonConverter excelProcessor = new ExcelToJsonConverter(); 102 | excelProcessor.ConvertExcelFilesToJson(inputPath, outputPath, onlyModifiedFiles); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/ExcelToJsonConverterWindow.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ea23e13965a82471e9cc17c0bf2c5818 3 | timeCreated: 1435495530 4 | licenseType: Free 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4913cccc9c26842b88edfcdcc5609be3 3 | folderAsset: yes 4 | timeCreated: 1437325404 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Json/Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Json/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Json/Newtonsoft.Json.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7bb4d177a821c42a08552d175e80894a 3 | timeCreated: 1434249722 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 1 13 | settings: {} 14 | Editor: 15 | enabled: 0 16 | settings: 17 | DefaultValueInitialized: true 18 | userData: 19 | assetBundleName: 20 | assetBundleVariant: 21 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Json/license.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2007 James Newton-King 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this 4 | software and associated documentation files (the "Software"), to deal in the Software 5 | without restriction, including without limitation the rights to use, copy, modify, 6 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to 7 | permit persons to whom the Software is furnished to do so, subject to the following 8 | conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all copies 11 | or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 14 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A 15 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 16 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 17 | CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 18 | OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Json/license.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a991a2f06af394d98b5bb6df8ff087f3 3 | timeCreated: 1434249725 4 | licenseType: Free 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Mono.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3859a04de77c4436e8fd79c621a2d502 3 | folderAsset: yes 4 | timeCreated: 1437325404 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Mono/System.Data.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Mono/System.Data.dll -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Editor/ExcelToJsonConverter/Mono/System.Data.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8e633a76adcb1450187a82a55edbe190 3 | timeCreated: 1434249725 4 | licenseType: Free 5 | PluginImporter: 6 | serializedVersion: 1 7 | iconMap: {} 8 | executionOrder: {} 9 | isPreloaded: 0 10 | platformData: 11 | Any: 12 | enabled: 1 13 | settings: {} 14 | Editor: 15 | enabled: 0 16 | settings: 17 | DefaultValueInitialized: true 18 | userData: 19 | assetBundleName: 20 | assetBundleVariant: 21 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Excel.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 453731b9ffef24fd3a0ca66d1e2ef25d 3 | folderAsset: yes 4 | timeCreated: 1437326351 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Excel/Character1997Format.xls: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/Assets/Excel/Character1997Format.xls -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Excel/Character1997Format.xls.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc45c077dd81a40ee9ff77f205fb4fe5 3 | timeCreated: 1437327006 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Excel/Character2007Format.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/Assets/Excel/Character2007Format.xlsx -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Excel/Character2007Format.xlsx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c5ac531037c1a4e5fb3e5a7ab2d48d61 3 | timeCreated: 1437326981 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Excel/TestMultipleSheets.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/Assets/Excel/TestMultipleSheets.xlsx -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Excel/TestMultipleSheets.xlsx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1f8e6e0d588bf422a845e4702d3a43b4 3 | timeCreated: 1437326874 4 | licenseType: Free 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: febd5d46a94c24852bc7b9b8534c7afb 3 | folderAsset: yes 4 | timeCreated: 1437326351 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5abee050f15c540d9903de3c6cf71be3 3 | folderAsset: yes 4 | timeCreated: 1434135837 5 | licenseType: Free 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json/CharacterSheet1997Format.json: -------------------------------------------------------------------------------- 1 | [{"Id":"charcter_1","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":"{building,repairing,exploding things}"},{"Id":"charcter_2","Name":"Darwin","Race":"Dwarf","Level":"10","Power":"30","Agility":"22","Charisma":"11","Intellect":"15","PastTimes":"{drinkin,eatin,fightin,sleepin}"},{"Id":"charcter_3","Name":"Pidgey","Race":"Pidgeon","Level":"100","Power":"100","Agility":"100","Charisma":"100","Intellect":"100","PastTimes":"{flying,pooping,dancing}"},{"Id":"charcter_4","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":"{building,repairing,exploding things}"},{"Id":"charcter_5","Name":"Darwin","Race":"Dwarf","Level":"10","Power":"30","Agility":"22","Charisma":"11","Intellect":"15","PastTimes":"{drinkin,eatin,fightin,sleepin}"},{"Id":"charcter_6","Name":"Pidgey","Race":"Pidgeon","Level":"100","Power":"100","Agility":"100","Charisma":"100","Intellect":"100","PastTimes":"{flying,pooping,dancing}"},{"Id":"charcter_7","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":""},{"Id":"charcter_8","Name":"Darwin","Race":"Dwarf","Level":"10","Power":"30","Agility":"22","Charisma":"11","Intellect":"15","PastTimes":"{drinkin,eatin,fightin,sleepin}"},{"Id":"charcter_9","Name":"Pidgey","Race":"Pidgeon","Level":"100","Power":"100","Agility":"100","Charisma":"100","Intellect":"100","PastTimes":"{flying,pooping,dancing}"},{"Id":"charcter_10","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":""},{"Id":"charcter_11","Name":"Darwin","Race":"Dwarf","Level":"10","Power":"30","Agility":"22","Charisma":"11","Intellect":"15","PastTimes":"{drinkin,eatin,fightin,sleepin}"},{"Id":"charcter_12","Name":"Pidgey","Race":"Pidgeon","Level":"100","Power":"100","Agility":"100","Charisma":"100","Intellect":"100","PastTimes":"{flying,pooping,dancing}"},{"Id":"charcter_13","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":"{building,repairing,exploding things}"}] -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json/CharacterSheet1997Format.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ddbeaa5c6a5184308b1589ee613fc2fe 3 | timeCreated: 1437327393 4 | licenseType: Free 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json/CharacterSheet2007Format.json: -------------------------------------------------------------------------------- 1 | [{"Id":"charcter_1","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":"{building,repairing,exploding things}"},{"Id":"charcter_2","Name":"Darwin","Race":"Dwarf","Level":"10","Power":"30","Agility":"22","Charisma":"11","Intellect":"15","PastTimes":"{drinkin,eatin,fightin,sleepin}"},{"Id":"charcter_3","Name":"Pidgey","Race":"Pidgeon","Level":"100","Power":"100","Agility":"100","Charisma":"100","Intellect":"100","PastTimes":"{flying,pooping,dancing}"},{"Id":"charcter_4","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":"{building,repairing,exploding things}"},{"Id":"charcter_5","Name":"Darwin","Race":"Dwarf","Level":"10","Power":"30","Agility":"22","Charisma":"11","Intellect":"15","PastTimes":"{drinkin,eatin,fightin,sleepin}"},{"Id":"charcter_6","Name":"Pidgey","Race":"Pidgeon","Level":"100","Power":"100","Agility":"100","Charisma":"100","Intellect":"100","PastTimes":"{flying,pooping,dancing}"},{"Id":"charcter_7","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":""},{"Id":"charcter_8","Name":"Darwin","Race":"Dwarf","Level":"10","Power":"30","Agility":"22","Charisma":"11","Intellect":"15","PastTimes":"{drinkin,eatin,fightin,sleepin}"},{"Id":"charcter_9","Name":"Pidgey","Race":"Pidgeon","Level":"100","Power":"100","Agility":"100","Charisma":"100","Intellect":"100","PastTimes":"{flying,pooping,dancing}"},{"Id":"charcter_10","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":""},{"Id":"charcter_11","Name":"Darwin","Race":"Dwarf","Level":"10","Power":"30","Agility":"22","Charisma":"11","Intellect":"15","PastTimes":"{drinkin,eatin,fightin,sleepin}"},{"Id":"charcter_12","Name":"Pidgey","Race":"Pidgeon","Level":"100","Power":"100","Agility":"100","Charisma":"100","Intellect":"100","PastTimes":"{flying,pooping,dancing}"},{"Id":"charcter_13","Name":"Gobbin","Race":"Goblin","Level":"2","Power":"3","Agility":"10","Charisma":"5","Intellect":"18","PastTimes":"{building,repairing,exploding things}"}] -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json/CharacterSheet2007Format.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c80d82b1c23df49feb2d81e1a11dd2cd 3 | timeCreated: 1437326995 4 | licenseType: Free 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json/TestSheet1.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json/TestSheet1.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5889c3aacc35442fabe6249b18e4cc82 3 | timeCreated: 1437326981 4 | licenseType: Free 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json/TestSheet3.json: -------------------------------------------------------------------------------- 1 | [] -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/Assets/Resources/Json/TestSheet3.json.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4c5cb491c7e846719207942f354af85 3 | timeCreated: 1437326981 4 | licenseType: Free 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.0.1f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ExcelToJsonConveterExample/ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Benzino/ExcelToJsonConverter/ce7a90ac1aabfdb2a43bd9731fadb6ac58e6af2d/ExcelToJsonConveterExample/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Benzino 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ExcelToJsonConverter 2 | This is a simple editor plugin which allows you to convert Excel files to Json within Unity. 3 | 4 | **Please note this has only been tested on Unity Mac. However it should work on Windows, 5 | you will probably need to remove the ExcelToJsonConverter/Mono folder to avoid conflicts with Windows System.Data.dll.** 6 | 7 | How to use: 8 | 9 | 1. Copy the contents of the ExcelToJsonConverter folder into your project's Assets/Editor folder. 10 | 2. Open Unity project and select Tools -> Excel to Json Converter. 11 | - Select input folder where Excel files are located. 12 | - Select output folder to save Json files. 13 | - Hit "Convert Excel Files" button. 14 | - Check console window for conversion info. 15 | 16 | How to call from code: 17 | Note: This is not designed for runtime use (although it should work in runtime, but will be slow). 18 | 19 | ```c# 20 | ExcelToJsonConverter excelProcessor = new ExcelToJsonConverter(); 21 | excelProcessor.ConversionToJsonSuccessfull += ConversionToJsonSuccessfullCallback; 22 | excelProcessor.ConversionToJsonFailed += ConversionToJsonFailedCallback; 23 | excelProcessor.ConvertExcelFilesToJson(inputPath, outputPath, false); 24 | ``` 25 | 26 | This can be useful to integrate with your build scripts. See test project for example of this. 27 | 28 | Notes: 29 | - Supports .xls (1997 - 2004) and .xlsx (2007) excel file formats. 30 | - Supports multiple sheets per file. Each sheet is saved separately to a Json file with the same name. (e.g. Sheet1 saved to Sheet1.json) 31 | - Assumes that the first row of a sheet are column headers. 32 | - If you want to ignore a column and not have it saved in the Json file, prefix the column header with '~'. E.G. ~Notes 33 | - If you want to ignore a sheet and not have it converted to Json, prefix the sheet name with '~'. E.G. ~Temp 34 | - Automatically scans and updates excel files when editor refreshes (e.g. after a script is changed) 35 | 36 | 37 | This plugin uses (and would not be possible without) ExcelDataReader & Json.Net. 38 | --------------------------------------------------------------------------------