簡體   English   中英

在C#中使用oledb連接字符串如何將科學計數法轉換為文本字符串?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM