如何将文本导入时间格式?

发布于 2024-10-08 07:46:42 字数 263 浏览 0 评论 0原文

我有来自数据记录器的文本文件,其格式类似于

hh:mm, Data, Data

,我需要将其导入到 Excel 中。

我一生都无法弄清楚如何让 Excel 将 hh:mm 部分导入为(24 小时格式)时间而不是文本。是否可以?如果没有,是否有任何直接的方法可以将 hh:mm 文本列转换为 Excel 的时间格式? (我知道我可以写一个转换公式,但一定已经有内置的东西了,对吧?)

OS X 上的 Excel 2008

I have text files from a data logger in a format like this

hh:mm, Data, Data

that I need to import into Excel.

I cannot for the life of me figure out how to get Excel to import the hh:mm part as (24 hour format) time instead of text. Is it possible? If not is there any straight-forward way of converting a column of hh:mm text into Excel's time format? (I know I can write a conversion formula, but there must be something built-in already right?)

Excel 2008 on OS X

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

琉璃繁缕 2024-10-15 07:46:42

不确定是否有一个好的方法可以通过按钮来完成此操作,但是

=TIMEVALUE(A1)

A1 是您的日期应该可以解决问题。

Not sure there is a good way to do this with a button but

=TIMEVALUE(A1)

where A1 is your date should do the trick.

以往的大感动 2024-10-15 07:46:42

如果所有时间的格式都为 hh:mm,那么应该非常简单。

A       B           C            D
22:15   =LEFT(A1,2) =RIGHT(A1,2) =TIME(B2,C1,0)

您在这里所做的就是获取文本(A 列)并隔离小时(B 列)和分钟(C 列),然后使用 TIME 函数将它们重新组合在一起。

您甚至可以用一个公式来完成:

=TIME(LEFT(A1,2),RIGHT(A1,2),0)

If all of the times are formatted as hh:mm, it should be pretty simple.

A       B           C            D
22:15   =LEFT(A1,2) =RIGHT(A1,2) =TIME(B2,C1,0)

All you're doing here is taking the text (Column A) and isolating the hour (Column B) and minute (Column C) and using the TIME function to put them back together.

You could even do it in a single formula:

=TIME(LEFT(A1,2),RIGHT(A1,2),0)
她比我温柔 2024-10-15 07:46:42

在导入后将列格式化为时间为时已晚,但在应用 来自文本

虽然链接中未显示,但第 3 步(共 3 步)应允许您将相关列数据格式设置为“常规”,并将中午导入的数据显示为 0.5,显示为 12:00

It is too late to format the column as time after import but should be possible as part of the import when applying FROM TEXT.

Though not shown in the link, Step 3 of 3 should allow you to set the relevant Column data format to General and that import noon for example as 0.5 displayed as 12:00.

萌辣 2024-10-15 07:46:42

假设我有一个名为 Time.txt 的文件,其中包含一列时间,如下所示:

22:13
09:25
12:20

我想将它们读入 Excel s/sheet 并将它们放在范围 A1 到 A3 中,并将它们格式化为 <代码>hh:mm:ss。此代码显示了如何实现这一点:(

注意:您需要添加对 Microsoft Scripting Runtime 的引用才能使其正常工作。在 VB 编辑器中:工具 > 参考 > Microsoft 脚本运行时)

Sub GetTimesFromFile()

Dim oFSO As New Scripting.FileSystemObject
Dim targetFile As Object
Set targetFile = oFSO.OpenTextFile("C:\Time.txt") //Change for your file path as appropriate

Dim cellCount As Long
cellCount = 1

Do Until targetFile.AtEndOfStream
    Cells(cellCount, 1) = targetFile.ReadLine
    Cells(cellCount, 1).NumberFormat = "hh:mm:ss" //Time format I want
    cellCount = cellCount + 1
Loop

End Sub

Suppose I have a file called Time.txt with a single column of times as follows:

22:13
09:25
12:20

I would like to read them into an excel s/sheet and place them in Range A1 to A3 and format them as hh:mm:ss. This code shows how this may be achieved:

(NB: You need to add a reference to the Microsoft Scripting Runtime to get this to work. In VB editor: Tools > References > Microsoft Scripting Runtime)

Sub GetTimesFromFile()

Dim oFSO As New Scripting.FileSystemObject
Dim targetFile As Object
Set targetFile = oFSO.OpenTextFile("C:\Time.txt") //Change for your file path as appropriate

Dim cellCount As Long
cellCount = 1

Do Until targetFile.AtEndOfStream
    Cells(cellCount, 1) = targetFile.ReadLine
    Cells(cellCount, 1).NumberFormat = "hh:mm:ss" //Time format I want
    cellCount = cellCount + 1
Loop

End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文