Je veux lire le file excel dans unity3d et j'ai ce code
using UnityEngine; using System.Collections; using System.Data.Odbc; using System.Data; public class ExcelReader : MonoBehaviour { // Use this for initialization void Start() { readXLS(Application.dataPath + "/Book1.xls"); Debug.Log(Application.dataPath); } // Update is called once per frame void Update() { } void readXLS(ssortingng filetoread) { // Must be saved as excel 2003 workbook, not 2007, mono issue really ssortingng con = "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq=" + filetoread + ";"; Debug.Log(con); ssortingng yourQuery = "SELECT * FROM [Sheet1$]"; // our odbc connector OdbcConnection oCon = new OdbcConnection(con); // our command object OdbcCommand oCmd = new OdbcCommand(yourQuery, oCon); // table to hold the data DataTable dtYourData = new DataTable("YourData"); // open the connection oCon.Open(); // lets use a datareader to fill that table! OdbcDataReader rData = oCmd.ExecuteReader(); // now lets blast that into the table by sheer man power! dtYourData.Load(rData); // close that reader! rData.Close(); // close your connection to the spreadsheet! oCon.Close(); // wow look at us go now! we are on a roll!!!!! // lets now see if our table has the spreadsheet data in it, shall we? if (dtYourData.Rows.Count > 0) { // do something with the data here // but how do I do this you ask??? good question! for (int i = 0; i < dtYourData.Rows.Count; i++) { // for giggles, lets see the column name then the data for that column! Debug.Log(dtYourData.Columns[0].ColumnName + " : " + dtYourData.Rows[i][dtYourData.Columns[0].ColumnName].ToSsortingng() + " | " + dtYourData.Columns[1].ColumnName + " : " + dtYourData.Rows[i][dtYourData.Columns[1].ColumnName].ToSsortingng() + " | " + dtYourData.Columns[2].ColumnName + " : " + dtYourData.Rows[i][dtYourData.Columns[2].ColumnName].ToSsortingng()); } } } }
mais comme mon programme commence à me donner cette erreur.
OdbcException: ERROR [IM002] [Microsoft] [ODBC Driver Manager] Le nom de la source de données n'est pas trouvé et aucun pilote par défaut n'a spécifié System.Data.Odbc.OdbcConnection.Open ()
Pourquoi je reçois cela? Mon DSN user inclut également le file Excel