English 中文(简体)
Google 脚本: 时间格式化单元格导致错误: 溢流
原标题:Google Scripts: Time formatted cells cause Error: Overflow

我试图写一个自定义函数,该函数需要两个单元格区域(起始时间和停止时间)作为输入,然后输出总小时。如果单元格格式化为正常数字(即 9: 00pm 表示为 0.875),则函数正常。如果我将单元格格式化为单元格值,公式在“# NUM!” 中,工具提示是“error:overflower” 。是否有一种方法可以在不格式化的情况下读取原始单元格数据,以使我的公式有效?

公式代码

function getHoursTest(startRange, stopRange) {
  var hours = 0; // define "hours" with start value of 0
  var i = startRange.length - 1;  // define "i" and assign the position of the last array element

  while(i>=0){
        hours = hours + ((stopRange[i] - startRange[i])*24);
        i--
  }
  return hours;
}
最佳回答

当单元格格式化为日期或时间值时, 它的 s 值会被传递到 Apps 脚本作为 JavaScript 日期对象。 您可以使用以下代码来确定该值是否为日期 :

if (value instanceof Date) {
  ...
} else {
  ...
}
问题回答

暂无回答




相关问题
Table cell stretching

I have two columns in my table with equal width (50%, 50%). I am showing search results URL in them. For big urls the columns are stretching and destroying the layout. Any suggestion to the problem?

Add Semicolon to each value (each line) in a cell

I have the following values in a single cell let be A1 1234 567 454 Likewise all the A(N) are filled with values. N various from 1000 to 1500 I want this to get converted as 1234;567;454 Any ...

Blank when NaN in jqGrid cells

How to set blank instead of NaN in jqGrid cells ? Using formatter ? Is there an example?

BeginEdit of a specific Cell from code behind

Is possibile begin edit of a specific cell from code behind with DataGrid control (WPF Toolkit)? I have to enable the celledittemplate of first cell of selected row after a button action...how can I ...

提供数据

我想让浏览头和一栏头目从使用因特网部分数据GridView的图像中获得一个习俗背景。 甚至有可能这样做吗? 如果是,如何?

热门标签