Il y a un moyen (un peu plus complexe) de télécharger directement sur le PC mais en passant pas une boite de dialoguer en html.
script
function onOpen() {
SpreadsheetApp.getUi().createMenu('⇩ M E N U ⇩')
.addItem('👉 Download file ...', 'openSidebar')
.addToUi();
}
function openSidebar() {
const html = HtmlService.createHtmlOutputFromFile("index").setTitle("DOMNLOAD KML FILE");
SpreadsheetApp.getUi().showSidebar(html);
}
function createDataUrl(type) {
var name = 'monfichier.txt'
const mimeTypes = { txt: MimeType.PLAIN_TXT };
var kml = SpreadsheetApp.getActiveSpreadsheet().getSheetByName('kml')
var data = kml.getRange('A1:A' + kml.getLastRow()).getValues()
var content = ''
data.forEach(r => r.forEach(x => content += x + '\n'))
var id = DriveApp.createFile(name, content).getId();
const blob = DriveApp.getFileById(id).getBlob();
return {
data:
`data:${mimeTypes[type]};base64,` + Utilities.base64Encode(blob.getBytes()),
filename: `${name}`,
};
}
ajoute un fichier au format html nommé index
<!DOCTYPE html>
<html>
<head>
</head>
<body onload="autoRun()">
Wait during your file will automatically download ...<br/><br/>
If any issue, click here <input type="button" value="download as XSV" onclick="download('txt')" />
<script>
function download(type) {
google.script.run
.withSuccessHandler(({ data, filename }) => {
const a = document.createElement("a");
document.body.appendChild(a);
a.download = filename;
a.href = data;
a.click();
})
.createDataUrl(type);
}
function autoRun(){
download('txt')
window.setTimeout(function(){google.script.host.close()},5000)
}
</script>
</body></html>