[英]Excel concatenate cell values from cells of different types
I have an Excel spreadsheet where I'm unable to concatenate a line to group the cells together.我有一个 Excel 电子表格,我无法连接一行以将单元格组合在一起。 In my spreadsheet I input dates and times to auto-add hours (a schedule with daily start/stop times).在我的电子表格中,我输入日期和时间以自动添加小时数(包含每日开始/停止时间的时间表)。 I'm trying to find a way to string these together to insert the lines into a Word doc.我试图找到一种方法将它们串在一起以将这些行插入到 Word 文档中。
Excel: (* indicates formula/calculation) Excel:(*表示公式/计算)
| | DATE |日期 | START |开始| STOP |停止 | Total*|总计*| Day* |天* | ddd* | DD* |
| | 2/27/23 | 2/27/23 | 8:00 AM |上午 8:00 | 7:00 PM |下午 7:00 | 11 | 11 | Mon |星期一 | 2/27 | 2/27 |
I've tried using =text() and =value() but nothing seems to get me the information I need in a string.我试过使用 =text() 和 =value() 但似乎没有任何东西可以让我在字符串中获得我需要的信息。 I do not want to do a copy/paste - the idea is to input the data once, and have another sheet read that in to a chart that can be inserted in to Word.我不想做复制/粘贴——我的想法是输入一次数据,然后让另一张纸将其读入可以插入到 Word 中的图表中。 What am I missing..?我错过了什么..?
=CONCATENATE(Rates!I9," ",Rates!H9," from ",Rates!C9," to ",Rates!D9)
I was expecting: Mon 2/27 from 8:00 AM to 7:00 PM我期待:2 月 27 日星期一上午 8:00 到晚上 7:00
I'm getting: Mon 44984 from 0.333333333333333 to 0.895833333333333我得到:周一 44984 从 0.333333333333333 到 0.895833333333333
This is one way to do it.这是一种方法。 Let's generate in A2
a timestamp via NOW()
function, and in B2
two hours after NOW() + 2/24
.让我们通过NOW()
function 在A2
中生成一个时间戳,并在NOW() + 2/24
两小时后在B2
中生成一个时间戳。 Then in C2
you can build the following output as follow:然后在C2
中,您可以按如下方式构建以下 output:
=CONCAT(TEXT(A2, "ddd mm/dd"), " from ",
TEXT(A2-TRUNC(A2), "hh:mm AM/PM"), " to ",
TEXT(B2-TRUNC(B2), "hh:mm AM/PM"))
Note : Dates in excel are represented as a Whole number and the time is the decimal part of that number.注意:excel 中的日期表示为整数,时间是该数字的小数部分。 The first hour is represented as 1/24
.第一个小时表示为1/24
。
Or you can create a user LAMBDA
function to get the decimal part ( GETDEC
) to simplify it:或者您可以创建一个用户LAMBDA
function 来获取小数部分 ( GETDEC
) 以简化它:
=LET(GETDEC, LAMBDA(x, x-TRUNC(x)), CONCAT(TEXT(A2, "ddd mm/dd"), " from ",
TEXT(GETDEC(A2), "hh:mm AM/PM"), " to ", TEXT(GETDEC(B2), "hh:mm AM/PM")))
Here is the output:这是 output:
or just putting it all together in a user LAMBDA
function ( GET_TIME_INFO
) that can be used inside a LET
function:或者只是将它们放在一个用户LAMBDA
function ( GET_TIME_INFO
) 中,可以在LET
function 中使用:
=LET(GET_TIME_INFO, LAMBDA(a,b, LET(GETDEC, LAMBDA(x, x-TRUNC(x)),
CONCAT(TEXT(a, "ddd mm/dd"), " from ",
TEXT(GETDEC(a), "hh:mm AM/PM"), " to ", TEXT(GETDEC(b), "hh:mm AM/PM"))
)), GET_TIME_INFO(A2,B2)
)
or you can define it in Name Manager and just use it, like any other regular Excel function: GET_TIME_INFO(A2,B2)
.或者您可以在名称管理器中定义它并使用它,就像任何其他常规 Excel function: GET_TIME_INFO(A2,B2)
一样。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.