Bonjour,
Après avoir galéré pour introduire les jours fériés et changer quelques réglages, la page html (une véritable usine à gaz) n'était pas compatible a priori.
Changement de stratégie ... https://docs.google.com/spreadsheets/d/1hy8qI19EnMZX4WU4s1GbQlv6UPrXsaw_qOAID6Jnsno/edit?usp=sharing
Un calendrier s'affiche à l'ouverture. Un clic sur un jour renvoie la valeur dans la cellule active. Je suis nul en CSS mais le reste semble correct !
function onOpen() {
const html = HtmlService.createHtmlOutputFromFile('calend').setTitle('Calendrier');
SpreadsheetApp.getUi().showSidebar(html);
}
function mettreDate(laDate) {
var doc = SpreadsheetApp.getActiveSpreadsheet();
var feuille = SpreadsheetApp.getActive();
var r = feuille.getActiveRange();
r.setValue(laDate);
}
et pour le fichier html
<!DOCTYPE html>
<html>
<head>
<title>calendrier</title>
<style type="text/css">
body {
font-family: Helvetica, sans-serif;
}
td {
text-align: center;
width: 32px;
height; 36px;
font-size: 14px;
}
th {
text-align: center;
width: 32px;
height; 36px;
font-size: 18px;
}
</style>
<script>
function JoursFeries (an){
//Il y a avec les 2 jours dont nous bénéficions en alsace, a savoir la Saint Etienne et le Vendredi Saint.
//https://codes-sources.commentcamarche.net/source/16245-calcul-des-jours-feries
var JourAn = new Date(an, "00", "01")
var FeteTravail = new Date(an, "04", "01")
var Victoire1945 = new Date(an, "04", "08")
var FeteNationale = new Date(an,"06", "14")
var Assomption = new Date(an, "07", "15")
var Toussaint = new Date(an, "10", "01")
var Armistice = new Date(an, "10", "11")
var Noel = new Date(an, "11", "25")
//var SaintEtienne = new Date(an, "11", "26")
var G = an%19
var C = Math.floor(an/100)
var H = (C - Math.floor(C/4) - Math.floor((8*C+13)/25) + 19*G + 15)%30
var I = H - Math.floor(H/28)*(1 - Math.floor(H/28)*Math.floor(29/(H + 1))*Math.floor((21 - G)/11))
var J = (an*1 + Math.floor(an/4) + I + 2 - C + Math.floor(C/4))%7
var L = I - J
var MoisPaques = 3 + Math.floor((L + 40)/44)
var JourPaques = L + 28 - 31*Math.floor(MoisPaques/4)
var Paques = new Date(an, MoisPaques-1, JourPaques)
//var VendrediSaint = new Date(an, MoisPaques-1, JourPaques-2)
var LundiPaques = new Date(an, MoisPaques-1, JourPaques+1)
var Ascension = new Date(an, MoisPaques-1, JourPaques+39)
var Pentecote = new Date(an, MoisPaques-1, JourPaques+49)
var LundiPentecote = new Date(an, MoisPaques-1, JourPaques+50)
return new Array(JourAn, Paques, LundiPaques, FeteTravail, Victoire1945, Ascension, Pentecote, LundiPentecote, FeteNationale, Assomption, Toussaint, Armistice, Noel)
}
function isFerie(jf,mf,af) {
for(var i in JoursFeries(af)) {
if ( ( ((jf<10)?'0'+jf:jf) + '/' + ((mf<10)?'0'+mf:mf) ) == ( JoursFeries(af)[i].getDate() + '/' + (JoursFeries(af)[i].getMonth()+1) ) ){
return true;
}
}
return false;
}
</script>
<script>
function calendar() {
var today= new Date();
var thisDay= today.getDate();
var monthNames= ['Janvier','Février','Mars','Avril','Mai','Juin','Juillet','Août','Septembre','Octobre','Novembre','Décembre'];
var jours= ['L','M','M','J','V','S','D'];
var monthDays= [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
var year= today.getYear();
year <= 200 ? year += 1900 : null;
if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0)){
monthDays[1] = 29;
}
var nDays= monthDays[today.getMonth()];
var firstDay= today;
firstDay.setDate(0);
firstDay.getDate() == 2 ? firstDay.setDate(0) : null;
var startDay = firstDay.getDay();
var tb= document.createElement('table');
var tbr= tb.insertRow(-1);
var tbh= document.createElement("th");
tbh.setAttribute('colspan','7');
var tbhtxt= document.createTextNode(monthNames[today.getMonth()+1]+' '+year);
tbh.appendChild(tbhtxt);
tbr.appendChild(tbh);
var tbr=tb.insertRow(-1);
for(var i=0 ;i<jours.length ; i++){
tbr.insertCell(-1).appendChild(document.createTextNode(jours[i]));
}
var tbr= document.createElement("tr");
var column= 0;
for (var i= 0; i < startDay; i++) {
tbr.insertCell(0);
column++;
}
for (var i = 1; i <= nDays; i++) {
var tdd= tbr.insertCell(-1);
tdd.appendChild(document.createTextNode(i));
tdd.onmouseover = function () {
this.style.cursor='pointer';
};
tdd.onclick = function () {
google.script.run.mettreDate(this.textContent + '/' + (today.getMonth()+2) + '/'+ year);
};
i == thisDay ? tdd.style.color="#0000FF" : null;
isFerie(i , (today.getMonth()+2) , year) ? tdd.style.color="#FF0000" : null;
column++;
if (column == 7) {
tb.appendChild(tbr);
var tbr=document.createElement("tr");
column = 0;
}
i == nDays ? tb.appendChild(tbr) : null;
}
document.getElementById('monCalendrier').appendChild(tb);
}
typeof window.addEventListener == 'undefined' ? window.attachEvent("onload",calendar) : addEventListener('load',calendar,false);
</script>
</head>
<body>
<center><div id='monCalendrier'></div></center>
</body>
</html>
Dites moi si quelque chose cloche. Reste à améliorer pour le défilement des mois !