Created
March 2, 2021 14:10
-
-
Save datYori/d4ac480b7b29b7d71943146030edf7e2 to your computer and use it in GitHub Desktop.
SimpleTimeStampTradFromStephVB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function onEdit() { | |
var s = SpreadsheetApp.getActiveSheet(); // equivalent VB -> Worksheet_SelectionChange | |
var r = s.getActiveCell(); | |
// on fait la meme chose pour la colonne C (index:3) et F (index:5) donc on va tout faire d'un coup | |
if (r.getColumn() == 3 || r.getColumn() == 5) { | |
var nextRCell = r.offset(0, 1); // permet d'aller chercher la cell tout de suite a droite | |
if (nextRCell.getValue() === '') { | |
var thetime = new Date(); | |
// quand on instancie un temps on a besoin d'une zone horaire de référence | |
// ici on aura bien l'heure de Paris mais seulement parce-que je suis allé | |
// modifier ça dans les params du sheet. | |
// Fichier > Parametres de la feuille de calcul > Fuseau horaire | |
// afin de ne pas etre limitant je me base sur la langue paramétrée par l'utilisateur | |
// on pourrait fixer a GMT+1 ou CET | |
var hhmmTime = Utilities.formatDate(thetime, SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "HH:mm") | |
nextRCell.setValue(hhmmTime); | |
} | |
} | |
if (r.getColumn() == 2){ | |
var nextLCell = r.offset(0, -1); | |
if (nextLCell.getValue() === '') { | |
var thetime = new Date(); | |
var hhmmTime = Utilities.formatDate(thetime, SpreadsheetApp.getActive().getSpreadsheetTimeZone(), "dd/M/yyyy") | |
nextLCell.setValue(hhmmTime); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment