Home

Awesome

Excel4Unity

Excel for Unity

Provides

How to use

read & write

string excelPath = Application.dataPath + "/Test/Test.xlsx";
string outputPath = Application.dataPath + "/Test/Test2.xlsx";
Excel xls = ExcelHelper.LoadExcel(excelPath);
xls.ShowLog();

xls.Tables[0].SetValue(1, 1, "???");
ExcelHelper.SaveExcel(xls, outputPath);

generate .cs file

string path = Application.dataPath + "/Test/Test4.xlsx";
Excel xls =  ExcelHelper.LoadExcel(path);
ExcelDeserializer ed = new ExcelDeserializer();
ed.FieldNameLine = 1;
ed.FieldTypeLine = 2;
ed.FieldValueLine = 3;
ed.IgnoreSymbol = "#";
ed.ModelPath = Application.dataPath + "/Editor/Excel4Unity/DataItem.txt";
ed.GenerateCS(xls.Tables[0]);

convert to json

Object[] objs = Selection.objects;
for (int i = 0; i < objs.Length; i++)
{
    string path = AssetDatabase.GetAssetPath(objs[i]);
    if (path.EndsWith(".xlsx"))
    {
        Excel4Unity.ParseFile(path);
    }
    else
    {
        EditorUtility.DisplayDialog("提示", "暂不支持的文件格式" + path, "ok");
        return;
    }
}
AssetDatabase.Refresh();

Dependency

Version

Unity 4.x or higher