【发布时间】:2011-09-23 05:19:24
【问题描述】:
Excel 已控制格式,如 here 中所述
在我的 excel 示例数据(字母数字)中:-
在我的示例代码中:-
DataTable dt = new DataTable("PartUpload");
DataColumn column;
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.AllowDBNull = true;
column.ColumnName = "Part Original";
dt.Columns.Add(column);
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.AllowDBNull = true;
column.ColumnName = "Part_ToString";
dt.Columns.Add(column);
column = new DataColumn();
column.DataType = System.Type.GetType("System.String");
column.AllowDBNull = true;
column.ColumnName = "Part_TryParse";
dt.Columns.Add(column);
string connStr = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\seahc1\Desktop\test1.xls;Extended Properties=ImportMixedTypes=Text;Excel 8.0;HDR=Yes;IMEX=1";
OleDbConnection objConn = new OleDbConnection(connStr);
objConn.Open();
OleDbDataAdapter adap = new OleDbDataAdapter(@"SELECT Part as [Part Original]FROM [Sheet1$]", connStr);
adap.Fill(dt);
foreach (DataRow row in dt.Rows)
{
row["Part_ToString"] = row["Part Original"].ToString();
double doubleConverResult;
bool result = double.TryParse(row["Part Original"].ToString(), NumberStyles.Any, CultureInfo.InvariantCulture, out doubleConverResult);
if (result)
{
row["Part_TryParse"] = doubleConverResult.ToString();
}
}
Part_ToString = 指数 = "3.1270013375e+011"
Part_TryParse = 四舍五入=312700133750
我调试并发现adap.Fill(dt) 用指数数据填充数据表。
我如何通过 C# 程序获得确切的值,因为我不希望最终用户格式化他们的 excel 电子表格。
请指教,谢谢。
【问题讨论】:
-
呃,什么?问题没有任何意义...
-
显然存在语言障碍,我们无法理解您想要的内容。
标签: c# excel tostring tryparse exponential