.net 4.0 对于.Net 4.0和.Net Framework客户端概要文件4.0,Oledb的行为有所不同
案例1: 在.Net Framework客户端配置文件中使用Oledb读取excel时,Oledb将忽略excel中给定的格式来读取excel中的数据 示例:1.98782637是实际值,但格式化后显示为1.99。 当我从代码中读取时,读取的值是1.98782637 案例2: 在.Net Framework中使用Oledb读取excel时,Oledb将读取格式化后excel中可用的数据 示例:1.98782637是实际值,但格式化后显示为1.99。 当我从代码中读取时,读取的值是1.99 下面是我在这两种情况下使用的代码.net 4.0 对于.Net 4.0和.Net Framework客户端概要文件4.0,Oledb的行为有所不同,.net-4.0,oledb,.net 4.0,Oledb,案例1: 在.Net Framework客户端配置文件中使用Oledb读取excel时,Oledb将忽略excel中给定的格式来读取excel中的数据 示例:1.98782637是实际值,但格式化后显示为1.99。 当我从代码中读取时,读取的值是1.98782637 案例2: 在.Net Framework中使用Oledb读取excel时,Oledb将读取格式化后excel中可用的数据 示例:1.98782637是实际值,但格式化后显示为1.99。 当我从代码中读取时,读取的值是1.99 下面是
DataSet dsoutlier = null;
OleDbDataAdapter oledbAdapterOutlier = null;
OleDbConnection oledbConnOutlier = new OleDbConnection();
string fileName = "C:\\Sample.xlsx";
oledbConnOutlier.ConnectionString= "Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source=" + fileName + ";Extended Properties='Excel 12.0 Xml;HDR=NO;IMEX=0;\'";
if (oledbConnOutlier.State == ConnectionState.Closed)
oledbConnOutlier.Open();
oledbAdapterOutlier = new OleDbDataAdapter("select F1,F9 from [Sheet1$] where F1 is not null", oledbConnOutlier);
dsoutlier = new DataSet();
try
{
oledbAdapterOutlier.Fill(dsoutlier);
int counter = 0;
foreach (var item in dsoutlier.Tables[0].Rows)
{
Console.Write(dsoutlier.Tables[0].Rows[counter][0]+" ");
Console.WriteLine(dsoutlier.Tables[0].Rows[counter++][1]);
}
}
catch (Exception ex)
{
}
finally
{
oledbConnOutlier.Close();
}
有没有办法在这两种情况下都包含和忽略格式设置?您是从电子表格中读取原始数据,而不是从格式化文本中读取。如何同时读取原始数据和格式化文本?有没有办法同时阅读这两种文字?