try
{
string Ext = Path.GetExtension(Constants.XlFile);
string connectionString = "";
if (Ext == ".xls")
{ //For Excel 97-03
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source =" + Constants.XlFile + "; Extended Properties = 'Excel 8.0;HDR=YES'";
}
else if (Ext == ".xlsx")
{ //For Excel 07 and greater
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source =" + Constants.XlFile + "; Extended Properties = 'Excel 8.0;HDR=YES'";
}
OleDbConnection conn = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
OleDbDataAdapter dataAdapter = new OleDbDataAdapter();
cmd.Connection = conn;
conn.Open();
DataTable dtSchema;
dtSchema = conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string ExcelSheetName = dtSchema.Rows[0]["TABLE_NAME"].ToString();
conn.Close();
//Read all data of fetched Sheet to a Data Table
conn.Open();
cmd.CommandText = "SELECT * From [" + ExcelSheetName + "]";
dataAdapter.SelectCommand = cmd;
dataAdapter.FillSchema(dt, SchemaType.Source);
dt.Columns[0].DataType = typeof(String);
dt.Columns[1].DataType = typeof(String);
dt.Columns[2].DataType = typeof(String);
dt.Columns[3].DataType = typeof(String);
dt.Columns[4].DataType = typeof(DateTime);
dt.Columns[5].DataType = typeof(String);
dt.Columns[6].DataType = typeof(String);
dt.Columns[7].DataType = typeof(String);
//dataGrid2.Columns[4].CellTemplate.ValueType = typeof(DateTime);
dataAdapter.Fill(dt);
dataGrid2.DataSource = dt;
conn.Close();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
所以我在
时处理与此对象的绑定data1 : {
id : 10,
name : 'franck',
param:{
style:'desert'
isUsed : true,
},
};
在KnockOut文件中,如果出现:
var rawValue = valueAccessor()
2小时后,我发现属性以“ param ___” +我的专有名称开头,因为经典的param.style无法正常工作。
下面的代码仅在布尔属性上发生...也许KO有一个特殊的布尔名称吗?
data-bind = "value : id" // all is OK is an Observable
data-bind = "value : param___style" // all is OK is an Observable
对不起,我的英语不好。