需要帮助将文本以持续时间格式转换为Google表格

发布于 2025-01-21 17:13:14 字数 374 浏览 1 评论 0 原文

在这里寻求一些帮助,我尝试在Google表上以持续时间格式将文本转换为时间,我使用了一些基本的曲目来分解文本(以D(Dise)H(days)H(hour)M(小时)M(分钟)和S(第二)将然后烘烤到时间函数中的值,但是对于24小时以上的输出,我无法在375小时的图像中正确格式化IE,应显示375:00:00或[H]或[H]:MM:SS:

吗?

想法

有什么 /电子表格/D/1YWHM5TPALOULHMBFDR8CZJSER7LBCEWLQRM9F8JCV9C/EDIT#GID = 0

Asking for some help here, im trying to convert text to time in duration format on Google Sheets, i´ve used some basic fuctions to to breakdown text (with delimiters as d (days) h (hour) m(minute) and s(second) into values that were then baked into a time function, however for outputs over 24 hours I was unable to get it to format properly i.e. in the image below 375 hrs should show 375:00:00 or [H]:mm:ss

Any ideas here?

Sharing the doc

https://docs.google.com/spreadsheets/d/1YWHM5tPaLOulHMbfdR8CZJsER7LBceWLQrm9f8JcV9c/edit#gid=0

enter image description here

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

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

发布评论

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

评论(4

风苍溪 2025-01-28 17:13:14

尝试,在J12中

=(G12+H12/60+I12/60/60)/24

使用持续时间格式

Try, in J12

=(G12+H12/60+I12/60/60)/24

then apply duration format
enter image description here

九歌凝 2025-01-28 17:13:14

尝试:

=FLATTEN(INDEX(QUERY(, "select  "&TEXTJOIN(",", 1, 
 SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B7:B27, 
 "d", "*86400"), "h", "*3600"), "m", "*60"), "s", "*1"), " ", "+")))/86400, 2))

“


更新

改进版本:

=INDEX(IFERROR(1/(1/BYROW(B3:B15, LAMBDA(i, LET(x, "(\d+)\s*", SUM(IFERROR(
 REGEXEXTRACT(i, x&{"d"; "h"; "m"; "s"}), 0)*{86400; 3600; 60; 1})/86400))))))

​src =“ https://i.sstatic.net/mltvxced.png” alt =“在此处输入图像说明”>

try:

=FLATTEN(INDEX(QUERY(, "select  "&TEXTJOIN(",", 1, 
 SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(SUBSTITUTE(B7:B27, 
 "d", "*86400"), "h", "*3600"), "m", "*60"), "s", "*1"), " ", "+")))/86400, 2))

enter image description here


update

improved version:

=INDEX(IFERROR(1/(1/BYROW(B3:B15, LAMBDA(i, LET(x, "(\d+)\s*", SUM(IFERROR(
 REGEXEXTRACT(i, x&{"d"; "h"; "m"; "s"}), 0)*{86400; 3600; 60; 1})/86400))))))

enter image description here

enter image description here

嘴硬脾气大 2025-01-28 17:13:14

使用 Regexextract(),如下:

=arrayformula( 
  iferror(regexextract(B7:B, "(\d+)\s*h"), 0) & ":" & 
  iferror(regexextract(B7:B, "(\d+)\s*m"), 0) & ":" & 
  iferror(regexextract(B7:B, "(\d+)\s*s"), 0) 
)

公式提供文本字符串。要获取数字持续时间,请使用 value(),例如:

=arrayformula( 
  iferror( 1 / 
    value( 
      iferror(regexextract(B7:B, "(\d+)\s*h"), 0) & ":" & 
      iferror(regexextract(B7:B, "(\d+)\s*m"), 0) & ":" & 
      iferror(regexextract(B7:B, "(\d+)\s*s"), 0) 
    ) 
  ^ -1 ) 
)

格式列为 format>数字>持续时间

如果您要转换的文本字符串中有许多组件,则仅使用一个 regextextract()可能是有益的,可以使用最近引入的lambda函数:

=arrayformula( 
  map( 
    B7:B, 
    lambda( 
      duration, 
      if( 
        len(duration), 
        join( 
          ":", 
          iferror( 
            regexextract( 
              duration, 
              { "(\d+)\s*h"; "(\d+)\s*m"; "(\d+)\s*s" } 
            ), 
            0 
          ) 
        ), 
        iferror(1/0) 
      ) 
    ) 
  ) 
)

