为了账号安全,请及时绑定邮箱和手机立即绑定

从当前行单元格中减去两个值并将该值输出到新的单元格行(谷歌脚本)

从当前行单元格中减去两个值并将该值输出到新的单元格行(谷歌脚本)

qq_遁去的一_1 2022-11-11 14:54:52
我正在制作一个 Google 表格,用于跟踪打卡时间。我想添加一个列 e,它将计算给定开始时间(c 列)和结束时间(d 列)的工作小时数。我该如何实施呢?这是我的代码:function setValue(cellName, value){  SpreadsheetApp.getActiveSpreadsheet().getRange(cellName).setValue(value);}function getValue(cellName){  return SpreadsheetApp.getActiveSpreadsheet().getRange(cellName).getValue();}function getNextRow(){  return getCurrentRow() + 1;}function getCurrentRow(){  return SpreadsheetApp.getActiveSpreadsheet().getLastRow();}function addStart(a, b, c, d){  var row = getNextRow();  setValue('A' + row, a); // employee name row  setValue('B' + row, b); // date row  setValue('C' + row, c); // clock in time row}function addEnd(endTime) {  var row = getCurrentRow();  setValue('D' + row, endTime); // }function updateRow(e){  // declare row e  var row = getCurrentRow();  setValue('E' + row, e) }function punchIn(){  addStart("Faiq Ashraf", new Date(), date(), "")}function punchOut(){  addEnd(date());}function totalHours(){  // function used to update column e with our total hours worked  var total = getCurrentRow().addEnd(d) - getCurrentRow().addStart(c)  updateRow(total);}function date(){  var dd = new Date();  var currentTime = dd.toLocaleTimeString();  return currentTime}javascript谷歌应用脚本谷歌表格
查看完整描述

1 回答

?
鸿蒙传说

TA贡献1865条经验 获得超7个赞

实际上,我目前在 Google 表格中使用了我为此目的制作的解决方案,您根本不需要使用自定义函数。

只需将以下函数放在您的示例中的 E 行中:

=Hour(D1-C1)+(Minute(D1-C1)/60)


查看完整回答
反对 回复 2022-11-11
  • 1 回答
  • 0 关注
  • 60 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信