在Unity中从excel中检索元数据

我正在使用ac#Unity脚本中的ODBC访问.xsl文件中的数据。 连接起作用,我可以从文件中检索数据,但是我的元数据有问题。 当我调用GetSchema(string)函数时,它会陷入无限的recursion调用,直到它导致堆栈溢出。 不pipe我试图得到什么特定的模式,这个问题都会发生。

这是我正在使用的代码:

string connectionString = "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=" + file + ";UNICODESQL=1;Unicode=yes;"; OdbcConnection dbCon = null; OdbcDataReader dbData = null; try { dbCon = new OdbcConnection(connectionString); Debug.Log(connectionString); dbCon.Open(); DataTable sheets = dbCon.GetSchema(OdbcMetaDataCollectionNames.Tables); foreach(DataRow sheet in sheets.Rows) { string sheetName = sheet["TABLE_NAME"].ToString().Trim('\'').TrimEnd('$'); OdbcCommand dbCommand = new OdbcCommand("SELECT * FROM [" + sheetName + "$]", dbCon); DataTable data = new DataTable(sheetName); dbData = dbCommand.ExecuteReader(); data.Load(dbData); } } catch (Exception ex) { if (ex != null) { Debug.LogError(ex.Message); Debug.LogError(ex.StackTrace); } else Debug.LogError("Exception raise loading '" + file + "'"); } finally { if (dbData != null) dbData.Close(); if (dbCon != null) dbCon.Close(); } 

}

我自己遇到了这个问题。 它与monchevelop的getschema(string str)的实现有关。 它不会做人们所期望的; 它会调用其中一个实例,然后recursion调用它(这会导致堆栈溢出),如果连接已closures,则会抛出exception,另一方面会自行调用。 换句话说,它不会返回它将要返回的东西,它会调用自己,直到stackoverflow或连接被closures(这可能不会发生,因为closures命令通常后来被调用)。

 public override DataTable GetSchema (string collectionName) { return GetSchema (collectionName, null); } public override DataTable GetSchema (string collectionName, string [] restrictionValues) { if (State == ConnectionState.Closed) throw ExceptionHelper.ConnectionClosed (); return GetSchema (collectionName, null); } 

^从文档: https : //github.com/mono/mono/blob/mono-4.0.0-branch/mcs/class/System.Data/System.Data.Odbc/OdbcConnection.cs

这是你的错误的原因,但不幸的是我现在还没有任何真正的解决scheme,但我的解决方法可能对某人有用。 我想在我的Excel文件中得到一些表单名称,所​​以我所做的就是添加所有我想在特定工作表“Unity”中使用的sheetNames。 然后我阅读,以获取sheetnames,然后逐个加载它们。

这是一个非常容易出错的解决scheme,因为它依赖于手册名单上的名单,这个名单是正确的,但我按时间,没有其他已知的select,但也许可以帮助某人。