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());
}