├── .gitignore ├── Assets ├── Editor.meta ├── Editor │ ├── EPPlus.meta │ ├── EPPlus │ │ ├── EPPlus.XML │ │ ├── EPPlus.XML.meta │ │ ├── EPPlus.dll │ │ ├── EPPlus.dll.meta │ │ ├── readme.txt │ │ └── readme.txt.meta │ ├── Excel4Unity.meta │ ├── Excel4Unity │ │ ├── DataItem.txt │ │ ├── DataItem.txt.meta │ │ ├── Excel.cs │ │ ├── Excel.cs.meta │ │ ├── ExcelDeserializer.cs │ │ ├── ExcelDeserializer.cs.meta │ │ ├── ExcelHelper.cs │ │ ├── ExcelHelper.cs.meta │ │ ├── ExcelSerializer.cs │ │ ├── ExcelSerializer.cs.meta │ │ ├── ExcelTable.cs │ │ ├── ExcelTable.cs.meta │ │ ├── ExcelTableCell.cs │ │ └── ExcelTableCell.cs.meta │ ├── MyEditor.cs │ └── MyEditor.cs.meta ├── Example.cs ├── Example.cs.meta ├── Example.unity ├── Example.unity.meta ├── Plugins.meta ├── Plugins │ ├── LitJson.dll │ └── LitJson.dll.meta ├── Resources.meta ├── Resources │ ├── DataFiles.meta │ └── DataFiles │ │ ├── Test.txt │ │ ├── Test.txt.meta │ │ ├── Test4.txt │ │ └── Test4.txt.meta ├── Scripts.meta ├── Scripts │ ├── Model.meta │ └── Model │ │ ├── DataItem.cs │ │ ├── DataItem.cs.meta │ │ ├── TestItem.cs │ │ ├── TestItem.cs.meta │ │ ├── sheet2Item.cs │ │ └── sheet2Item.cs.meta ├── Test.meta └── Test │ ├── Test.xlsx │ ├── Test.xlsx.meta │ ├── Test2.xlsx │ ├── Test2.xlsx.meta │ ├── Test3.xlsx │ ├── Test3.xlsx.meta │ ├── Test4.xlsx │ └── Test4.xlsx.meta ├── Excel4Unity.sln ├── Excel4Unity.userprefs ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.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 ├── UnityAdsSettings.asset └── UnityConnectSettings.asset ├── README.md └── doc └── 001.png /.gitignore: -------------------------------------------------------------------------------- 1 | Library/ 2 | Temp/ 3 | obj/ 4 | .vs/ 5 | -------------------------------------------------------------------------------- /Assets/Editor.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fe73958112b864c11b051666b93fb0f9 3 | folderAsset: yes 4 | timeCreated: 1448966053 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/EPPlus.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6b19aa227135d461892cf8ff2a84f99f 3 | folderAsset: yes 4 | timeCreated: 1448966025 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/EPPlus/EPPlus.XML.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f5eea5f583c1d4e4e97c247539458bb1 3 | timeCreated: 1448966026 4 | licenseType: Pro 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Editor/EPPlus/EPPlus.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/Assets/Editor/EPPlus/EPPlus.dll -------------------------------------------------------------------------------- /Assets/Editor/EPPlus/EPPlus.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 779effc783b37445b91de0d6b70078e3 3 | PluginImporter: 4 | externalObjects: {} 5 | serializedVersion: 2 6 | iconMap: {} 7 | executionOrder: {} 8 | defineConstraints: [] 9 | isPreloaded: 0 10 | isOverridable: 0 11 | isExplicitlyReferenced: 0 12 | validateReferences: 1 13 | platformData: 14 | - first: 15 | '': Any 16 | second: 17 | enabled: 0 18 | settings: 19 | Exclude Android: 0 20 | Exclude Editor: 0 21 | Exclude Linux: 0 22 | Exclude Linux64: 0 23 | Exclude LinuxUniversal: 0 24 | Exclude OSXUniversal: 0 25 | Exclude Win: 0 26 | Exclude Win64: 0 27 | - first: 28 | Android: Android 29 | second: 30 | enabled: 1 31 | settings: 32 | CPU: ARMv7 33 | - first: 34 | Any: 35 | second: 36 | enabled: 1 37 | settings: {} 38 | - first: 39 | Editor: Editor 40 | second: 41 | enabled: 1 42 | settings: 43 | CPU: AnyCPU 44 | DefaultValueInitialized: true 45 | OS: AnyOS 46 | - first: 47 | Facebook: Win 48 | second: 49 | enabled: 0 50 | settings: 51 | CPU: AnyCPU 52 | - first: 53 | Facebook: Win64 54 | second: 55 | enabled: 0 56 | settings: 57 | CPU: AnyCPU 58 | - first: 59 | Standalone: Linux 60 | second: 61 | enabled: 1 62 | settings: 63 | CPU: x86 64 | - first: 65 | Standalone: Linux64 66 | second: 67 | enabled: 1 68 | settings: 69 | CPU: x86_64 70 | - first: 71 | Standalone: LinuxUniversal 72 | second: 73 | enabled: 1 74 | settings: 75 | CPU: AnyCPU 76 | - first: 77 | Standalone: OSXUniversal 78 | second: 79 | enabled: 1 80 | settings: 81 | CPU: AnyCPU 82 | - first: 83 | Standalone: Win 84 | second: 85 | enabled: 1 86 | settings: 87 | CPU: AnyCPU 88 | - first: 89 | Standalone: Win64 90 | second: 91 | enabled: 1 92 | settings: 93 | CPU: AnyCPU 94 | - first: 95 | Windows Store Apps: WindowsStoreApps 96 | second: 97 | enabled: 0 98 | settings: 99 | CPU: AnyCPU 100 | userData: 101 | assetBundleName: 102 | assetBundleVariant: 103 | -------------------------------------------------------------------------------- /Assets/Editor/EPPlus/readme.txt: -------------------------------------------------------------------------------- 1 | EPPlus 4.0.4 2 | 3 | Visit epplus.codeplex.com for the latest information 4 | 5 | EPPlus-Create Advanced Excel spreadsheet. 6 | 7 | New features 8 | 9 | Replaced Packaging API with DotNetZip 10 | * This will remove any problems with Isolated Storage and enable multi threading 11 | 12 | 13 | New Cell store 14 | * Less memory consumtion 15 | * Insert columns (not on the range level) 16 | * Faster row inserts, 17 | 18 | Formula Parser 19 | * Calculates all formulas in a workbook, a worksheet or in a specified range 20 | * 100+ functions implemented 21 | * Access via Calculate methods on Workbook, Worksheet and Range objects. 22 | * Add custom/missing Excel functions via Workbook.FormulaParserManager. 23 | * Samples added to the EPPlusSamples project. 24 | 25 | The formula parser does not support Array Formulas 26 | * Intersect operator (Space) 27 | * References to external workbooks 28 | * And probably a whole lot of other stuff as well :) 29 | 30 | Perfomance 31 | *Of course the performance of the formula parser is nowhere near Excels.Our focus has been functionality. 32 | 33 | Agile Encryption (Office 2012-) 34 | * Support for newer type of encryption. 35 | 36 | Minor new features 37 | * Chart worksheets 38 | * New Chart Types Bubblecharts 39 | * Radar Charts 40 | * Area Charts 41 | * And lots of bugfixes... 42 | 43 | Beta 2 Changes 44 | * Fixed bug when using RepeatColumns & RepeatRows at the same time. 45 | * VBA project will be left untouched if its not accessed. 46 | * Fixed problem with strings on save. 47 | * Added locks to the cellstore for access by mulitple threads. 48 | * Implemented Indirect function 49 | * Used DisplayNameAttribute to generate column headers from LoadFromCollection 50 | * Rewrote ExcelRangeBase.Copy function. 51 | * Added caching to Save ZipStream for Cells and shared strings to speed up the Save method. 52 | * Added Missing InsertColumn and DeleteColumn 53 | * Added pull request to support Date1904 54 | * Added pull request ExcelWorksheet.LoadFromDataReader 55 | 56 | Release Candidare changes 57 | * Fixed some problems with Range.Copy Function 58 | * InsertColumn and Delete column didn't work in some cases 59 | * Chart.DisplayBlankAs had the wrong default type in Excel 2010+ 60 | * Datavalidation list overflow cauesed corruption of the package 61 | * Fixed a few Calculation when refering ranges (for example If) function and some 62 | * Added ChartAxis.DisplayUnit 63 | * Fixed a bug related to shared formulas 64 | * Named styles faild in some cases. 65 | * Style.Indent got an invalid value in some cases. 66 | * Fixed a problem with AutofitColumns method. 67 | * Performance fix. 68 | * An a whole lot of other small fixes. 69 | 70 | 4.0.1 Fixes 71 | * VBA unreadable content 72 | * Fixed a few issues with InsertRow and DeleteRow 73 | * Fixed bug in Average and AverageA 74 | * Handling of Div/0 in functions 75 | * Fixed VBA CodeModule error when copying a worksheet. 76 | * Value decoding when reading str element for cell value. 77 | * Better exception when accessing a worksheet out of range in the Excelworksheets indexer. 78 | * Added Small and Large function to formula parser. Performance fix when encountering an unknown function. 79 | * Fixed handling strings in formulas 80 | * Calculate hanges if formula start with a parenthes. 81 | * Worksheet.Dimension returned an invalid range in some cases. 82 | * Rowheight was wrong in some cases. 83 | * ExcelSeries.Header had an incorrect validation check. 84 | 85 | 4.0.2 Fixes 86 | * Fixes a whole bunch of bugs related to the cell store (Worksheet.InsertColumn, Worksheet.InsertRow, Worksheet.DeleteColumn, Worksheet.DeleteRow, Range.Copy, Range.Clear) 87 | * Added functions Acos, Acosh, Asinh, Atanh, Atan, CountBlank, CountIfs, Mina, Offset, Median, Hyperlink, Rept 88 | * Fix for reading Excel comment content from the t-element. 89 | * Fix to make Range.LoadFromCollection work better with inheritence 90 | * And alot of other smal fixes 91 | 92 | 4.0.3 Fixes 93 | * Added compilation directive for MONO (Thanks Danny) 94 | * Added functions IfError, Char, Error.Type, Degrees, Fixed, IsNonText, IfNa and SumIfs 95 | * And fixed a lot of issues. See http://epplus.codeplex.com/SourceControl/list/changesets for more details 96 | 97 | 4.0.4 Fixes 98 | * Added functions Daverage, Dvar Dvarp, DMax, DMin DSum, DGet, DCount and DCountA 99 | * Exposed the formula parser logging functionality via FormulaParserManager. 100 | * And fixed a lot of issues. See http://epplus.codeplex.com/SourceControl/list/changesets for more details 101 | -------------------------------------------------------------------------------- /Assets/Editor/EPPlus/readme.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 28b2754fb50034ca0aaaa7609262d7af 3 | timeCreated: 1448966026 4 | licenseType: Pro 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f8bad2be1a6c64210a6efdbbb0967a19 3 | folderAsset: yes 4 | timeCreated: 1448966121 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/DataItem.txt: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using LitJson; 4 | 5 | public class {0} : DataItem { 6 | {1} 7 | public override void Setup(JsonData data) { 8 | base.Setup(data); 9 | {3} 10 | } 11 | 12 | public {2} () { 13 | 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/DataItem.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 702e882d464866e4c98f166169a849b0 3 | timeCreated: 1545986295 4 | licenseType: Pro 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/Excel.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using OfficeOpenXml; 5 | 6 | public class Excel 7 | { 8 | public List Tables = new List(); 9 | 10 | public Excel() 11 | { 12 | 13 | } 14 | 15 | public Excel(ExcelWorkbook wb) 16 | { 17 | for (int i = 1; i <= wb.Worksheets.Count; i++) 18 | { 19 | ExcelWorksheet sheet = wb.Worksheets[i]; 20 | ExcelTable table = new ExcelTable(sheet); 21 | Tables.Add(table); 22 | } 23 | } 24 | 25 | public void ShowLog() { 26 | for (int i = 0; i < Tables.Count; i++) 27 | { 28 | Tables[i].ShowLog(); 29 | } 30 | } 31 | 32 | public void AddTable(string name) { 33 | ExcelTable table = new ExcelTable(); 34 | table.TableName = name; 35 | Tables.Add(table); 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/Excel.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 04d78b0c6a7ff4d3780578bad9b7f5f8 3 | timeCreated: 1448966138 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelDeserializer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using UnityEditor; 4 | using System.IO; 5 | //using LitJson; 6 | using System.Collections.Generic; 7 | using System.Text; 8 | using System.Xml; 9 | 10 | public class ExcelDeserializer { 11 | public int FieldNameLine; 12 | public int FieldTypeLine; 13 | public int FieldValueLine; 14 | 15 | public string IgnoreSymbol = string.Empty; 16 | public string ModelPath = Application.dataPath + "/Editor/Excel4Unity/DataItem.txt"; 17 | public bool GenerateCS(ExcelTable table) 18 | { 19 | string moudle = File.ReadAllText(ModelPath); 20 | 21 | string properties = ""; 22 | string parse = ""; 23 | int tableColumn = 0; 24 | try 25 | { 26 | for (int j = 1; j <= table.NumberOfColumns; j++) 27 | { 28 | tableColumn = j; 29 | string propName = table.GetValue(FieldNameLine, j).ToString(); 30 | string propType = table.GetValue(FieldTypeLine, j).ToString().ToLower(); 31 | if (!string.IsNullOrEmpty(IgnoreSymbol) && propName.StartsWith(IgnoreSymbol)) 32 | { 33 | continue; 34 | } 35 | if (string.IsNullOrEmpty(propName) || string.IsNullOrEmpty(propType)) 36 | { 37 | continue; 38 | } 39 | if (properties.Length == 0) 40 | { 41 | properties += string.Format("\tpublic {0} {1};\n", propType, propName); 42 | if (propType.Equals("string")) 43 | { 44 | properties += "\tpublic override string StringIdentity(){ return " + propName + "; }\n"; 45 | } 46 | else 47 | { 48 | properties += "\tpublic override int Identity(){ return " + propName + "; }\n"; 49 | } 50 | } 51 | else 52 | { 53 | properties += string.Format("\tpublic {0} {1};\n", propType, propName); 54 | } 55 | 56 | if (propType == "string") 57 | { 58 | parse += string.Format("\t\t{0} = data[\"{1}\"].ToString();\n", propName, propName); 59 | } 60 | else if (propType == "bool") 61 | { 62 | parse += string.Format("\t\t{0} = data[\"{1}\"].ToString() != \"0\";\n", propName, propName); 63 | } 64 | else if (propType == "int" || propType == "float" || propType == "double") 65 | { 66 | parse += string.Format("\t\t{0} = {1}.Parse(data[\"{2}\"].ToString());\n", propName, propType, propName); 67 | } 68 | else if (propType == "string[]") 69 | { 70 | string subType = propType.Replace("[]", ""); 71 | parse += string.Format("\t\tstring {0}_str = data[\"{1}\"].ToString();\n", propName, propName); 72 | parse += "\t\tif(" + propName + "_str.Length > 0) { \n"; 73 | parse += string.Format("\t\t {0} = data[\"{1}\"].ToString().Split (';');\n", propName, propName); 74 | string elseStr = string.Format("{0} = new {1}[0];", propName, subType); 75 | parse += "\t\t} else {" + elseStr + "}\n"; 76 | } 77 | else if (propType == "int[]" || propType == "float[]" || propType == "double[]") 78 | { 79 | string subType = propType.Replace("[]", ""); 80 | parse += string.Format("\t\tstring {0}_str = data[\"{1}\"].ToString();\n", propName, propName); 81 | parse += "\t\tif(" + propName + "_str.Length > 0) { \n"; 82 | parse += string.Format("\t\tstring[] {0}_data = data[\"{1}\"].ToString().Split (';');\n", propName, propName); 83 | parse += string.Format("\t\t{0} = new {1}[{2}_data.Length];\n", propName, subType, propName); 84 | parse += "\t\tfor (int i = 0; i < " + propName + "_data.Length; i++) { " + propName + "[i] = " + subType + ".Parse (" + propName + "_data [i]);}\n"; 85 | string elseStr = string.Format("{0} = new {1}[0];", propName, subType); 86 | parse += "\t\t} else {" + elseStr + "}\n"; 87 | } 88 | else 89 | { 90 | Debug.LogError("generate .cs failed! " + propType + " not a valid type" + " " + "table:" + table.TableName); 91 | return false; 92 | } 93 | } 94 | } 95 | catch (System.Exception e) 96 | { 97 | Debug.LogError(e); 98 | Debug.LogError("generate .cs failed: " + table.TableName + "!" + " " + "table:" + table.TableName); 99 | return false; 100 | } 101 | moudle = moudle.Replace("{0}", table.TableName + "Item"); 102 | moudle = moudle.Replace("{1}", properties); 103 | moudle = moudle.Replace("{2}", table.TableName + "Item"); 104 | moudle = moudle.Replace("{3}", parse); 105 | string path = Application.dataPath + "/Scripts/Model/" + table.TableName + "Item.cs"; 106 | string str = string.Empty; 107 | if (File.Exists(path)) 108 | { 109 | str = File.ReadAllText(path); 110 | } 111 | string directory = Path.GetDirectoryName(path); 112 | Debug.LogError(directory); 113 | if (!Directory.Exists(directory)) 114 | { 115 | Directory.CreateDirectory(directory); 116 | } 117 | if (str != moudle) 118 | { 119 | Debug.LogError("change " + table.TableName + ".cs"); 120 | File.WriteAllText(path, moudle); 121 | } 122 | else 123 | { 124 | // Debug.LogError ("no change " + table.TableName + ".cs"); 125 | } 126 | AssetDatabase.Refresh(); 127 | return true; 128 | } 129 | } 130 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelDeserializer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e1cd863dca3872d4680acffdb29b4155 3 | timeCreated: 1545985787 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelHelper.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using OfficeOpenXml; 4 | using System.IO; 5 | 6 | public class ExcelHelper 7 | { 8 | 9 | public static Excel LoadExcel(string path) 10 | { 11 | FileInfo file = new FileInfo(path); 12 | ExcelPackage ep = new ExcelPackage(file); 13 | Excel xls = new Excel(ep.Workbook); 14 | return xls; 15 | } 16 | 17 | public static Excel CreateExcel(string path) { 18 | ExcelPackage ep = new ExcelPackage (); 19 | ep.Workbook.Worksheets.Add ("sheet"); 20 | Excel xls = new Excel(ep.Workbook); 21 | SaveExcel (xls, path); 22 | return xls; 23 | } 24 | 25 | public static void SaveExcel(Excel xls, string path) 26 | { 27 | FileInfo output = new FileInfo(path); 28 | ExcelPackage ep = new ExcelPackage(); 29 | for (int i = 0; i < xls.Tables.Count; i++) 30 | { 31 | ExcelTable table = xls.Tables[i]; 32 | ExcelWorksheet sheet = ep.Workbook.Worksheets.Add(table.TableName); 33 | for (int row = 1; row <= table.NumberOfRows; row++) { 34 | for (int column = 1; column <= table.NumberOfColumns; column++) { 35 | sheet.Cells[row, column].Value = table.GetValue(row, column); 36 | } 37 | } 38 | } 39 | ep.SaveAs(output); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelHelper.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 753d43750dab14f1c82a3144dbf6dada 3 | timeCreated: 1448969291 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelSerializer.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class ExcelSerializer { 5 | 6 | } 7 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelSerializer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8fdc6cbf5d3014841bb6730c26b15962 3 | timeCreated: 1545985674 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelTable.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | using OfficeOpenXml; 5 | 6 | public class ExcelTable 7 | { 8 | private Dictionary > cells = new Dictionary>(); 9 | 10 | public string TableName; 11 | public int NumberOfRows; 12 | public int NumberOfColumns; 13 | 14 | public Vector2 Position; 15 | 16 | public ExcelTable() 17 | { 18 | 19 | } 20 | 21 | public ExcelTable(ExcelWorksheet sheet) 22 | { 23 | TableName = sheet.Name; 24 | if (sheet.Dimension != null) 25 | { 26 | NumberOfRows = sheet.Dimension.Rows; 27 | NumberOfColumns = sheet.Dimension.Columns; 28 | } 29 | else 30 | { 31 | //empty Sheet 32 | NumberOfRows = 0; 33 | NumberOfColumns = 0; 34 | } 35 | for (int row = 1; row <= NumberOfRows; row++) 36 | { 37 | for (int column = 1; column <= NumberOfColumns; column++) 38 | { 39 | string value = ""; //default value for empty cell 40 | if (sheet.Cells [row, column].Value != null) 41 | { 42 | value = sheet.Cells [row, column].Value.ToString (); 43 | } 44 | SetValue(row, column, value); 45 | } 46 | } 47 | } 48 | 49 | public ExcelTableCell SetValue(int row, int column, string value) 50 | { 51 | CorrectSize(row, column); 52 | if (!cells.ContainsKey(row)) 53 | { 54 | cells[row] = new Dictionary(); 55 | } 56 | if (cells[row].ContainsKey(column)) 57 | { 58 | cells[row][column].Value = value; 59 | 60 | return cells[row][column]; 61 | } 62 | else 63 | { 64 | ExcelTableCell cell = new ExcelTableCell(row, column, value); 65 | cells[row][column] = cell; 66 | return cell; 67 | } 68 | } 69 | 70 | public object GetValue(int row, int column) 71 | { 72 | ExcelTableCell cell = GetCell(row, column); 73 | if (cell != null) 74 | { 75 | return cell.Value; 76 | } 77 | else 78 | { 79 | return SetValue(row, column, "").Value; 80 | } 81 | } 82 | 83 | public ExcelTableCell GetCell(int row, int column) 84 | { 85 | if (cells.ContainsKey(row)) 86 | { 87 | if (cells[row].ContainsKey(column)) 88 | { 89 | return cells[row][column]; 90 | } 91 | } 92 | return null; 93 | } 94 | 95 | public void CorrectSize(int row, int column) 96 | { 97 | NumberOfRows = Mathf.Max(row, NumberOfRows); 98 | NumberOfColumns = Mathf.Max(column, NumberOfColumns); 99 | } 100 | 101 | public void SetCellTypeRow(int rowIndex, ExcelTableCellType type) 102 | { 103 | for (int column = 1; column <= NumberOfColumns; column++) 104 | { 105 | ExcelTableCell cell = GetCell(rowIndex, column); 106 | if (cell != null) 107 | { 108 | cell.Type = type; 109 | } 110 | } 111 | } 112 | 113 | public void SetCellTypeColumn(int columnIndex, ExcelTableCellType type, List values = null) 114 | { 115 | for (int row = 1; row <= NumberOfRows; row++) 116 | { 117 | ExcelTableCell cell = GetCell(row, columnIndex); 118 | if (cell != null) 119 | { 120 | cell.Type = type; 121 | if (values != null) 122 | { 123 | cell.ValueSelected = values; 124 | } 125 | } 126 | } 127 | } 128 | 129 | public void ShowLog() { 130 | string msg = ""; 131 | for (int row = 1; row <= NumberOfRows; row++) 132 | { 133 | for (int column = 1; column <= NumberOfColumns; column++) 134 | { 135 | msg += string.Format("{0} ", GetValue(row, column)); 136 | } 137 | msg += "\n"; 138 | } 139 | Debug.Log(msg); 140 | } 141 | 142 | 143 | } 144 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelTable.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b6e628b52baab4ed499c173f494f7af3 3 | timeCreated: 1448966146 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelTableCell.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | public enum ExcelTableCellType 5 | { 6 | None = 0, 7 | TextField = 1, 8 | Label = 2, 9 | Popup = 3, 10 | } 11 | 12 | public class ExcelTableCell { 13 | public int RowIndex; 14 | public int ColumnIndex; 15 | 16 | public string Value; 17 | public List ValueSelected = new List(); 18 | 19 | 20 | public float width = 50f; 21 | 22 | 23 | public ExcelTableCellType Type = ExcelTableCellType.TextField; 24 | 25 | public ExcelTableCell(int row, int column, string value) 26 | { 27 | RowIndex = row; 28 | ColumnIndex = column; 29 | Value = value; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /Assets/Editor/Excel4Unity/ExcelTableCell.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4dc62fc4a3f9d487bbce2c5d047900ca 3 | timeCreated: 1458025712 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Editor/MyEditor.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEditor; 3 | using System.Collections; 4 | using OfficeOpenXml; 5 | using System.IO; 6 | using System.Collections.Generic; 7 | using LitJson; 8 | using System.Text; 9 | 10 | public class Excel4Unity : Editor 11 | { 12 | 13 | [MenuItem("Excel4Unity/Test/ReadWrite")] 14 | static void ReadWrite() 15 | { 16 | Excel xls = new Excel(); 17 | ExcelTable table = new ExcelTable(); 18 | table.TableName = "test"; 19 | string outputPath = Application.dataPath + "/Test/Test2.xlsx"; 20 | xls.Tables.Add(table); 21 | xls.Tables[0].SetValue(1, 1, "1"); 22 | xls.Tables[0].SetValue(1, 2, "2"); 23 | xls.Tables[0].SetValue(2, 1, "3"); 24 | xls.Tables[0].SetValue(2, 2, "4"); 25 | xls.ShowLog(); 26 | ExcelHelper.SaveExcel(xls, outputPath); 27 | } 28 | 29 | [MenuItem("Excel4Unity/Test/Read")] 30 | static void Read() 31 | { 32 | string path = Application.dataPath + "/Test/Test3.xlsx"; 33 | Excel xls = ExcelHelper.LoadExcel(path); 34 | xls.ShowLog(); 35 | } 36 | 37 | [MenuItem("Excel4Unity/Test/Write")] 38 | static void Write() 39 | { 40 | Excel xls = new Excel(); 41 | ExcelTable table = new ExcelTable(); 42 | table.TableName = "test"; 43 | string outputPath = Application.dataPath + "/Test/Test2.xlsx"; 44 | xls.Tables.Add(table); 45 | xls.Tables[0].SetValue(1, 1, Random.Range(1000,100000).ToString()); 46 | xls.ShowLog(); 47 | ExcelHelper.SaveExcel(xls, outputPath); 48 | } 49 | 50 | [MenuItem("Excel4Unity/Test/GenerateModel")] 51 | static void GenerateModel() 52 | { 53 | string path = Application.dataPath + "/Test/Test4.xlsx"; 54 | Excel xls = ExcelHelper.LoadExcel(path); 55 | ExcelDeserializer ed = new ExcelDeserializer(); 56 | ed.FieldNameLine = 1; 57 | ed.FieldTypeLine = 2; 58 | ed.FieldValueLine = 3; 59 | ed.IgnoreSymbol = "#"; 60 | ed.ModelPath = Application.dataPath + "/Editor/Excel4Unity/DataItem.txt"; 61 | ed.GenerateCS(xls.Tables[0]); 62 | } 63 | 64 | [MenuItem(@"Excel4Unity/Test/Excel2JSON")] 65 | static void Excel2JSON() 66 | { 67 | Object[] objs = Selection.objects; 68 | for (int i = 0; i < objs.Length; i++) 69 | { 70 | string path = AssetDatabase.GetAssetPath(objs[i]); 71 | if (path.EndsWith(".xlsx")) 72 | { 73 | Excel4Unity.ParseFile(path); 74 | } 75 | else 76 | { 77 | EditorUtility.DisplayDialog("提示", "暂不支持的文件格式" + path, "ok"); 78 | return; 79 | } 80 | } 81 | AssetDatabase.Refresh(); 82 | } 83 | 84 | public static string ParseFile(string path, bool createCS = true, bool isMac = false) 85 | { 86 | // UnityEngine.Debug.LogError ("path " + path); 87 | if (!path.EndsWith("xlsx")) 88 | { 89 | return null; 90 | } 91 | 92 | string tableName = ""; 93 | string currentPropName = ""; 94 | int tableRow = 0; 95 | int tableColumn = 0; 96 | string v = ""; 97 | Excel excel = null; 98 | excel = ExcelHelper.LoadExcel(path); 99 | try 100 | { 101 | System.Text.StringBuilder sb = new System.Text.StringBuilder(); 102 | JsonWriter writer = new JsonWriter(sb); 103 | writer.WriteObjectStart(); 104 | foreach (ExcelTable table in excel.Tables) 105 | { 106 | tableName = table.TableName; 107 | bool language = tableName.ToLower().Contains("language"); 108 | if (table.TableName.StartsWith("#")) 109 | { 110 | continue; 111 | } 112 | if (createCS) 113 | { 114 | ExcelDeserializer ed = new ExcelDeserializer(); 115 | ed.FieldNameLine = 1; 116 | ed.FieldTypeLine = 2; 117 | ed.FieldValueLine = 3; 118 | ed.IgnoreSymbol = "#"; 119 | ed.ModelPath = Application.dataPath + "/Editor/Excel4Unity/DataItem.txt"; 120 | ed.GenerateCS(table); 121 | } 122 | writer.WritePropertyName(table.TableName); 123 | writer.WriteArrayStart(); 124 | for (int i = 4; i <= table.NumberOfRows; i++) 125 | { 126 | tableRow = i; 127 | string idStr = table.GetValue(i, 1).ToString(); 128 | if (idStr.Length <= 0) 129 | { 130 | // UnityEngine.Debug.LogError ("ID error:" + tableName + " (第" + i + "行)"); 131 | break; 132 | } 133 | writer.WriteObjectStart(); 134 | 135 | for (int j = 1; j <= table.NumberOfColumns; j++) 136 | { 137 | tableColumn = j; 138 | string propName = table.GetValue(1, j).ToString(); 139 | string propType = table.GetValue(3, j).ToString(); 140 | propName = propName.Replace("*", ""); 141 | currentPropName = propName; 142 | 143 | if (propName.StartsWith("#")) 144 | { 145 | continue; 146 | } 147 | if (string.IsNullOrEmpty(propName) || string.IsNullOrEmpty(propType)) 148 | { 149 | continue; 150 | } 151 | writer.WritePropertyName(propName); 152 | v = table.GetValue(i, j).ToString(); 153 | if (propType.Equals("int")) 154 | { 155 | int value = v.Length > 0 ? int.Parse(v) : 0; 156 | writer.Write(value); 157 | } 158 | else if (propType.Equals("bool")) 159 | { 160 | int value = v.Length > 0 ? int.Parse(v) : 0; 161 | writer.Write(value); 162 | } 163 | else if (propType.Equals("float")) 164 | { 165 | float value = v.Length > 0 ? float.Parse(v) : 0; 166 | writer.Write(value); 167 | } 168 | else 169 | { 170 | string ss = table.GetValue(i, j).ToString(); 171 | if (language && ss.Contains(" ")) 172 | { 173 | ss = ss.Replace(" ", "\u00A0"); 174 | } 175 | writer.Write(ss); 176 | } 177 | } 178 | writer.WriteObjectEnd(); 179 | } 180 | writer.WriteArrayEnd(); 181 | } 182 | writer.WriteObjectEnd(); 183 | string outputDir = Application.dataPath + "/Resources/DataFiles/"; 184 | string outputPath = outputDir + Path.GetFileNameWithoutExtension(path) + ".txt"; 185 | if (!Directory.Exists(outputDir)) { 186 | Directory.CreateDirectory(outputDir); 187 | } 188 | string str = string.Empty; 189 | if (File.Exists(path)) 190 | { 191 | byte[] bytes = File.ReadAllBytes(path); 192 | UTF8Encoding encoding = new UTF8Encoding(); 193 | str = encoding.GetString(bytes); 194 | } 195 | string content = sb.ToString(); 196 | if (str != content) 197 | { 198 | File.WriteAllText(outputPath, content); 199 | } 200 | Debug.Log("convert success! path = " + path); 201 | 202 | return sb.ToString(); 203 | } 204 | catch (System.Exception e) 205 | { 206 | if (excel == null) 207 | { 208 | // EditorUtility.DisplayDialog("ERROR!", "open excel failed!","ok"); 209 | Debug.LogError("open excel failed!"); 210 | Debug.LogError(e.StackTrace); 211 | } 212 | else 213 | { 214 | string msg = "解析错误! \n表:" + tableName + " \n字段:" + currentPropName + " \n第" + tableRow + "行,第" + tableColumn + "列 \nvalue = " + v; 215 | EditorUtility.DisplayDialog("error!", msg, "ok"); 216 | Debug.LogError(e); 217 | Debug.LogError(e.StackTrace); 218 | Debug.LogError(msg); 219 | } 220 | return null; 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /Assets/Editor/MyEditor.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0fc75a4459f354b4abe850020b65f67e 3 | timeCreated: 1448966226 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Example.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class Example : MonoBehaviour { 5 | 6 | 7 | } 8 | -------------------------------------------------------------------------------- /Assets/Example.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 51646727c57893e478a5073d50d347b5 3 | timeCreated: 1545986662 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Example.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/Assets/Example.unity -------------------------------------------------------------------------------- /Assets/Example.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4ead0c995913d45b08fa544295b414b7 3 | timeCreated: 1448966062 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Plugins.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 82bec3a80b0240a4e8f6c02442e5d3ae 3 | folderAsset: yes 4 | timeCreated: 1552361261 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Plugins/LitJson.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/Assets/Plugins/LitJson.dll -------------------------------------------------------------------------------- /Assets/Plugins/LitJson.dll.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3a343876ef95bb548a13f41620b076fb 3 | timeCreated: 1552361272 4 | licenseType: Pro 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 | WindowsStoreApps: 19 | enabled: 0 20 | settings: 21 | CPU: AnyCPU 22 | userData: 23 | assetBundleName: 24 | assetBundleVariant: 25 | -------------------------------------------------------------------------------- /Assets/Resources.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e41db711cfb3cc846b4fe9c2601f7a17 3 | folderAsset: yes 4 | timeCreated: 1552361628 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Resources/DataFiles.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 01ce226fbd749fb4f9a5e802d03af2bd 3 | folderAsset: yes 4 | timeCreated: 1552361628 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Resources/DataFiles/Test.txt: -------------------------------------------------------------------------------- 1 | {"Sheet1":[{"1":"4","2":"5","3":"6","4":"7"}],"Sheet2":[{"2":"5","3":"6","4":"7","5":"8"}]} -------------------------------------------------------------------------------- /Assets/Resources/DataFiles/Test.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2e971c51feb34554a968096b1a70adfe 3 | timeCreated: 1552361628 4 | licenseType: Pro 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Resources/DataFiles/Test4.txt: -------------------------------------------------------------------------------- 1 | {"Test":[{"ID":"2","Name":"2","Type":"2"},{"ID":"3","Name":"2","Type":"1"},{"ID":"4","Name":"2","Type":"2"},{"ID":"5","Name":"2","Type":"1"},{"ID":"6","Name":"2","Type":"2"},{"ID":"7","Name":"2","Type":"1"},{"ID":"8","Name":"2","Type":"2"},{"ID":"9","Name":"2","Type":"1"},{"ID":"10","Name":"2","Type":"1"},{"ID":"11","Name":"2","Type":"1"},{"ID":"12","Name":"2","Type":"1"},{"ID":"13","Name":"2","Type":"1"},{"ID":"14","Name":"2","Type":"1"},{"ID":"15","Name":"2","Type":"1"},{"ID":"16","Name":"2","Type":"1"},{"ID":"17","Name":"2","Type":"1"},{"ID":"18","Name":"2","Type":"1"},{"ID":"19","Name":"2","Type":"1"},{"ID":"20","Name":"2","Type":"1"},{"ID":"21","Name":"2","Type":"1"},{"ID":"22","Name":"2","Type":"1"},{"ID":"23","Name":"2","Type":"1"},{"ID":"24","Name":"2","Type":"1"},{"ID":"25","Name":"2","Type":"1"}],"sheet2":[{"ID":"2","Name":"0","Type":"2","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0"},{"ID":"3","Name":"0","Type":"1","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0"},{"ID":"4","Name":"0","Type":"2","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0"},{"ID":"5","Name":"0","Type":"1","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0","Name":"0"}]} -------------------------------------------------------------------------------- /Assets/Resources/DataFiles/Test4.txt.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 393f94da5bf406a419a56ffa103a2fd1 3 | timeCreated: 1552361663 4 | licenseType: Pro 5 | TextScriptImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0c0dadd59268e554c9d4b5907dd29579 3 | folderAsset: yes 4 | timeCreated: 1545987266 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/Model.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e899fdaaf6fbb2746afe61d684ebeefd 3 | folderAsset: yes 4 | timeCreated: 1545987266 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Scripts/Model/DataItem.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using LitJson; 4 | 5 | public class DataItem { 6 | 7 | public DataItem() 8 | { 9 | 10 | } 11 | 12 | public virtual void Setup(JsonData data) { 13 | 14 | } 15 | 16 | public virtual int Identity() 17 | { 18 | return 0; 19 | } 20 | 21 | public virtual int IndexIdentity() 22 | { 23 | return 0; 24 | } 25 | 26 | public virtual string StringIdentity() 27 | { 28 | return string.Empty; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /Assets/Scripts/Model/DataItem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6f74edc4fa5000479a0805cca1d542b 3 | timeCreated: 1545987501 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/Model/TestItem.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using LitJson; 4 | 5 | public class TestItem : DataItem { 6 | public int ID; 7 | public override int Identity(){ return ID; } 8 | public string Name; 9 | public int Type; 10 | 11 | public override void Setup(JsonData data) { 12 | base.Setup(data); 13 | ID = int.Parse(data["ID"].ToString()); 14 | Name = data["Name"].ToString(); 15 | Type = int.Parse(data["Type"].ToString()); 16 | 17 | } 18 | 19 | public TestItem () { 20 | 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /Assets/Scripts/Model/TestItem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f3d41ab958c9318459bcc2c1d433c742 3 | timeCreated: 1545987608 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Scripts/Model/sheet2Item.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using LitJson; 4 | 5 | public class sheet2Item : DataItem { 6 | public int ID; 7 | public override int Identity(){ return ID; } 8 | public string Name; 9 | public int Type; 10 | 11 | public override void Setup(JsonData data) { 12 | base.Setup(data); 13 | 14 | 15 | } 16 | 17 | public sheet2Item () { 18 | 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Assets/Scripts/Model/sheet2Item.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d984f5b54f46f9841965b8471ae56822 3 | timeCreated: 1552361663 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5d28c71960efe4a4e8f23461fb1f1ab3 3 | folderAsset: yes 4 | timeCreated: 1448969585 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/Test/Test.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/Assets/Test/Test.xlsx -------------------------------------------------------------------------------- /Assets/Test/Test.xlsx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b21dd21716b8a45de9d91df9951b362d 3 | timeCreated: 1448969632 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Test/Test2.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/Assets/Test/Test2.xlsx -------------------------------------------------------------------------------- /Assets/Test/Test2.xlsx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 2d698248b9d9f4528aa2f4b2f69b290c 3 | timeCreated: 1457601450 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Test/Test3.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/Assets/Test/Test3.xlsx -------------------------------------------------------------------------------- /Assets/Test/Test3.xlsx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d6073191a19b94db8b87ff49f5b853df 3 | timeCreated: 1457685824 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/Test/Test4.xlsx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/Assets/Test/Test4.xlsx -------------------------------------------------------------------------------- /Assets/Test/Test4.xlsx.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b667ce8482c9ee64c949fbb27fe2c79b 3 | timeCreated: 1545986860 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Excel4Unity.sln: -------------------------------------------------------------------------------- 1 | Microsoft Visual Studio Solution File, Format Version 11.00 2 | # Visual Studio 2008 3 | 4 | Project("{2C1D8478-3ED7-7B1D-4DC2-47BD095CFD94}") = "Excel4Unity", "Assembly-CSharp.csproj", "{1182A448-C391-50DC-E482-8747AE0EF89B}" 5 | EndProject 6 | Project("{2C1D8478-3ED7-7B1D-4DC2-47BD095CFD94}") = "Excel4Unity", "Assembly-CSharp-Editor.csproj", "{920A979E-1835-3F0F-9D7B-7ED313699E9E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {1182A448-C391-50DC-E482-8747AE0EF89B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {1182A448-C391-50DC-E482-8747AE0EF89B}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {1182A448-C391-50DC-E482-8747AE0EF89B}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {1182A448-C391-50DC-E482-8747AE0EF89B}.Release|Any CPU.Build.0 = Release|Any CPU 18 | {920A979E-1835-3F0F-9D7B-7ED313699E9E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 19 | {920A979E-1835-3F0F-9D7B-7ED313699E9E}.Debug|Any CPU.Build.0 = Debug|Any CPU 20 | {920A979E-1835-3F0F-9D7B-7ED313699E9E}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {920A979E-1835-3F0F-9D7B-7ED313699E9E}.Release|Any CPU.Build.0 = Release|Any CPU 22 | EndGlobalSection 23 | GlobalSection(SolutionProperties) = preSolution 24 | HideSolutionNode = FALSE 25 | EndGlobalSection 26 | GlobalSection(MonoDevelopProperties) = preSolution 27 | Policies = $0 28 | $0.TextStylePolicy = $1 29 | $1.inheritsSet = VisualStudio 30 | $1.inheritsScope = text/plain 31 | $1.scope = text/x-csharp 32 | $0.CSharpFormattingPolicy = $2 33 | $2.IndentSwitchBody = True 34 | $2.IndentBlocksInsideExpressions = True 35 | $2.AnonymousMethodBraceStyle = NextLine 36 | $2.PropertyBraceStyle = NextLine 37 | $2.PropertyGetBraceStyle = NextLine 38 | $2.PropertySetBraceStyle = NextLine 39 | $2.EventBraceStyle = NextLine 40 | $2.EventAddBraceStyle = NextLine 41 | $2.EventRemoveBraceStyle = NextLine 42 | $2.StatementBraceStyle = NextLine 43 | $2.ElseNewLinePlacement = NewLine 44 | $2.CatchNewLinePlacement = NewLine 45 | $2.FinallyNewLinePlacement = NewLine 46 | $2.WhileNewLinePlacement = DoNotCare 47 | $2.ArrayInitializerWrapping = DoNotChange 48 | $2.ArrayInitializerBraceStyle = NextLine 49 | $2.BeforeMethodDeclarationParentheses = False 50 | $2.BeforeMethodCallParentheses = False 51 | $2.BeforeConstructorDeclarationParentheses = False 52 | $2.NewLineBeforeConstructorInitializerColon = NewLine 53 | $2.NewLineAfterConstructorInitializerColon = SameLine 54 | $2.BeforeDelegateDeclarationParentheses = False 55 | $2.NewParentheses = False 56 | $2.SpacesBeforeBrackets = False 57 | $2.inheritsSet = Mono 58 | $2.inheritsScope = text/x-csharp 59 | $2.scope = text/x-csharp 60 | $0.TextStylePolicy = $3 61 | $3.FileWidth = 120 62 | $3.TabsToSpaces = False 63 | $3.EolMarker = Unix 64 | $3.inheritsSet = VisualStudio 65 | $3.inheritsScope = text/plain 66 | $3.scope = text/plain 67 | StartupItem = Assembly-CSharp.csproj 68 | EndGlobalSection 69 | EndGlobal 70 | -------------------------------------------------------------------------------- /Excel4Unity.userprefs: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.3.5f1 2 | m_StandardAssetsVersion: 0 3 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Excel4Unity 2 | Excel for Unity 3 | 4 | 5 | ## Provides 6 | 7 | * Excel(.xlsx) Read/Write 8 | * Format Excel sheet into custom object (Excel,ExcelTable...) 9 | * Edit .xlsx file in Unity EditorWindow 10 | * Generate .cs model according to .xls 11 | * Conver .xlsx file to JSON format 12 | 13 | ## How to use 14 | #### read & write 15 | ``` c# 16 | string excelPath = Application.dataPath + "/Test/Test.xlsx"; 17 | string outputPath = Application.dataPath + "/Test/Test2.xlsx"; 18 | Excel xls = ExcelHelper.LoadExcel(excelPath); 19 | xls.ShowLog(); 20 | 21 | xls.Tables[0].SetValue(1, 1, "???"); 22 | ExcelHelper.SaveExcel(xls, outputPath); 23 | ``` 24 | #### generate .cs file 25 | ``` c# 26 | string path = Application.dataPath + "/Test/Test4.xlsx"; 27 | Excel xls = ExcelHelper.LoadExcel(path); 28 | ExcelDeserializer ed = new ExcelDeserializer(); 29 | ed.FieldNameLine = 1; 30 | ed.FieldTypeLine = 2; 31 | ed.FieldValueLine = 3; 32 | ed.IgnoreSymbol = "#"; 33 | ed.ModelPath = Application.dataPath + "/Editor/Excel4Unity/DataItem.txt"; 34 | ed.GenerateCS(xls.Tables[0]); 35 | ``` 36 | #### convert to json 37 | ``` c# 38 | Object[] objs = Selection.objects; 39 | for (int i = 0; i < objs.Length; i++) 40 | { 41 | string path = AssetDatabase.GetAssetPath(objs[i]); 42 | if (path.EndsWith(".xlsx")) 43 | { 44 | Excel4Unity.ParseFile(path); 45 | } 46 | else 47 | { 48 | EditorUtility.DisplayDialog("提示", "暂不支持的文件格式" + path, "ok"); 49 | return; 50 | } 51 | } 52 | AssetDatabase.Refresh(); 53 | ``` 54 | ## Dependency 55 | 56 | * EEPlus 57 | * .Net 2.0 instead of .Net 2.0 Subset if you want to do excel job runtime 58 | 59 | ## Version 60 | 61 | Unity 4.x or higher 62 | 63 | -------------------------------------------------------------------------------- /doc/001.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/joexi/Excel4Unity/4dcc0bfae8b6d5caf52fb72b743f2b0de8cf9956/doc/001.png --------------------------------------------------------------------------------