Beispiel #1
0
        void import()
        {
            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");
            List <string> keys = new List <string> ();
            ExcelFile     ef   = ExcelFile.Load(file);
            //ExcelFile ef= ExcelFile.LoadFromDirectory(file,XlsxLoadOptions.XlsxDefault);
            //StringBuilder sb = new StringBuilder ();


            //first row for names of vaules
            ExcelWorksheet sheet = ef.Worksheets[0];
            //sheet.Calculate();//should work but doesn't
            ExcelCell tmpcell = sheet.Cells["XX100"];

            ExcelRow row = sheet.Rows[0];

            //get name of
            foreach (ExcelCell cell in row.AllocatedCells)
            {
                if (cell.ValueType != CellValueType.Null)
                {
                    keys.Add(cell.StringValue);
                }
            }

            int i = 0;

            int size = keys.Count;

            foreach (ExcelRow rows in sheet.Rows)
            {
                if (i == 0)
                {
                    i++;
                    continue;
                }
                if (rows.Cells [0].Value == null)
                {
                    break;
                }

                int    x      = 0;
                string name   = rows.Cells [0].StringValue;
                Object prefab = PrefabUtility.CreateEmptyPrefab(folder + "/" + name + ".prefab");
                //this is the error
                GameObject gb = (GameObject)GameObject.Instantiate <GameObject>((GameObject)tmp);                //All the casting to be safe
                foreach (ExcelCell cell in rows.AllocatedCells)
                {
                    if (x >= size)
                    {
                        break;
                    }

                    if (cell.Value == null)
                    {
                        continue;
                    }

                    tmpcell.Formula = cell.StringValue;
                    tmpcell.Calculate();
                    gb.SendMessage(keys[x], tmpcell.Value);
                    x++;
                }

                PrefabUtility.ReplacePrefab(gb, prefab, ReplacePrefabOptions.ConnectToPrefab);
                Debug.Log("prebab: " + name + " done");
            }
            Debug.Log("finished excel unity");
        }