请参见 this Answer 以说明日期和时间值在电子表格中的工作方式。

Use regexextract(), like this:

=arrayformula( 
  iferror(regexextract(B7:B, "(\d+)\s*h"), 0) & ":" & 
  iferror(regexextract(B7:B, "(\d+)\s*m"), 0) & ":" & 
  iferror(regexextract(B7:B, "(\d+)\s*s"), 0) 
)

The formula gives text strings. To get numeric durations, use value(), like this:

=arrayformula( 
  iferror( 1 / 
    value( 
      iferror(regexextract(B7:B, "(\d+)\s*h"), 0) & ":" & 
      iferror(regexextract(B7:B, "(\d+)\s*m"), 0) & ":" & 
      iferror(regexextract(B7:B, "(\d+)\s*s"), 0) 
    ) 
  ^ -1 ) 
)

Format the result column as Format > Number > Duration.

In the event there are many components in the text string you are converting, it may be beneficial to use just one regextextract(), which is possible using the recently introduced lambda functions:

=arrayformula( 
  map( 
    B7:B, 
    lambda( 
      duration, 
      if( 
        len(duration), 
        join( 
          ":", 
          iferror( 
            regexextract( 
              duration, 
              { "(\d+)\s*h"; "(\d+)\s*m"; "(\d+)\s*s" } 
            ), 
            0 
          ) 
        ), 
        iferror(1/0) 
      ) 
    ) 
  ) 
)

See this answer for an explanation of how date and time values work in spreadsheets.

梦年海沫深 2025-01-28 17:13:14

带有Regextract的TimeValue

此方法利用时间值函数,而不是除以几天的分数。

假设您的时间文本字符串在A列中:

=BYROW(A2:A, LAMBDA(r, IF(LEN(r),
   IFNA(REGEXEXTRACT(r,"(\d*)d"))+
   TIMEVALUE(JOIN(":",
     MAP({"h","m","s"}, LAMBDA(t, 
       IFNA(REGEXEXTRACT(r,"(\d*)"&t),0))))),)))

说明

  1. byrow将您的每个时间字符串通过行传递到lambda函数中,该函数将当前行存储在 r 中,
  2. 如果 r 使用RegeXextract从字符串中返回lambda的公式首次返回(用LEN进行测试),并将结果添加到TimeValue函数中。
  3. TimeValue函数使用映射将您的每个时间定义器传递数小时,分钟和秒,一一逐一传递到一个lambda函数中,
  4. 该函数存储了当前时间定界符在 t 中,lambda的公式使用regexextract返回由 r t 界定的数字,如果找不到 t ,则IFNA返回0。
  5. JOIN通过该lambda的结果,并将其作为字符串返回,该字符串由Colons 用作TimeValue的 time_string 参数,该参数已添加到步骤#中计算的总天数2上面。

您可以将结果值编号为持续时间。

TIMEVALUE w/ REGEXEXTRACT

This approach leverages the TIMEVALUE function instead of dividing by fractions of days.

Assuming your time text strings are in Column A:

=BYROW(A2:A, LAMBDA(r, IF(LEN(r),
   IFNA(REGEXEXTRACT(r,"(\d*)d"))+
   TIMEVALUE(JOIN(":",
     MAP({"h","m","s"}, LAMBDA(t, 
       IFNA(REGEXEXTRACT(r,"(\d*)"&t),0))))),)))

Explanation

  1. BYROW passes each of your time strings, row by row, into a LAMBDA function that stores the current row in r
  2. If r is populated (tested with LEN) the LAMBDA's formula first returns any days from the string using REGEXEXTRACT and adds that result to a TIMEVALUE function.
  3. The TIMEVALUE function uses MAP to pass each of your time delimiters for hours, minutes, and seconds, one by one, into a LAMBDA function that stores the current time delimiter in t
  4. That LAMBDA's formula uses REGEXEXTRACT to return the number from r that's delimited by t, and IFNA returns 0 if t is not found.
  5. JOIN is passed the result of that LAMBDA and returns it as a string delimited by colons : which is used as TIMEVALUE's time_string argument which is added to the total days calculated in Step #2 above.

You can number format the resulting values as duration.

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