[英]in C# using oledb connection string how to Convert Scientific Notation to text strings?
我有一组数据使用OLEDB连接字符串下载为Excel文件,如下所示:
4552
3.00E + 03
3.00E + 22
3F45
3.00E + 99
DD56677 37
Excel会自动认为3E03、3E22和3E99是数字,并使它们看起来像上面。
如何获得它作为字符串?
我的代码是
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();
}
请任何人可以帮助我将此字符串作为字符串
看一下这个题为“ 如何将包含指数数字的字符串转换为十进制然后再转换为string”的 StackOverflow问题。
他们使用decimal.Parse(someMoneyVar, NumberStyles.Any)
方法进行转换。
在查询中按名称选择Excel列,然后使用CStr(<columnName>)
将所需的列转换为字符串
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.