0
Googleスプレッドシートに自動番号を作成する方法を探しています。シンプルになるかもしれませんが、スクリプトについてはあまりよく分かりません...Googleスクリプト - すべてのエクスポート時にセルに1を追加する
ユーザーがシートをダウンロードするたびに、A1の数字が1になります。
Googleスプレッドシートに自動番号を作成する方法を探しています。シンプルになるかもしれませんが、スクリプトについてはあまりよく分かりません...Googleスクリプト - すべてのエクスポート時にセルに1を追加する
ユーザーがシートをダウンロードするたびに、A1の数字が1になります。
otOInkInitを使用して、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());
}