hello,
here’s my code for read from excel file.
editor works fine but in the build the excel file is not read.
when i work in the editor the file is in the folder
c:\projectname\1.xls
in the build:
c:\1.xls
c:\project_Data\ 1.xls
using UnityEngine;
using System.Collections;
using System;
using System.Data;
using System.Data.Odbc;
public class ExcelReader : MonoBehaviour
{
String something;
public String Filename="1";
void Start ()
{
readXLS(Filename);
}
void readXLS(String Filename)
{
// Must be saved as excel 2003 workbook, not 2007, mono issue really
string con = "Driver={Microsoft Excel Driver (*.xls)}; DriverId=790; Dbq="+Filename+";";
string yourQuery = "SELECT * FROM [Foglio1$]";
OdbcConnection oCon = new OdbcConnection(con);
OdbcCommand oCmd = new OdbcCommand(yourQuery, oCon);
DataTable dtYourData = new DataTable("YourData");
oCon.Open();
OdbcDataReader rData = oCmd.ExecuteReader();
dtYourData.Load(rData);
rData.Close();
oCon.Close();
if(dtYourData.Rows.Count > 0)
{
prova = dtYourData.Rows[0][dtYourData.Columns[1].ColumnName].ToString();
if (something == "DESTROY!")
Destroy(GameObject.Find("Cube"));
print(something);
}
}
}