[英]in C# using oledb connection string how to Convert Scientific Notation to text strings?
I have a set of data that is downloaded as a Excel file using OLEDB connection string like so: 我有一组数据使用OLEDB连接字符串下载为Excel文件,如下所示:
4552 4552
3.00E+03 3.00E + 03
3.00E+22 3.00E + 22
3F45 3F45
3.00E+99 3.00E + 99
DD56677 37 DD56677 37
Excel automatically thinks that 3E03, 3E22 and 3E99 are numbers and makes them look like above.. Excel会自动认为3E03、3E22和3E99是数字,并使它们看起来像上面。
how to get it as a string ? 如何获得它作为字符串?
my code is 我的代码是
DataTable dataTable = new DataTable();
strExcelConn = "Provider=Microsoft.Jet.OLEDB.4.0;"
+ "Data Source=" + strFilePath + ";"
+ "Extended Properties='Excel 8.0;HDR=" + header + ";IMEX=1;TypeGuessRows=0;ImportMixedTypes=Text'";
OleDbConnection connection = new OleDbConnection(strExcelConn);
using (OleDbCommand command = new OleDbCommand())
using (OleDbDataAdapter adapter = new OleDbDataAdapter(command))
{
command.Connection = connection;
//Check if the Sheet Exists
connection.Open();
DataTable dtExcelSchema;
//Get the Schema of the WorkBook
dtExcelSchema = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
connection.Close();
connection.Open();
DataSet ds = new DataSet();
string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
command.CommandText = "SELECT * From [" + SheetName + "]";
adapter.SelectCommand = command;
adapter.Fill(dataTable);
connection.Close();
}
please can any one help me to get this colum as a string 请任何人可以帮助我将此字符串作为字符串
Have a look at this StackOverflow question entitled How to convert a string containing an exponential number to decimal and back to string . 看一下这个题为“ 如何将包含指数数字的字符串转换为十进制然后再转换为string”的 StackOverflow问题。
They use the decimal.Parse(someMoneyVar, NumberStyles.Any)
method to do the conversion. 他们使用decimal.Parse(someMoneyVar, NumberStyles.Any)
方法进行转换。
在查询中按名称选择Excel列,然后使用CStr(<columnName>)
将所需的列转换为字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.