简体   繁体   English

从excel导入数据并插入到sql表中

[英]Importing data from excel and inserting into sql tables

I am Importing data from excel and inserting into a sql table. 我从excel导入数据并插入到sql表中。 One of the fields in my Excel file is populated with a time value. 我的Excel文件中的一个字段填充了时间值。 I want to import that time value as a string into my sql table. 我想将该时间值作为字符串导入到我的sql表中。 When i do that i get a weird value in my sql table. 当我这样做时,我在我的SQL表中得到一个奇怪的值。 Excel value is: 07:00 and after inserting that as a string into the sql table the time values looks like this: 0,29166666667 . Excel值为: 0700并将其作为字符串插入sql表后,时间值如下所示: 0,29166666667

The reason for importing it as a string value is that you have to be able to define Days in the same field. 将其作为字符串值导入的原因是您必须能够在同一字段中定义Days。 Like this : D2 10:30 . 像这样: D2 10:30 When i import this kind of values it is inserted correctly. 当我导入这种值时,它被正确插入。

can anyone help ? 有人可以帮忙吗?

Excel stores dates and times as number-values from 0 to 0.99999999 +x days. Excel将日期和时间存储为0到0.99999999 + x天的数字值。

0.29166666667 would be like 00.01.1900 07:00:00 , which seems to be correct in your case. 0.29166666667就像是00.01.1900 07:00:00 ,这在你的情况下似乎是正确的。

So, you would have to use some reformatting or conversion of this value, before using it as a direct string-input. 因此,在将其用作直接字符串输入之前,您必须使用此值的一些重新格式化或转换。

In VBA you could use Format(myValue,"DD-MM-YYYY hh:mm:ss") . 在VBA中,您可以使用Format(myValue,"DD-MM-YYYY hh:mm:ss")

The equivalent worksheet function would be TEXT(A1,"DD-MM-YYYY hh:mm:ss") . 等效的工作表函数是TEXT(A1,"DD-MM-YYYY hh:mm:ss")

The format-code depends on your regional settings. 格式代码取决于您的区域设置。 You might want to try something like this Format(myTime, "Long Time") , if you preffer to use excel-defined time-formats. 如果你想使用excel定义的时间格式,你可能想尝试类似这种Format(myTime, "Long Time")东西。

Because you did not post any code, I am not sure about how you import your excel-data. 因为您没有发布任何代码,我不确定如何导入您的Excel数据。 But I would say, the fastest way to get better results, would be setting up a new column, using the TEXT formula with a reference to the previously time-column and use this new formatted column as input for your sql-db. 但我想说,获得更好结果的最快方法是设置一个新列,使用TEXT公式并引用之前的时间列,并使用这个新的格式化列作为sql-db的输入。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM