简体   繁体   English

Excel Javascript API - 在相邻单元格上记录日期

[英]Excel Javascript API - Record Date on Adjacent Cell

I am new to Excel JavaScript. I'm trying to record the date a cell changed in column 4 and update column 7 with the date & time the change occurred.我是 Excel JavaScript 的新手。我正在尝试记录第 4 列中单元格更改的日期,并使用发生更改的日期和时间更新第 7 列。 I'm encountering parameter out of range whit the.getColumn statement.我在 .getColumn 语句中遇到参数超出范围。 Hope someone gives me some guidance.希望有人能给我一些指导。

function main(workbook: ExcelScript.Workbook) {
 var s= workbook.getActiveWorksheet();
  if(s.getName() =="Records"){
  var r = workbook.getActiveCell();
  if(r.getColumn(4)) {
      var nextCell = r.getOffsetRange(0, 3);
      nextCell.setValue(new Date());
  }
 }
}

This is because getColumn is to get a column contained in the range.这是因为getColumn是获取范围内包含的列。

You would need to use range.columnIndex == 4 , please note columnIndex is Zero-indexed.您需要使用range.columnIndex == 4 ,请注意 columnIndex 是零索引的。

function main(workbook: ExcelScript.Workbook) {
 var s= workbook.getActiveWorksheet();
  if(s.getName() =="Records"){
  var r = workbook.getActiveCell();
  r.load('columnIndex');
  await context.sync();

  if(r.columnIndex == 4) {
      var nextCell = r.getOffsetRange(0, 3);
      nextCell.setValue(new Date());

  }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM