0
votes

what i've already done...

  1. reading the excel file content into datatable
  2. one of column contains data in scientific notation (e.g 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();
    

    how can scientific notation be converted to actual data (e.g 6754357899912)

1
Hey did you get this resolved?Capn Jack

1 Answers

0
votes

Try using this:

double result = Double.Parse("6.75436E+12", System.Globalization.NumberStyles.Float);

*NB that when you hover the value in c# it'll look like sci still but it is indeed a double.