我有一组数据,使用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();
}
请任何人帮我把这个colum作为一个字符串
答案 0 :(得分:1)
看看这个名为How to convert a string containing an exponential number to decimal and back to string的StackOverflow问题。
他们使用decimal.Parse(someMoneyVar, NumberStyles.Any)
方法进行转换。
答案 1 :(得分:0)
在查询中按名称选择Excel列,然后使用CStr(<columnName>)