Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/google-sheets/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google sheets 谷歌脚本-在每次导出时向单元格添加1_Google Sheets - Fatal编程技术网

Google sheets 谷歌脚本-在每次导出时向单元格添加1

Google sheets 谷歌脚本-在每次导出时向单元格添加1,google-sheets,Google Sheets,我正在寻找一种在谷歌表单上创建自动编号的方法。可能很简单,但我对脚本了解不多 过程是,每次用户下载工作表时,A1中的数字都会上升一个。使用Otinkinit在PropertiesService中设置初始值。然后可以将loadSerial放入下载脚本中 function onOpen(e) { SpreadsheetApp.getUi().createMenu('My Tools') .addItem('otOInk','otOInk') .addItem('otOInkIni

我正在寻找一种在谷歌表单上创建自动编号的方法。可能很简单,但我对脚本了解不多


过程是,每次用户下载工作表时,A1中的数字都会上升一个。

使用Otinkinit在PropertiesService中设置初始值。然后可以将loadSerial放入下载脚本中

function onOpen(e)
{
  SpreadsheetApp.getUi().createMenu('My Tools')
    .addItem('otOInk','otOInk')
    .addItem('otOInkInit', 'otOInkInit')
    .addItem('loadSerial', 'loadSerial')
    .addToUi();
}

//provides an otOInk number and increments to the next one 
function otOInk() 
{
  var num=PropertiesService.getScriptProperties().getProperty('otOInk');
  if(num)
  {
    PropertiesService.getScriptProperties().setProperty('otOInk',Number(num)+1);
    return num;
  }
}
//use to setup the otOInk property in the PropertiesService
function otOInkInit(initialValue)
{
  var initialValue=(typeof(initialValue)!='undefined')?initialValue:0;
  PropertiesService.getScriptProperties().setProperty('otOInk',initialValue);
}
//loads the otOInk number into a cell of a named sheet
function loadSerial(cellA1Notation,sheetName)
{
  var cellA1Notation=(typeof(cellA1Notation)!='undefined')?cellA1Notation:'A1';
  var sheetName=(typeof(sheetName)!='undefined')?sheetName:'Sheet1';
  var ss=SpreadsheetApp.getActiveSpreadsheet();
  var sht=ss.getSheetByName(sheetName);
  var cell=sht.getRange(cellA1Notation);
  cell.setValue(otOInk());
}