Excel Scientific Notation以C#编程方式进行字符串转换

时间:2017-08-08 18:55:31

标签: c# asp.net excel datatable

我已经做过的......

  1. 将excel文件内容读入datatable
  2. 其中一列包含科学记数法的数据(例如6.75436E + 12)

        string filename = Server.MapPath("testfile.xlsx");
        string conStr = "";
        string Extension = ".xlsx";
        switch (Extension)
        {
            case ".xls": //Excel 97-03
                conStr = ConfigurationManager.ConnectionStrings["Excel03ConString"]
                         .ConnectionString;
                break;
            case ".xlsx": //Excel 07
                conStr = ConfigurationManager.ConnectionStrings["Excel07ConString"]
                          .ConnectionString;
                break;
        }
        conStr = String.Format(conStr, filename, "Yes");
        OleDbConnection connExcel = new OleDbConnection(conStr);
        OleDbCommand cmdExcel = new OleDbCommand();
        OleDbDataAdapter oda = new OleDbDataAdapter();
        DataTable dt = new DataTable();
        cmdExcel.Connection = connExcel;
    
        //Get the name of First Sheet
        connExcel.Open();
        DataTable dtExcelSchema;
        dtExcelSchema = connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
        connExcel.Close();
    
        //Read Data from First Sheet
        connExcel.Open();
        cmdExcel.CommandText = "SELECT * From [" + SheetName + "]";
        oda.SelectCommand = cmdExcel;
        oda.Fill(dt);
        connExcel.Close();
    

    如何将科学记数法转换为实际数据(例如6754357899912)

1 个答案:

答案 0 :(得分:0)

尝试使用:

<input type="text" class="form-control" aria-label="Text input with radio button" name="transType" id="transcationOtherText" onfocus="otherTextBox(transcationOtherText);" placeholder="Other">

*请注意,当您将值悬停在c#中时,它看起来仍然像sci,但确实是一个双倍。